Sebastian Redl | 3b3c874 | 2010-08-18 23:57:11 +0000 | [diff] [blame] | 1 | //===--- ASTReader.cpp - AST File Reader ------------------------*- C++ -*-===// |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 10 | // This file defines the ASTReader class, which reads AST files. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Chris Lattner | 92ba5ff | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 13 | |
Sebastian Redl | f5b1346 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTReader.h" |
| 15 | #include "clang/Serialization/ASTDeserializationListener.h" |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 16 | #include "ASTCommon.h" |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 17 | #include "clang/Frontend/FrontendDiagnostic.h" |
Daniel Dunbar | 732ef8a | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/Utils.h" |
Douglas Gregor | c3a6ade | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 19 | #include "clang/Sema/Sema.h" |
John McCall | cc14d1f | 2010-08-24 08:50:51 +0000 | [diff] [blame] | 20 | #include "clang/Sema/Scope.h" |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 21 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 22 | #include "clang/AST/ASTContext.h" |
John McCall | 19c1bfd | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 24 | #include "clang/AST/Expr.h" |
John McCall | bfd822c | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 26 | #include "clang/AST/NestedNameSpecifier.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 27 | #include "clang/AST/Type.h" |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 28 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 34321bc | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 29 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 30 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 31 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 3fa455a | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 32 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 33 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 34 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 35 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 36 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 37 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 38 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | d54f3a1 | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 39 | #include "clang/Basic/Version.h" |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 40 | #include "clang/Basic/VersionTuple.h" |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 41 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 42 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 43 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 44 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 45 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 46 | #include "llvm/Support/Path.h" |
Michael J. Spencer | f25faaa | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 47 | #include "llvm/Support/system_error.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 48 | #include <algorithm> |
Douglas Gregor | c379c07 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 49 | #include <iterator> |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 50 | #include <cstdio> |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 51 | #include <sys/stat.h> |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 52 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 53 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 54 | using namespace clang::serialization; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 55 | |
| 56 | //===----------------------------------------------------------------------===// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 57 | // PCH validator implementation |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 58 | //===----------------------------------------------------------------------===// |
| 59 | |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 60 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 61 | |
| 62 | bool |
| 63 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 64 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 65 | #define PARSE_LANGOPT_BENIGN(Option) |
| 66 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 67 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 68 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 69 | return true; \ |
| 70 | } |
| 71 | |
| 72 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 73 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 74 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 75 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 76 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
Chandler Carruth | e03aa55 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 77 | PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 78 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 79 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 80 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 81 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
Peter Collingbourne | a686b5f | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 82 | PARSE_LANGOPT_IMPORTANT(C1X, diag::warn_pch_c1x); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 83 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
Michael J. Spencer | 4992ca4b | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 84 | PARSE_LANGOPT_BENIGN(MSCVersion); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 85 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 86 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 87 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 88 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 89 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 90 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
Fariborz Jahanian | 4587803 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 91 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2); |
Fariborz Jahanian | 13f3b2f | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 92 | PARSE_LANGOPT_IMPORTANT(AppleKext, diag::warn_pch_apple_kext); |
Ted Kremenek | 1d56c9e | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 93 | PARSE_LANGOPT_IMPORTANT(ObjCDefaultSynthProperties, |
| 94 | diag::warn_pch_objc_auto_properties); |
Douglas Gregor | a860e6a | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 95 | PARSE_LANGOPT_BENIGN(ObjCInferRelatedResultType) |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 96 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 62c5602 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 97 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 98 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 99 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 100 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 101 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 9d90579 | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 102 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 103 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Anders Carlsson | ce8dd3a | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 104 | PARSE_LANGOPT_IMPORTANT(ObjCExceptions, diag::warn_pch_objc_exceptions); |
Anders Carlsson | 6bbd268 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 105 | PARSE_LANGOPT_IMPORTANT(CXXExceptions, diag::warn_pch_cxx_exceptions); |
| 106 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Douglas Gregor | dbe3927 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 107 | PARSE_LANGOPT_IMPORTANT(MSBitfields, diag::warn_pch_ms_bitfields); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 108 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 109 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 110 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 111 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 112 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | a77eaeb | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 113 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 114 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 115 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 116 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 117 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 118 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 119 | diag::warn_pch_heinous_extensions); |
| 120 | // FIXME: Most of the options below are benign if the macro wasn't |
| 121 | // used. Unfortunately, this means that a PCH compiled without |
| 122 | // optimization can't be used with optimization turned on, even |
| 123 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 124 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 125 | // doesn't matter. We could consider making this some special kind |
| 126 | // of check. |
| 127 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 128 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 129 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 130 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 131 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 132 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
Chandler Carruth | 7ffce73 | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 133 | PARSE_LANGOPT_IMPORTANT(Deprecated, diag::warn_pch_deprecated); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 134 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 135 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | ed4e295 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 136 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 74825bc | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 137 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 138 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 139 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 140 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 141 | return true; |
| 142 | } |
| 143 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 144 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 145 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 146 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 9d90579 | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 147 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Peter Collingbourne | 546d079 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 148 | PARSE_LANGOPT_IMPORTANT(CUDA, diag::warn_pch_cuda); |
Mike Stump | d954638 | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 149 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 150 | PARSE_LANGOPT_BENIGN(DefaultFPContract); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 151 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | 8ed0c0b | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 152 | PARSE_LANGOPT_BENIGN(SpellChecking); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 153 | PARSE_LANGOPT_IMPORTANT(ObjCAutoRefCount, diag::warn_pch_auto_ref_count); |
| 154 | PARSE_LANGOPT_BENIGN(ObjCInferRelatedReturnType); |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 155 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 156 | #undef PARSE_LANGOPT_BENIGN |
| 157 | |
| 158 | return false; |
| 159 | } |
| 160 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 161 | bool PCHValidator::ReadTargetTriple(StringRef Triple) { |
Daniel Dunbar | 20a682d | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 162 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 163 | return false; |
| 164 | |
| 165 | Reader.Diag(diag::warn_pch_target_triple) |
| 166 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 167 | return true; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Benjamin Kramer | 90b5b68 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 170 | namespace { |
| 171 | struct EmptyStringRef { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 172 | bool operator ()(StringRef r) const { return r.empty(); } |
Benjamin Kramer | 90b5b68 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 173 | }; |
| 174 | struct EmptyBlock { |
| 175 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 176 | }; |
| 177 | } |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 178 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 179 | static bool EqualConcatenations(SmallVector<StringRef, 2> L, |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 180 | PCHPredefinesBlocks R) { |
| 181 | // First, sum up the lengths. |
| 182 | unsigned LL = 0, RL = 0; |
| 183 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 184 | LL += L[I].size(); |
| 185 | } |
| 186 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 187 | RL += R[I].Data.size(); |
| 188 | } |
| 189 | if (LL != RL) |
| 190 | return false; |
| 191 | if (LL == 0 && RL == 0) |
| 192 | return true; |
| 193 | |
| 194 | // Kick out empty parts, they confuse the algorithm below. |
| 195 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 196 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 197 | |
| 198 | // Do it the hard way. At this point, both vectors must be non-empty. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 199 | StringRef LR = L[0], RR = R[0].Data; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 200 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | 01ad0a7 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 201 | (void) RN; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 202 | for (;;) { |
| 203 | // Compare the current pieces. |
| 204 | if (LR.size() == RR.size()) { |
| 205 | // If they're the same length, it's pretty easy. |
| 206 | if (LR != RR) |
| 207 | return false; |
| 208 | // Both pieces are done, advance. |
| 209 | ++LI; |
| 210 | ++RI; |
| 211 | // If either string is done, they're both done, since they're the same |
| 212 | // length. |
| 213 | if (LI == LN) { |
| 214 | assert(RI == RN && "Strings not the same length after all?"); |
| 215 | return true; |
| 216 | } |
| 217 | LR = L[LI]; |
| 218 | RR = R[RI].Data; |
| 219 | } else if (LR.size() < RR.size()) { |
| 220 | // Right piece is longer. |
| 221 | if (!RR.startswith(LR)) |
| 222 | return false; |
| 223 | ++LI; |
| 224 | assert(LI != LN && "Strings not the same length after all?"); |
| 225 | RR = RR.substr(LR.size()); |
| 226 | LR = L[LI]; |
| 227 | } else { |
| 228 | // Left piece is longer. |
| 229 | if (!LR.startswith(RR)) |
| 230 | return false; |
| 231 | ++RI; |
| 232 | assert(RI != RN && "Strings not the same length after all?"); |
| 233 | LR = LR.substr(RR.size()); |
| 234 | RR = R[RI].Data; |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 239 | static std::pair<FileID, StringRef::size_type> |
| 240 | FindMacro(const PCHPredefinesBlocks &Buffers, StringRef MacroDef) { |
| 241 | std::pair<FileID, StringRef::size_type> Res; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 242 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 243 | Res.second = Buffers[I].Data.find(MacroDef); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 244 | if (Res.second != StringRef::npos) { |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 245 | Res.first = Buffers[I].BufferID; |
| 246 | break; |
| 247 | } |
| 248 | } |
| 249 | return Res; |
| 250 | } |
| 251 | |
| 252 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 253 | StringRef OriginalFileName, |
Nick Lewycky | 3607989 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 254 | std::string &SuggestedPredefines, |
| 255 | FileManager &FileMgr) { |
Daniel Dunbar | 732ef8a | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 256 | // We are in the context of an implicit include, so the predefines buffer will |
| 257 | // have a #include entry for the PCH file itself (as normalized by the |
| 258 | // preprocessor initialization). Find it and skip over it in the checking |
| 259 | // below. |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 260 | llvm::SmallString<256> PCHInclude; |
| 261 | PCHInclude += "#include \""; |
Nick Lewycky | 3607989 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 262 | PCHInclude += NormalizeDashIncludePath(OriginalFileName, FileMgr); |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 263 | PCHInclude += "\"\n"; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 264 | std::pair<StringRef,StringRef> Split = |
| 265 | StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 266 | StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 267 | if (Left == PP.getPredefines()) { |
| 268 | Error("Missing PCH include entry!"); |
| 269 | return true; |
| 270 | } |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 271 | |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 272 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 273 | // command line, we're done. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 274 | SmallVector<StringRef, 2> CommandLine; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 275 | CommandLine.push_back(Left); |
| 276 | CommandLine.push_back(Right); |
| 277 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 278 | return false; |
| 279 | |
| 280 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 281 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 282 | // The predefines buffers are different. Determine what the differences are, |
| 283 | // and whether they require us to reject the PCH file. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 284 | SmallVector<StringRef, 8> PCHLines; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 285 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 286 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | 045f917e | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 287 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 288 | SmallVector<StringRef, 8> CmdLineLines; |
Daniel Dunbar | 045f917e | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 289 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 290 | |
| 291 | // Pick out implicit #includes after the PCH and don't consider them for |
| 292 | // validation; we will insert them into SuggestedPredefines so that the |
| 293 | // preprocessor includes them. |
| 294 | std::string IncludesAfterPCH; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 295 | SmallVector<StringRef, 8> AfterPCHLines; |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 296 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 297 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 298 | if (AfterPCHLines[i].startswith("#include ")) { |
| 299 | IncludesAfterPCH += AfterPCHLines[i]; |
| 300 | IncludesAfterPCH += '\n'; |
| 301 | } else { |
| 302 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | // Make sure we add the includes last into SuggestedPredefines before we |
| 307 | // exit this function. |
| 308 | struct AddIncludesRAII { |
| 309 | std::string &SuggestedPredefines; |
| 310 | std::string &IncludesAfterPCH; |
| 311 | |
| 312 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 313 | std::string &IncludesAfterPCH) |
| 314 | : SuggestedPredefines(SuggestedPredefines), |
| 315 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 316 | ~AddIncludesRAII() { |
| 317 | SuggestedPredefines += IncludesAfterPCH; |
| 318 | } |
| 319 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 320 | |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 321 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 322 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 323 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 324 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 325 | |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 326 | // Determine which predefines that were used to build the PCH file are missing |
| 327 | // from the command line. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 328 | std::vector<StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 329 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 330 | CmdLineLines.begin(), CmdLineLines.end(), |
| 331 | std::back_inserter(MissingPredefines)); |
| 332 | |
| 333 | bool MissingDefines = false; |
| 334 | bool ConflictingDefines = false; |
| 335 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 336 | StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 337 | if (Missing.startswith("#include ")) { |
| 338 | // An -include was specified when generating the PCH; it is included in |
| 339 | // the PCH, just ignore it. |
| 340 | continue; |
| 341 | } |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 342 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 343 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 344 | return true; |
| 345 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 346 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 347 | // This is a macro definition. Determine the name of the macro we're |
| 348 | // defining. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 349 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 350 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 351 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 352 | assert(EndOfMacroName != std::string::npos && |
| 353 | "Couldn't find the end of the macro name"); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 354 | StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 355 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 356 | // Determine whether this macro was given a different definition on the |
| 357 | // command line. |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 358 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 359 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 360 | SmallVector<StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 361 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 362 | MacroDefStart); |
| 363 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 364 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 365 | // Different macro; we're done. |
| 366 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 367 | break; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 368 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 369 | |
| 370 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 371 | "Invalid #define in predefines buffer?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 372 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 373 | (*ConflictPos)[MacroDefLen] != '(') |
| 374 | continue; // Longer macro name; keep trying. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 376 | // We found a conflicting macro definition. |
| 377 | break; |
| 378 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 379 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 380 | if (ConflictPos != CmdLineLines.end()) { |
| 381 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 382 | << MacroName; |
| 383 | |
| 384 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 385 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 386 | FindMacro(Buffers, Missing); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 387 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 388 | SourceLocation PCHMissingLoc = |
| 389 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 390 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 391 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 392 | |
| 393 | ConflictingDefines = true; |
| 394 | continue; |
| 395 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 396 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 397 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 398 | // definition from the PCH file. Warn the user that they made a mistake. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 399 | if (ConflictingDefines) |
| 400 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 402 | if (!MissingDefines) { |
| 403 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 404 | MissingDefines = true; |
| 405 | } |
| 406 | |
| 407 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 408 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 409 | FindMacro(Buffers, Missing); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 410 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 411 | SourceLocation PCHMissingLoc = |
| 412 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 413 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 414 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 415 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 416 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 417 | if (ConflictingDefines) |
| 418 | return true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 419 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 420 | // Determine what predefines were introduced based on command-line |
| 421 | // parameters that were not present when building the PCH |
| 422 | // file. Extra #defines are okay, so long as the identifiers being |
| 423 | // defined were not used within the precompiled header. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 424 | std::vector<StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 425 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 426 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 427 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 428 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 429 | StringRef &Extra = ExtraPredefines[I]; |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 430 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 431 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 432 | return true; |
| 433 | } |
| 434 | |
| 435 | // This is an extra macro definition. Determine the name of the |
| 436 | // macro we're defining. |
| 437 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 438 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 439 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 440 | assert(EndOfMacroName != std::string::npos && |
| 441 | "Couldn't find the end of the macro name"); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 442 | StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 443 | |
| 444 | // Check whether this name was used somewhere in the PCH file. If |
| 445 | // so, defining it as a macro could change behavior, so we reject |
| 446 | // the PCH file. |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 447 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 045c92f | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 448 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 449 | return true; |
| 450 | } |
| 451 | |
| 452 | // Add this definition to the suggested predefines buffer. |
| 453 | SuggestedPredefines += Extra; |
| 454 | SuggestedPredefines += '\n'; |
| 455 | } |
| 456 | |
| 457 | // If we get here, it's because the predefines buffer had compatible |
| 458 | // contents. Accept the PCH file. |
| 459 | return false; |
| 460 | } |
| 461 | |
Douglas Gregor | 5712ebc | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 462 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 463 | unsigned ID) { |
| 464 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 465 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | void PCHValidator::ReadCounter(unsigned Value) { |
| 469 | PP.setCounterValue(Value); |
| 470 | } |
| 471 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 472 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 473 | // AST reader implementation |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 474 | //===----------------------------------------------------------------------===// |
| 475 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 476 | void |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 477 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 478 | DeserializationListener = Listener; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 479 | } |
| 480 | |
Chris Lattner | 92ba5ff | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 481 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 482 | namespace { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 483 | class ASTSelectorLookupTrait { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 484 | ASTReader &Reader; |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 485 | Module &F; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 486 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 487 | public: |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 488 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 489 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 490 | ObjCMethodList Instance, Factory; |
| 491 | }; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 492 | |
| 493 | typedef Selector external_key_type; |
| 494 | typedef external_key_type internal_key_type; |
| 495 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 496 | ASTSelectorLookupTrait(ASTReader &Reader, Module &F) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 497 | : Reader(Reader), F(F) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 498 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 499 | static bool EqualKey(const internal_key_type& a, |
| 500 | const internal_key_type& b) { |
| 501 | return a == b; |
| 502 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 503 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 504 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 505 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 506 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 507 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 508 | // This hopefully will just get inlined and removed by the optimizer. |
| 509 | static const internal_key_type& |
| 510 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 512 | static std::pair<unsigned, unsigned> |
| 513 | ReadKeyDataLength(const unsigned char*& d) { |
| 514 | using namespace clang::io; |
| 515 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 516 | unsigned DataLen = ReadUnalignedLE16(d); |
| 517 | return std::make_pair(KeyLen, DataLen); |
| 518 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 520 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 521 | using namespace clang::io; |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 522 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 523 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 524 | IdentifierInfo *FirstII |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 525 | = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 526 | if (N == 0) |
| 527 | return SelTable.getNullarySelector(FirstII); |
| 528 | else if (N == 1) |
| 529 | return SelTable.getUnarySelector(FirstII); |
| 530 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 531 | SmallVector<IdentifierInfo *, 16> Args; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 532 | Args.push_back(FirstII); |
| 533 | for (unsigned I = 1; I != N; ++I) |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 534 | Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d))); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 535 | |
Douglas Gregor | 038c338 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 536 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 537 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 538 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 539 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 540 | using namespace clang::io; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 541 | |
| 542 | data_type Result; |
| 543 | |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 544 | Result.ID = Reader.getGlobalSelectorID(F, ReadUnalignedLE32(d)); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 545 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 546 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 547 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 548 | // Load instance methods |
| 549 | ObjCMethodList *Prev = 0; |
| 550 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 551 | ObjCMethodDecl *Method |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 552 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d)); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 553 | if (!Result.Instance.Method) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 554 | // This is the first method, which is the easy case. |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 555 | Result.Instance.Method = Method; |
| 556 | Prev = &Result.Instance; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 557 | continue; |
| 558 | } |
| 559 | |
Ted Kremenek | da4abf1 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 560 | ObjCMethodList *Mem = |
| 561 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 562 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 563 | Prev = Prev->Next; |
| 564 | } |
| 565 | |
| 566 | // Load factory methods |
| 567 | Prev = 0; |
| 568 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 569 | ObjCMethodDecl *Method |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 570 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d)); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 571 | if (!Result.Factory.Method) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 572 | // This is the first method, which is the easy case. |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 573 | Result.Factory.Method = Method; |
| 574 | Prev = &Result.Factory; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 575 | continue; |
| 576 | } |
| 577 | |
Ted Kremenek | da4abf1 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 578 | ObjCMethodList *Mem = |
| 579 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 580 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 581 | Prev = Prev->Next; |
| 582 | } |
| 583 | |
| 584 | return Result; |
| 585 | } |
| 586 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 587 | |
| 588 | } // end anonymous namespace |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 589 | |
| 590 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 591 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 592 | ASTSelectorLookupTable; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 593 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 594 | namespace clang { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 595 | class ASTIdentifierLookupTrait { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 596 | ASTReader &Reader; |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 597 | Module &F; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 598 | |
| 599 | // If we know the IdentifierInfo in advance, it is here and we will |
| 600 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 601 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 602 | IdentifierInfo *KnownII; |
| 603 | |
| 604 | public: |
| 605 | typedef IdentifierInfo * data_type; |
| 606 | |
| 607 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 608 | |
| 609 | typedef external_key_type internal_key_type; |
| 610 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 611 | ASTIdentifierLookupTrait(ASTReader &Reader, Module &F, |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 612 | IdentifierInfo *II = 0) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 613 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 614 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 615 | static bool EqualKey(const internal_key_type& a, |
| 616 | const internal_key_type& b) { |
| 617 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 618 | : false; |
| 619 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 620 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 621 | static unsigned ComputeHash(const internal_key_type& a) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 622 | return llvm::HashString(StringRef(a.first, a.second)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 623 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 624 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 625 | // This hopefully will just get inlined and removed by the optimizer. |
| 626 | static const internal_key_type& |
| 627 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 628 | |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 629 | // This hopefully will just get inlined and removed by the optimizer. |
| 630 | static const external_key_type& |
| 631 | GetExternalKey(const internal_key_type& x) { return x; } |
| 632 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 633 | static std::pair<unsigned, unsigned> |
| 634 | ReadKeyDataLength(const unsigned char*& d) { |
| 635 | using namespace clang::io; |
Douglas Gregor | 6b7bf5a | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 636 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | 5287b4e | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 637 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 638 | return std::make_pair(KeyLen, DataLen); |
| 639 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 640 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 641 | static std::pair<const char*, unsigned> |
| 642 | ReadKey(const unsigned char* d, unsigned n) { |
| 643 | assert(n >= 2 && d[n-1] == '\0'); |
| 644 | return std::make_pair((const char*) d, n-1); |
| 645 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 646 | |
| 647 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 648 | const unsigned char* d, |
| 649 | unsigned DataLen) { |
| 650 | using namespace clang::io; |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 651 | unsigned RawID = ReadUnalignedLE32(d); |
| 652 | bool IsInteresting = RawID & 0x01; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 653 | |
| 654 | // Wipe out the "is interesting" bit. |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 655 | RawID = RawID >> 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 656 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 657 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 658 | if (!IsInteresting) { |
Sebastian Redl | 9891212 | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 659 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 660 | // and associate it with the persistent ID. |
| 661 | IdentifierInfo *II = KnownII; |
| 662 | if (!II) |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 663 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 664 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 665 | II->setIsFromAST(); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 666 | return II; |
| 667 | } |
| 668 | |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 669 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 670 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 671 | Bits >>= 1; |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 672 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 673 | Bits >>= 1; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 674 | bool Poisoned = Bits & 0x01; |
| 675 | Bits >>= 1; |
| 676 | bool ExtensionToken = Bits & 0x01; |
| 677 | Bits >>= 1; |
| 678 | bool hasMacroDefinition = Bits & 0x01; |
| 679 | Bits >>= 1; |
| 680 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 681 | Bits >>= 10; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 682 | |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 683 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 684 | DataLen -= 6; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 685 | |
| 686 | // Build the IdentifierInfo itself and link the identifier ID with |
| 687 | // the new IdentifierInfo. |
| 688 | IdentifierInfo *II = KnownII; |
| 689 | if (!II) |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 690 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 691 | Reader.SetIdentifierInfo(ID, II); |
| 692 | |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 693 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 694 | // Token IDs are read-only. |
| 695 | if (HasRevertedTokenIDToIdentifier) |
| 696 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 697 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 698 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 699 | "Incorrect extension token flag"); |
| 700 | (void)ExtensionToken; |
Douglas Gregor | b36fc53 | 2011-08-20 05:09:43 +0000 | [diff] [blame] | 701 | if (Poisoned) |
| 702 | II->setIsPoisoned(true); |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 703 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 704 | "Incorrect C++ operator keyword flag"); |
| 705 | (void)CPlusPlusOperatorKeyword; |
| 706 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 707 | // If this identifier is a macro, deserialize the macro |
| 708 | // definition. |
| 709 | if (hasMacroDefinition) { |
Douglas Gregor | b36fc53 | 2011-08-20 05:09:43 +0000 | [diff] [blame] | 710 | // FIXME: Check for conflicts? |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 711 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 712 | Reader.SetIdentifierIsMacro(II, F, Offset); |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 713 | DataLen -= 4; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 714 | } |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 715 | |
| 716 | // Read all of the declarations visible at global scope with this |
| 717 | // name. |
Chris Lattner | 1d72888 | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 718 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 719 | if (DataLen > 0) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 720 | SmallVector<uint32_t, 4> DeclIDs; |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 721 | for (; DataLen > 0; DataLen -= 4) |
Douglas Gregor | f224ae0 | 2011-07-21 23:29:11 +0000 | [diff] [blame] | 722 | DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 723 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 724 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 725 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 726 | II->setIsFromAST(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 727 | return II; |
| 728 | } |
| 729 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 730 | |
| 731 | } // end anonymous namespace |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 732 | |
| 733 | /// \brief The on-disk hash table used to contain information about |
| 734 | /// all of the identifiers in the program. |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 735 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 736 | ASTIdentifierLookupTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 737 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 738 | namespace { |
| 739 | class ASTDeclContextNameLookupTrait { |
| 740 | ASTReader &Reader; |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 741 | Module &F; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 742 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 743 | public: |
| 744 | /// \brief Pair of begin/end iterators for DeclIDs. |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 745 | /// |
| 746 | /// Note that these declaration IDs are local to the module that contains this |
| 747 | /// particular lookup t |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 748 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 749 | |
| 750 | /// \brief Special internal key for declaration names. |
| 751 | /// The hash table creates keys for comparison; we do not create |
| 752 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 753 | struct DeclNameKey { |
| 754 | DeclarationName::NameKind Kind; |
| 755 | uint64_t Data; |
| 756 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 757 | }; |
| 758 | |
| 759 | typedef DeclarationName external_key_type; |
| 760 | typedef DeclNameKey internal_key_type; |
| 761 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 762 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 763 | Module &F) |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 764 | : Reader(Reader), F(F) { } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 765 | |
| 766 | static bool EqualKey(const internal_key_type& a, |
| 767 | const internal_key_type& b) { |
| 768 | return a.Kind == b.Kind && a.Data == b.Data; |
| 769 | } |
| 770 | |
| 771 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 772 | llvm::FoldingSetNodeID ID; |
| 773 | ID.AddInteger(Key.Kind); |
| 774 | |
| 775 | switch (Key.Kind) { |
| 776 | case DeclarationName::Identifier: |
| 777 | case DeclarationName::CXXLiteralOperatorName: |
| 778 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 779 | break; |
| 780 | case DeclarationName::ObjCZeroArgSelector: |
| 781 | case DeclarationName::ObjCOneArgSelector: |
| 782 | case DeclarationName::ObjCMultiArgSelector: |
| 783 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 784 | break; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 785 | case DeclarationName::CXXOperatorName: |
| 786 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 787 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 788 | case DeclarationName::CXXConstructorName: |
| 789 | case DeclarationName::CXXDestructorName: |
| 790 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 791 | case DeclarationName::CXXUsingDirective: |
| 792 | break; |
| 793 | } |
| 794 | |
| 795 | return ID.ComputeHash(); |
| 796 | } |
| 797 | |
| 798 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 799 | DeclNameKey Key; |
| 800 | Key.Kind = Name.getNameKind(); |
| 801 | switch (Name.getNameKind()) { |
| 802 | case DeclarationName::Identifier: |
| 803 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 804 | break; |
| 805 | case DeclarationName::ObjCZeroArgSelector: |
| 806 | case DeclarationName::ObjCOneArgSelector: |
| 807 | case DeclarationName::ObjCMultiArgSelector: |
| 808 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 809 | break; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 810 | case DeclarationName::CXXOperatorName: |
| 811 | Key.Data = Name.getCXXOverloadedOperator(); |
| 812 | break; |
| 813 | case DeclarationName::CXXLiteralOperatorName: |
| 814 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 815 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 816 | case DeclarationName::CXXConstructorName: |
| 817 | case DeclarationName::CXXDestructorName: |
| 818 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 819 | case DeclarationName::CXXUsingDirective: |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 820 | Key.Data = 0; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 821 | break; |
| 822 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 823 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 824 | return Key; |
| 825 | } |
| 826 | |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 827 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 828 | ASTContext *Context = Reader.getContext(); |
| 829 | switch (Key.Kind) { |
| 830 | case DeclarationName::Identifier: |
| 831 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 832 | |
| 833 | case DeclarationName::ObjCZeroArgSelector: |
| 834 | case DeclarationName::ObjCOneArgSelector: |
| 835 | case DeclarationName::ObjCMultiArgSelector: |
| 836 | return DeclarationName(Selector(Key.Data)); |
| 837 | |
| 838 | case DeclarationName::CXXConstructorName: |
| 839 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 840 | Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 841 | |
| 842 | case DeclarationName::CXXDestructorName: |
| 843 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 844 | Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 845 | |
| 846 | case DeclarationName::CXXConversionFunctionName: |
| 847 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 848 | Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 849 | |
| 850 | case DeclarationName::CXXOperatorName: |
| 851 | return Context->DeclarationNames.getCXXOperatorName( |
| 852 | (OverloadedOperatorKind)Key.Data); |
| 853 | |
| 854 | case DeclarationName::CXXLiteralOperatorName: |
| 855 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 856 | (IdentifierInfo*)Key.Data); |
| 857 | |
| 858 | case DeclarationName::CXXUsingDirective: |
| 859 | return DeclarationName::getUsingDirectiveName(); |
| 860 | } |
| 861 | |
| 862 | llvm_unreachable("Invalid Name Kind ?"); |
| 863 | } |
| 864 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 865 | static std::pair<unsigned, unsigned> |
| 866 | ReadKeyDataLength(const unsigned char*& d) { |
| 867 | using namespace clang::io; |
| 868 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 869 | unsigned DataLen = ReadUnalignedLE16(d); |
| 870 | return std::make_pair(KeyLen, DataLen); |
| 871 | } |
| 872 | |
| 873 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 874 | using namespace clang::io; |
| 875 | |
| 876 | DeclNameKey Key; |
| 877 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 878 | switch (Key.Kind) { |
| 879 | case DeclarationName::Identifier: |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 880 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 881 | break; |
| 882 | case DeclarationName::ObjCZeroArgSelector: |
| 883 | case DeclarationName::ObjCOneArgSelector: |
| 884 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 885 | Key.Data = |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 886 | (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d)) |
| 887 | .getAsOpaquePtr(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 888 | break; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 889 | case DeclarationName::CXXOperatorName: |
| 890 | Key.Data = *d++; // OverloadedOperatorKind |
| 891 | break; |
| 892 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 893 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 894 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 895 | case DeclarationName::CXXConstructorName: |
| 896 | case DeclarationName::CXXDestructorName: |
| 897 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 898 | case DeclarationName::CXXUsingDirective: |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 899 | Key.Data = 0; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 900 | break; |
| 901 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 902 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 903 | return Key; |
| 904 | } |
| 905 | |
| 906 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 907 | unsigned DataLen) { |
| 908 | using namespace clang::io; |
| 909 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 910 | DeclID *Start = (DeclID *)d; |
| 911 | return std::make_pair(Start, Start + NumDecls); |
| 912 | } |
| 913 | }; |
| 914 | |
| 915 | } // end anonymous namespace |
| 916 | |
| 917 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 918 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 919 | ASTDeclContextNameLookupTable; |
| 920 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 921 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 922 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 923 | DeclContextInfo &Info) { |
| 924 | SavedStreamPosition SavedPosition(Cursor); |
| 925 | // First the lexical decls. |
| 926 | if (Offsets.first != 0) { |
| 927 | Cursor.JumpToBit(Offsets.first); |
| 928 | |
| 929 | RecordData Record; |
| 930 | const char *Blob; |
| 931 | unsigned BlobLen; |
| 932 | unsigned Code = Cursor.ReadCode(); |
| 933 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 934 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 935 | Error("Expected lexical block"); |
| 936 | return true; |
| 937 | } |
| 938 | |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 939 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 940 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 941 | } else { |
| 942 | Info.LexicalDecls = 0; |
| 943 | Info.NumLexicalDecls = 0; |
| 944 | } |
| 945 | |
| 946 | // Now the lookup table. |
| 947 | if (Offsets.second != 0) { |
| 948 | Cursor.JumpToBit(Offsets.second); |
| 949 | |
| 950 | RecordData Record; |
| 951 | const char *Blob; |
| 952 | unsigned BlobLen; |
| 953 | unsigned Code = Cursor.ReadCode(); |
| 954 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 955 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 956 | Error("Expected visible lookup table block"); |
| 957 | return true; |
| 958 | } |
| 959 | Info.NameLookupTableData |
| 960 | = ASTDeclContextNameLookupTable::Create( |
| 961 | (const unsigned char *)Blob + Record[0], |
| 962 | (const unsigned char *)Blob, |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 963 | ASTDeclContextNameLookupTrait(*this, *Info.F)); |
Sebastian Redl | 9d8f58b | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 964 | } else { |
| 965 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | return false; |
| 969 | } |
| 970 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 971 | void ASTReader::Error(StringRef Msg) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 972 | Error(diag::err_fe_pch_malformed, Msg); |
| 973 | } |
| 974 | |
| 975 | void ASTReader::Error(unsigned DiagID, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 976 | StringRef Arg1, StringRef Arg2) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 977 | if (Diags.isDiagnosticInFlight()) |
| 978 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 979 | else |
| 980 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 983 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 984 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 985 | if (Listener) |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 986 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 987 | ActualOriginalFileName, |
Nick Lewycky | 3607989 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 988 | SuggestedPredefines, |
| 989 | FileMgr); |
Douglas Gregor | c379c07 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 990 | return false; |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 991 | } |
| 992 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 993 | //===----------------------------------------------------------------------===// |
| 994 | // Source Manager Deserialization |
| 995 | //===----------------------------------------------------------------------===// |
| 996 | |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 997 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 998 | /// \returns true if there was an error. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 999 | bool ASTReader::ParseLineTable(Module &F, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1000 | SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1001 | unsigned Idx = 0; |
| 1002 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1003 | |
| 1004 | // Parse the file names |
Douglas Gregor | a885465 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 1005 | std::map<int, int> FileIDs; |
| 1006 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1007 | // Extract the file name |
| 1008 | unsigned FilenameLen = Record[Idx++]; |
| 1009 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 1010 | Idx += FilenameLen; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1011 | MaybeAddSystemRootToFilename(Filename); |
Jay Foad | 9a6b098 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 1012 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | // Parse the line entries |
| 1016 | std::vector<LineEntry> Entries; |
| 1017 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1018 | int FID = Record[Idx++]; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1019 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 1020 | // Remap FileID from 1-based old view. |
| 1021 | FID += F.SLocEntryBaseID - 1; |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1022 | |
| 1023 | // Extract the line entries |
| 1024 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1025 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1026 | Entries.clear(); |
| 1027 | Entries.reserve(NumEntries); |
| 1028 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1029 | unsigned FileOffset = Record[Idx++]; |
| 1030 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1031 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1032 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1033 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1034 | unsigned IncludeOffset = Record[Idx++]; |
| 1035 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1036 | FileKind, IncludeOffset)); |
| 1037 | } |
| 1038 | LineTable.AddEntry(FID, Entries); |
| 1039 | } |
| 1040 | |
| 1041 | return false; |
| 1042 | } |
| 1043 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1044 | namespace { |
| 1045 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1046 | class ASTStatData { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1047 | public: |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1048 | const ino_t ino; |
| 1049 | const dev_t dev; |
| 1050 | const mode_t mode; |
| 1051 | const time_t mtime; |
| 1052 | const off_t size; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1053 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1054 | ASTStatData(ino_t i, dev_t d, mode_t mo, time_t m, off_t s) |
Chris Lattner | 2a6fa47 | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1055 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1056 | }; |
| 1057 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1058 | class ASTStatLookupTrait { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1059 | public: |
| 1060 | typedef const char *external_key_type; |
| 1061 | typedef const char *internal_key_type; |
| 1062 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1063 | typedef ASTStatData data_type; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1064 | |
| 1065 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1066 | return llvm::HashString(path); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1070 | |
| 1071 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1072 | return strcmp(a, b) == 0; |
| 1073 | } |
| 1074 | |
| 1075 | static std::pair<unsigned, unsigned> |
| 1076 | ReadKeyDataLength(const unsigned char*& d) { |
| 1077 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1078 | unsigned DataLen = (unsigned) *d++; |
| 1079 | return std::make_pair(KeyLen + 1, DataLen); |
| 1080 | } |
| 1081 | |
| 1082 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1083 | return (const char *)d; |
| 1084 | } |
| 1085 | |
| 1086 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1087 | unsigned /*DataLen*/) { |
| 1088 | using namespace clang::io; |
| 1089 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1090 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1091 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1092 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1093 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1094 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1095 | return data_type(ino, dev, mode, mtime, size); |
| 1096 | } |
| 1097 | }; |
| 1098 | |
| 1099 | /// \brief stat() cache for precompiled headers. |
| 1100 | /// |
| 1101 | /// This cache is very similar to the stat cache used by pretokenized |
| 1102 | /// headers. |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1103 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1104 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1105 | CacheTy *Cache; |
| 1106 | |
| 1107 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1108 | public: |
Chris Lattner | 2a6fa47 | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1109 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1110 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1111 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1112 | Cache = CacheTy::Create(Buckets, Base); |
| 1113 | } |
| 1114 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1115 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1116 | |
Chris Lattner | dd27843 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1117 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1118 | int *FileDescriptor) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1119 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1120 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1121 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1122 | // If we don't get a hit in the AST file just forward to 'stat'. |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1123 | if (I == Cache->end()) { |
| 1124 | ++NumStatMisses; |
Chris Lattner | dd27843 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1125 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1126 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1127 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1128 | ++NumStatHits; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1129 | ASTStatData Data = *I; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1130 | |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1131 | StatBuf.st_ino = Data.ino; |
| 1132 | StatBuf.st_dev = Data.dev; |
| 1133 | StatBuf.st_mtime = Data.mtime; |
| 1134 | StatBuf.st_mode = Data.mode; |
| 1135 | StatBuf.st_size = Data.size; |
Chris Lattner | 8f0583d | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1136 | return CacheExists; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1137 | } |
| 1138 | }; |
| 1139 | } // end anonymous namespace |
| 1140 | |
| 1141 | |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1142 | /// \brief Read a source manager block |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1143 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(Module &F) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1144 | using namespace SrcMgr; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1145 | |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1146 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1147 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1148 | // Set the source-location entry cursor to the current position in |
| 1149 | // the stream. This cursor will be used to read the contents of the |
| 1150 | // source manager block initially, and then lazily read |
| 1151 | // source-location entries as needed. |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1152 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1153 | |
| 1154 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1155 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1156 | Error("malformed block record in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1157 | return Failure; |
| 1158 | } |
| 1159 | |
| 1160 | // Enter the source manager block. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1161 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1162 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1163 | return Failure; |
| 1164 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1165 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1166 | RecordData Record; |
| 1167 | while (true) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1168 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1169 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1170 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1171 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1172 | return Failure; |
| 1173 | } |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1174 | return Success; |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1175 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1176 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1177 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1178 | // No known subblocks, always skip them. |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1179 | SLocEntryCursor.ReadSubBlockID(); |
| 1180 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1181 | Error("malformed block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1182 | return Failure; |
| 1183 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1184 | continue; |
| 1185 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1186 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1187 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1188 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1189 | continue; |
| 1190 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1191 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1192 | // Read a record. |
| 1193 | const char *BlobStart; |
| 1194 | unsigned BlobLen; |
| 1195 | Record.clear(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1196 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1197 | default: // Default behavior: ignore. |
| 1198 | break; |
| 1199 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1200 | case SM_SLOC_FILE_ENTRY: |
| 1201 | case SM_SLOC_BUFFER_ENTRY: |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1202 | case SM_SLOC_EXPANSION_ENTRY: |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1203 | // Once we hit one of the source location entries, we're done. |
| 1204 | return Success; |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1209 | /// \brief If a header file is not found at the path that we expect it to be |
| 1210 | /// and the PCH file was moved from its original location, try to resolve the |
| 1211 | /// file by assuming that header+PCH were moved together and the header is in |
| 1212 | /// the same place relative to the PCH. |
| 1213 | static std::string |
| 1214 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1215 | const std::string &OriginalDir, |
| 1216 | const std::string &CurrDir) { |
| 1217 | assert(OriginalDir != CurrDir && |
| 1218 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1219 | using namespace llvm::sys; |
| 1220 | llvm::SmallString<128> filePath(Filename); |
| 1221 | fs::make_absolute(filePath); |
| 1222 | assert(path::is_absolute(OriginalDir)); |
| 1223 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1224 | |
| 1225 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1226 | fileDirE = path::end(path::parent_path(filePath)); |
| 1227 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1228 | origDirE = path::end(OriginalDir); |
| 1229 | // Skip the common path components from filePath and OriginalDir. |
| 1230 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1231 | *fileDirI == *origDirI) { |
| 1232 | ++fileDirI; |
| 1233 | ++origDirI; |
| 1234 | } |
| 1235 | for (; origDirI != origDirE; ++origDirI) |
| 1236 | path::append(currPCHPath, ".."); |
| 1237 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1238 | path::append(currPCHPath, path::filename(Filename)); |
| 1239 | return currPCHPath.str(); |
| 1240 | } |
| 1241 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1242 | /// \brief Read in the source location entry with the given ID. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1243 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(int ID) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1244 | if (ID == 0) |
| 1245 | return Success; |
| 1246 | |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1247 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1248 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1249 | return Failure; |
| 1250 | } |
| 1251 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1252 | Module *F = GlobalSLocEntryMap.find(-ID)->second; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1253 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1254 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1255 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1256 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1257 | ++NumSLocEntriesRead; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1258 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1259 | if (Code == llvm::bitc::END_BLOCK || |
| 1260 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1261 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1262 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1263 | return Failure; |
| 1264 | } |
| 1265 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1266 | RecordData Record; |
| 1267 | const char *BlobStart; |
| 1268 | unsigned BlobLen; |
| 1269 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1270 | default: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1271 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1272 | return Failure; |
| 1273 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1274 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1275 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1276 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 5159f61 | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1277 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1278 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1279 | OriginalDir != CurrentDir) { |
| 1280 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1281 | OriginalDir, |
| 1282 | CurrentDir); |
| 1283 | if (!resolved.empty()) |
| 1284 | File = FileMgr.getFile(resolved); |
| 1285 | } |
Axel Naumann | 63fbaed | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1286 | if (File == 0) |
| 1287 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1288 | (time_t)Record[5]); |
Chris Lattner | d20dc87 | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1289 | if (File == 0) { |
| 1290 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1291 | ErrorStr += Filename; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1292 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d20dc87 | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1293 | Error(ErrorStr.c_str()); |
| 1294 | return Failure; |
| 1295 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1296 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1297 | if (Record.size() < 6) { |
Ted Kremenek | abb1ddd | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1298 | Error("source location entry is incorrect"); |
| 1299 | return Failure; |
| 1300 | } |
| 1301 | |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1302 | if (!DisableValidation && |
| 1303 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 08288f2 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1304 | #if !defined(LLVM_ON_WIN32) |
| 1305 | // In our regression testing, the Windows file system seems to |
| 1306 | // have inconsistent modification times that sometimes |
| 1307 | // erroneously trigger this error-handling path. |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1308 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 08288f2 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1309 | #endif |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1310 | )) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1311 | Error(diag::err_fe_pch_file_modified, Filename); |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1312 | return Failure; |
| 1313 | } |
| 1314 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1315 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1316 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1317 | // This is the module's main file. |
| 1318 | IncludeLoc = getImportLocation(F); |
| 1319 | } |
| 1320 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, |
Chris Lattner | 26b5c19 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1321 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1322 | ID, BaseOffset + Record[0]); |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame^] | 1323 | SrcMgr::FileInfo &FileInfo = |
| 1324 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
| 1325 | FileInfo.NumCreatedFIDs = Record[6]; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1326 | if (Record[3]) |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame^] | 1327 | FileInfo.setHasLineDirectives(); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1328 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1329 | break; |
| 1330 | } |
| 1331 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1332 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1333 | const char *Name = BlobStart; |
| 1334 | unsigned Offset = Record[0]; |
| 1335 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1336 | Record.clear(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1337 | unsigned RecCode |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1338 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1339 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1340 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1341 | Error("AST record has invalid code"); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1342 | return Failure; |
| 1343 | } |
| 1344 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1345 | llvm::MemoryBuffer *Buffer |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1346 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1347 | Name); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1348 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, |
| 1349 | BaseOffset + Offset); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1350 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1351 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1352 | PCHPredefinesBlock Block = { |
| 1353 | BufferID, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1354 | StringRef(BlobStart, BlobLen - 1) |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1355 | }; |
| 1356 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1357 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1358 | |
| 1359 | break; |
| 1360 | } |
| 1361 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1362 | case SM_SLOC_EXPANSION_ENTRY: { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1363 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Chandler Carruth | 115b077 | 2011-07-26 03:03:05 +0000 | [diff] [blame] | 1364 | SourceMgr.createExpansionLoc(SpellingLoc, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1365 | ReadSourceLocation(*F, Record[2]), |
| 1366 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1367 | Record[4], |
| 1368 | ID, |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1369 | BaseOffset + Record[0]); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1370 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1371 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | return Success; |
| 1375 | } |
| 1376 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1377 | /// \brief Find the location where the module F is imported. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1378 | SourceLocation ASTReader::getImportLocation(Module *F) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1379 | if (F->ImportLoc.isValid()) |
| 1380 | return F->ImportLoc; |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1381 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1382 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1383 | // location of its includer. |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1384 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1385 | // Main file is the importer. We assume that it is the first entry in the |
| 1386 | // entry table. We can't ask the manager, because at the time of PCH loading |
| 1387 | // the main file entry doesn't exist yet. |
| 1388 | // The very first entry is the invalid instantiation loc, which takes up |
| 1389 | // offsets 0 and 1. |
| 1390 | return SourceLocation::getFromRawEncoding(2U); |
| 1391 | } |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1392 | //return F->Loaders[0]->FirstLoc; |
| 1393 | return F->ImportedBy[0]->FirstLoc; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1396 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1397 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1398 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1399 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1400 | unsigned BlockID) { |
| 1401 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1402 | Error("malformed block record in AST file"); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1403 | return Failure; |
| 1404 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1405 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1406 | while (true) { |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1407 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1408 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1409 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1410 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1411 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1412 | Cursor.JumpToBit(Offset); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1413 | return false; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1414 | } |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1415 | Cursor.ReadAbbrevRecord(); |
| 1416 | } |
| 1417 | } |
| 1418 | |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1419 | void ASTReader::ReadMacroRecord(Module &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1420 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1421 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1422 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1423 | // Keep track of where we are in the stream, then jump back there |
| 1424 | // after reading this macro. |
| 1425 | SavedStreamPosition SavedPosition(Stream); |
| 1426 | |
| 1427 | Stream.JumpToBit(Offset); |
| 1428 | RecordData Record; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1429 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1430 | MacroInfo *Macro = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1431 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1432 | while (true) { |
| 1433 | unsigned Code = Stream.ReadCode(); |
| 1434 | switch (Code) { |
| 1435 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1436 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1437 | |
| 1438 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1439 | // No known subblocks, always skip them. |
| 1440 | Stream.ReadSubBlockID(); |
| 1441 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1442 | Error("malformed block record in AST file"); |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1443 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1444 | } |
| 1445 | continue; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1446 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1447 | case llvm::bitc::DEFINE_ABBREV: |
| 1448 | Stream.ReadAbbrevRecord(); |
| 1449 | continue; |
| 1450 | default: break; |
| 1451 | } |
| 1452 | |
| 1453 | // Read a record. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1454 | const char *BlobStart = 0; |
| 1455 | unsigned BlobLen = 0; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1456 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1457 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1458 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1459 | BlobLen); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1460 | switch (RecType) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1461 | case PP_MACRO_OBJECT_LIKE: |
| 1462 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1463 | // If we already have a macro, that means that we've hit the end |
| 1464 | // of the definition of the macro we were looking for. We're |
| 1465 | // done. |
| 1466 | if (Macro) |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1467 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1468 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1469 | IdentifierInfo *II = getLocalIdentifier(F, Record[0]); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1470 | if (II == 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1471 | Error("macro must have a name in AST file"); |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1472 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1473 | } |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1474 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1475 | bool isUsed = Record[2]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1476 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1477 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1478 | MI->setIsUsed(isUsed); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1479 | MI->setIsFromAST(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1480 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1481 | unsigned NextIndex = 3; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1482 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1483 | // Decode function-like macro info. |
| 1484 | bool isC99VarArgs = Record[3]; |
| 1485 | bool isGNUVarArgs = Record[4]; |
| 1486 | MacroArgs.clear(); |
| 1487 | unsigned NumArgs = Record[5]; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1488 | NextIndex = 6 + NumArgs; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1489 | for (unsigned i = 0; i != NumArgs; ++i) |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1490 | MacroArgs.push_back(getLocalIdentifier(F, Record[6+i])); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1491 | |
| 1492 | // Install function-like macro info. |
| 1493 | MI->setIsFunctionLike(); |
| 1494 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1495 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 038c338 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1496 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1497 | PP->getPreprocessorAllocator()); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | // Finally, install the macro. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1501 | PP->setMacroInfo(II, MI); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1502 | |
| 1503 | // Remember that we saw this macro last so that we add the tokens that |
| 1504 | // form its body to it. |
| 1505 | Macro = MI; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1506 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1507 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1508 | // We have a macro definition. Load it now. |
| 1509 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1510 | getLocalMacroDefinition(F, Record[NextIndex])); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1511 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1512 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1513 | ++NumMacrosRead; |
| 1514 | break; |
| 1515 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1516 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1517 | case PP_TOKEN: { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1518 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1519 | // erroneous, just pretend we didn't see this. |
| 1520 | if (Macro == 0) break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1521 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1522 | Token Tok; |
| 1523 | Tok.startToken(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1524 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1525 | Tok.setLength(Record[1]); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1526 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[2])) |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1527 | Tok.setIdentifierInfo(II); |
| 1528 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1529 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1530 | Macro->AddTokenToBody(Tok); |
| 1531 | break; |
| 1532 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1533 | } |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1534 | } |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1535 | |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1536 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1539 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(Module &F) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1540 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1541 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1542 | switch (Code) { |
| 1543 | case llvm::bitc::END_BLOCK: |
| 1544 | return 0; |
| 1545 | |
| 1546 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1547 | Error("unexpected subblock record in preprocessor detail block"); |
| 1548 | return 0; |
| 1549 | |
| 1550 | case llvm::bitc::DEFINE_ABBREV: |
| 1551 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1552 | return 0; |
| 1553 | |
| 1554 | default: |
| 1555 | break; |
| 1556 | } |
| 1557 | |
| 1558 | if (!PP->getPreprocessingRecord()) { |
| 1559 | Error("no preprocessing record"); |
| 1560 | return 0; |
| 1561 | } |
| 1562 | |
| 1563 | // Read the record. |
| 1564 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1565 | const char *BlobStart = 0; |
| 1566 | unsigned BlobLen = 0; |
| 1567 | RecordData Record; |
| 1568 | PreprocessorDetailRecordTypes RecType = |
| 1569 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1570 | Code, Record, BlobStart, BlobLen); |
| 1571 | switch (RecType) { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1572 | case PPD_MACRO_EXPANSION: { |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1573 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1574 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1575 | return PE; |
| 1576 | |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1577 | MacroExpansion *ME = |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1578 | new (PPRec) MacroExpansion(getLocalIdentifier(F, Record[3]), |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1579 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1580 | ReadSourceLocation(F, Record[2])), |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1581 | getLocalMacroDefinition(F, Record[4])); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1582 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, ME); |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1583 | return ME; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | case PPD_MACRO_DEFINITION: { |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1587 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1588 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1589 | return PE; |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1590 | |
| 1591 | unsigned MacroDefID = getGlobalMacroDefinitionID(F, Record[1]); |
| 1592 | if (MacroDefID > MacroDefinitionsLoaded.size()) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1593 | Error("out-of-bounds macro definition record"); |
| 1594 | return 0; |
| 1595 | } |
| 1596 | |
| 1597 | // Decode the identifier info and then check again; if the macro is |
| 1598 | // still defined and associated with the identifier, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1599 | IdentifierInfo *II = getLocalIdentifier(F, Record[4]); |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1600 | if (!MacroDefinitionsLoaded[MacroDefID - 1]) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1601 | MacroDefinition *MD |
| 1602 | = new (PPRec) MacroDefinition(II, |
| 1603 | ReadSourceLocation(F, Record[5]), |
| 1604 | SourceRange( |
| 1605 | ReadSourceLocation(F, Record[2]), |
| 1606 | ReadSourceLocation(F, Record[3]))); |
| 1607 | |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1608 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, MD); |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1609 | MacroDefinitionsLoaded[MacroDefID - 1] = MD; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1610 | |
| 1611 | if (DeserializationListener) |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1612 | DeserializationListener->MacroDefinitionRead(MacroDefID, MD); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1615 | return MacroDefinitionsLoaded[MacroDefID - 1]; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | case PPD_INCLUSION_DIRECTIVE: { |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1619 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1620 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1621 | return PE; |
| 1622 | |
| 1623 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1624 | const FileEntry *File |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1625 | = PP->getFileManager().getFile(StringRef(FullFileNameStart, |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1626 | BlobLen - Record[3])); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1627 | |
| 1628 | // FIXME: Stable encoding |
| 1629 | InclusionDirective::InclusionKind Kind |
| 1630 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1631 | InclusionDirective *ID |
| 1632 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1633 | StringRef(BlobStart, Record[3]), |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1634 | Record[4], |
| 1635 | File, |
| 1636 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1637 | ReadSourceLocation(F, Record[2]))); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1638 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, ID); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1639 | return ID; |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | Error("invalid offset in preprocessor detail block"); |
| 1644 | return 0; |
| 1645 | } |
| 1646 | |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1647 | PreprocessedEntityID |
| 1648 | ASTReader::getGlobalPreprocessedEntityID(Module &M, unsigned LocalID) { |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1649 | ContinuousRangeMap<uint32_t, int, 2>::iterator |
| 1650 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1651 | assert(I != M.PreprocessedEntityRemap.end() |
| 1652 | && "Invalid index into preprocessed entity index remap"); |
| 1653 | |
| 1654 | return LocalID + I->second; |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1657 | namespace { |
| 1658 | /// \brief Trait class used to search the on-disk hash table containing all of |
| 1659 | /// the header search information. |
| 1660 | /// |
| 1661 | /// The on-disk hash table contains a mapping from each header path to |
| 1662 | /// information about that header (how many times it has been included, its |
| 1663 | /// controlling macro, etc.). Note that we actually hash based on the |
| 1664 | /// filename, and support "deep" comparisons of file names based on current |
| 1665 | /// inode numbers, so that the search can cope with non-normalized path names |
| 1666 | /// and symlinks. |
| 1667 | class HeaderFileInfoTrait { |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1668 | ASTReader &Reader; |
| 1669 | Module &M; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1670 | HeaderSearch *HS; |
| 1671 | const char *FrameworkStrings; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1672 | const char *SearchPath; |
| 1673 | struct stat SearchPathStatBuf; |
| 1674 | llvm::Optional<int> SearchPathStatResult; |
| 1675 | |
| 1676 | int StatSimpleCache(const char *Path, struct stat *StatBuf) { |
| 1677 | if (Path == SearchPath) { |
| 1678 | if (!SearchPathStatResult) |
| 1679 | SearchPathStatResult = stat(Path, &SearchPathStatBuf); |
| 1680 | |
| 1681 | *StatBuf = SearchPathStatBuf; |
| 1682 | return *SearchPathStatResult; |
| 1683 | } |
| 1684 | |
| 1685 | return stat(Path, StatBuf); |
| 1686 | } |
| 1687 | |
| 1688 | public: |
| 1689 | typedef const char *external_key_type; |
| 1690 | typedef const char *internal_key_type; |
| 1691 | |
| 1692 | typedef HeaderFileInfo data_type; |
| 1693 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1694 | HeaderFileInfoTrait(ASTReader &Reader, Module &M, HeaderSearch *HS, |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1695 | const char *FrameworkStrings, |
| 1696 | const char *SearchPath = 0) |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1697 | : Reader(Reader), M(M), HS(HS), FrameworkStrings(FrameworkStrings), |
| 1698 | SearchPath(SearchPath) { } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1699 | |
| 1700 | static unsigned ComputeHash(const char *path) { |
| 1701 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1702 | } |
| 1703 | |
| 1704 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1705 | |
| 1706 | bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1707 | if (strcmp(a, b) == 0) |
| 1708 | return true; |
| 1709 | |
| 1710 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1711 | return false; |
| 1712 | |
| 1713 | // The file names match, but the path names don't. stat() the files to |
| 1714 | // see if they are the same. |
| 1715 | struct stat StatBufA, StatBufB; |
| 1716 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1717 | return false; |
| 1718 | |
| 1719 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1720 | } |
| 1721 | |
| 1722 | static std::pair<unsigned, unsigned> |
| 1723 | ReadKeyDataLength(const unsigned char*& d) { |
| 1724 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1725 | unsigned DataLen = (unsigned) *d++; |
| 1726 | return std::make_pair(KeyLen + 1, DataLen); |
| 1727 | } |
| 1728 | |
| 1729 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1730 | return (const char *)d; |
| 1731 | } |
| 1732 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1733 | data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1734 | unsigned DataLen) { |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1735 | const unsigned char *End = d + DataLen; |
| 1736 | using namespace clang::io; |
| 1737 | HeaderFileInfo HFI; |
| 1738 | unsigned Flags = *d++; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1739 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1740 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1741 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1742 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1743 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1744 | HFI.NumIncludes = ReadUnalignedLE16(d); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1745 | HFI.ControllingMacroID = Reader.getGlobalDeclID(M, ReadUnalignedLE32(d)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1746 | if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { |
| 1747 | // The framework offset is 1 greater than the actual offset, |
| 1748 | // since 0 is used as an indicator for "no framework name". |
| 1749 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1750 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1751 | } |
| 1752 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1753 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1754 | (void)End; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1755 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1756 | // This HeaderFileInfo was externally loaded. |
| 1757 | HFI.External = true; |
| 1758 | return HFI; |
| 1759 | } |
| 1760 | }; |
| 1761 | } |
| 1762 | |
| 1763 | /// \brief The on-disk hash table used for the global method pool. |
| 1764 | typedef OnDiskChainedHashTable<HeaderFileInfoTrait> |
| 1765 | HeaderFileInfoLookupTable; |
| 1766 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1767 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, Module &F, |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1768 | uint64_t LocalOffset) { |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1769 | // Note that this identifier has a macro definition. |
| 1770 | II->setHasMacroDefinition(true); |
| 1771 | |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1772 | // Adjust the offset to a global offset. |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1773 | UnreadMacroRecordOffsets[II] = F.GlobalBitOffset + LocalOffset; |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1776 | void ASTReader::ReadDefinedMacros() { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1777 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1778 | E = ModuleMgr.rend(); I != E; ++I) { |
| 1779 | llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1780 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1781 | // If there was no preprocessor block, skip this file. |
| 1782 | if (!MacroCursor.getBitStreamReader()) |
| 1783 | continue; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1784 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1785 | llvm::BitstreamCursor Cursor = MacroCursor; |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1786 | Cursor.JumpToBit((*I)->MacroStartOffset); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1787 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1788 | RecordData Record; |
| 1789 | while (true) { |
| 1790 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1791 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1792 | break; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1793 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1794 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1795 | // No known subblocks, always skip them. |
| 1796 | Cursor.ReadSubBlockID(); |
| 1797 | if (Cursor.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1798 | Error("malformed block record in AST file"); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1799 | return; |
| 1800 | } |
| 1801 | continue; |
| 1802 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1803 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1804 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1805 | Cursor.ReadAbbrevRecord(); |
| 1806 | continue; |
| 1807 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1808 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1809 | // Read a record. |
| 1810 | const char *BlobStart; |
| 1811 | unsigned BlobLen; |
| 1812 | Record.clear(); |
| 1813 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1814 | default: // Default behavior: ignore. |
| 1815 | break; |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1816 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1817 | case PP_MACRO_OBJECT_LIKE: |
| 1818 | case PP_MACRO_FUNCTION_LIKE: |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1819 | getLocalIdentifier(**I, Record[0]); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1820 | break; |
| 1821 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1822 | case PP_TOKEN: |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1823 | // Ignore tokens. |
| 1824 | break; |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1825 | } |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1826 | } |
| 1827 | } |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1828 | |
| 1829 | // Drain the unread macro-record offsets map. |
| 1830 | while (!UnreadMacroRecordOffsets.empty()) |
| 1831 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1832 | } |
| 1833 | |
| 1834 | void ASTReader::LoadMacroDefinition( |
| 1835 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1836 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1837 | uint64_t Offset = Pos->second; |
| 1838 | UnreadMacroRecordOffsets.erase(Pos); |
| 1839 | |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1840 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 1841 | ReadMacroRecord(*Loc.F, Loc.Offset); |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1845 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1846 | = UnreadMacroRecordOffsets.find(II); |
| 1847 | LoadMacroDefinition(Pos); |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
Sebastian Redl | 50e2658 | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1850 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1851 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1852 | return 0; |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1853 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1854 | if (!MacroDefinitionsLoaded[ID - 1]) { |
Douglas Gregor | 270e014 | 2011-07-20 01:29:15 +0000 | [diff] [blame] | 1855 | GlobalMacroDefinitionMapType::iterator I =GlobalMacroDefinitionMap.find(ID); |
| 1856 | assert(I != GlobalMacroDefinitionMap.end() && |
| 1857 | "Corrupted global macro definition map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1858 | Module &M = *I->second; |
| 1859 | unsigned Index = ID - 1 - M.BaseMacroDefinitionID; |
| 1860 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
| 1861 | M.PreprocessorDetailCursor.JumpToBit(M.MacroDefinitionOffsets[Index]); |
| 1862 | LoadPreprocessedEntity(M); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1865 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1868 | const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1869 | std::string Filename = filenameStrRef; |
| 1870 | MaybeAddSystemRootToFilename(Filename); |
| 1871 | const FileEntry *File = FileMgr.getFile(Filename); |
| 1872 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1873 | OriginalDir != CurrentDir) { |
| 1874 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1875 | OriginalDir, |
| 1876 | CurrentDir); |
| 1877 | if (!resolved.empty()) |
| 1878 | File = FileMgr.getFile(resolved); |
| 1879 | } |
| 1880 | |
| 1881 | return File; |
| 1882 | } |
| 1883 | |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1884 | MacroID ASTReader::getGlobalMacroDefinitionID(Module &M, unsigned LocalID) { |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 1885 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 1886 | return LocalID; |
| 1887 | |
| 1888 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 1889 | = M.MacroDefinitionRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 1890 | assert(I != M.MacroDefinitionRemap.end() && |
| 1891 | "Invalid index into macro definition ID remap"); |
| 1892 | |
| 1893 | return LocalID + I->second; |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1894 | } |
| 1895 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1896 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1897 | /// not an absolute path, add the system root to the beginning of the file |
| 1898 | /// name. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1899 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1900 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1901 | if (!RelocatablePCH) |
| 1902 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1903 | |
Michael J. Spencer | f28df4c | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1904 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1905 | return; |
| 1906 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1907 | if (isysroot.empty()) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1908 | // If no system root was given, default to '/' |
| 1909 | Filename.insert(Filename.begin(), '/'); |
| 1910 | return; |
| 1911 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1912 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1913 | unsigned Length = isysroot.size(); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1914 | if (isysroot[Length - 1] != '/') |
| 1915 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1916 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1917 | Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end()); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1918 | } |
| 1919 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1920 | ASTReader::ASTReadResult |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1921 | ASTReader::ReadASTBlock(Module &F) { |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1922 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1923 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1924 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1925 | Error("malformed block record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1926 | return Failure; |
| 1927 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1928 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1929 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1930 | RecordData Record; |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1931 | bool First = true; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1932 | while (!Stream.AtEndOfStream()) { |
| 1933 | unsigned Code = Stream.ReadCode(); |
| 1934 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1935 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1936 | Error("error at end of module block in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1937 | return Failure; |
| 1938 | } |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1939 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1940 | return Success; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1944 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1945 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1946 | // We lazily load the decls block, but we want to set up the |
| 1947 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1948 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1949 | // With the main cursor, we just skip over it. |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1950 | F.DeclsCursor = Stream; |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1951 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1952 | // Read the abbrevs. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1953 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1954 | Error("malformed block record in AST file"); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1955 | return Failure; |
| 1956 | } |
| 1957 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1958 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1959 | case DECL_UPDATES_BLOCK_ID: |
| 1960 | if (Stream.SkipBlock()) { |
| 1961 | Error("malformed block record in AST file"); |
| 1962 | return Failure; |
| 1963 | } |
| 1964 | break; |
| 1965 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1966 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1967 | F.MacroCursor = Stream; |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1968 | if (PP) |
| 1969 | PP->setExternalSource(this); |
| 1970 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1971 | if (Stream.SkipBlock() || |
| 1972 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1973 | Error("malformed block record in AST file"); |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1974 | return Failure; |
| 1975 | } |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1976 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1977 | break; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1978 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1979 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1980 | F.PreprocessorDetailCursor = Stream; |
| 1981 | if (Stream.SkipBlock() || |
| 1982 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1983 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1984 | Error("malformed preprocessor detail record in AST file"); |
| 1985 | return Failure; |
| 1986 | } |
| 1987 | F.PreprocessorDetailStartOffset |
| 1988 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 1989 | break; |
| 1990 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1991 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1992 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1993 | case Success: |
| 1994 | break; |
| 1995 | |
| 1996 | case Failure: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1997 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1998 | return Failure; |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1999 | |
| 2000 | case IgnorePCH: |
| 2001 | return IgnorePCH; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2002 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2003 | break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2004 | } |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2005 | First = false; |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2006 | continue; |
| 2007 | } |
| 2008 | |
| 2009 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2010 | Stream.ReadAbbrevRecord(); |
| 2011 | continue; |
| 2012 | } |
| 2013 | |
| 2014 | // Read and process a record. |
| 2015 | Record.clear(); |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2016 | const char *BlobStart = 0; |
| 2017 | unsigned BlobLen = 0; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2018 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2019 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2020 | default: // Default behavior: ignore. |
| 2021 | break; |
| 2022 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2023 | case METADATA: { |
| 2024 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 2025 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2026 | : diag::warn_pch_version_too_new); |
| 2027 | return IgnorePCH; |
| 2028 | } |
| 2029 | |
| 2030 | RelocatablePCH = Record[4]; |
| 2031 | if (Listener) { |
| 2032 | std::string TargetTriple(BlobStart, BlobLen); |
| 2033 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 2034 | return IgnorePCH; |
| 2035 | } |
| 2036 | break; |
| 2037 | } |
| 2038 | |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 2039 | case IMPORTS: { |
| 2040 | // Load each of the imported PCH files. |
| 2041 | unsigned Idx = 0, N = Record.size(); |
| 2042 | while (Idx < N) { |
| 2043 | // Read information about the AST file. |
| 2044 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 2045 | unsigned Length = Record[Idx++]; |
| 2046 | llvm::SmallString<128> ImportedFile(Record.begin() + Idx, |
| 2047 | Record.begin() + Idx + Length); |
| 2048 | Idx += Length; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2049 | |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 2050 | // Load the AST file. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2051 | switch(ReadASTCore(ImportedFile, ImportedKind, &F)) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 2052 | case Failure: return Failure; |
| 2053 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 2054 | case IgnorePCH: return IgnorePCH; |
| 2055 | case Success: break; |
| 2056 | } |
| 2057 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2058 | break; |
| 2059 | } |
| 2060 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2061 | case TYPE_OFFSET: { |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2062 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2063 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2064 | return Failure; |
| 2065 | } |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2066 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 2067 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2068 | unsigned LocalBaseTypeIndex = Record[1]; |
| 2069 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 2070 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2071 | if (F.LocalNumTypes > 0) { |
| 2072 | // Introduce the global -> local mapping for types within this module. |
| 2073 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 2074 | |
| 2075 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2076 | F.TypeRemap.insert(std::make_pair(LocalBaseTypeIndex, |
| 2077 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2078 | |
| 2079 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 2080 | } |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2081 | break; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2084 | case DECL_OFFSET: { |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2085 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2086 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2087 | return Failure; |
| 2088 | } |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2089 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 2090 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2091 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2092 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 047d2ef | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 2093 | |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2094 | if (F.LocalNumDecls > 0) { |
| 2095 | // Introduce the global -> local mapping for declarations within this |
| 2096 | // module. |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2097 | GlobalDeclMap.insert( |
| 2098 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2099 | |
| 2100 | // Introduce the local -> global mapping for declarations within this |
| 2101 | // module. |
| 2102 | F.DeclRemap.insert(std::make_pair(LocalBaseDeclID, |
| 2103 | F.BaseDeclID - LocalBaseDeclID)); |
| 2104 | |
| 2105 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 2106 | } |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2107 | break; |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2110 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | 4b1f490 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2111 | DeclContextInfo Info = { |
Douglas Gregor | f224ae0 | 2011-07-21 23:29:11 +0000 | [diff] [blame] | 2112 | &F, |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2113 | /* No visible information */ 0, |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2114 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
Douglas Gregor | dc5c958 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 2115 | static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)) |
Sebastian Redl | 4b1f490 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2116 | }; |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2117 | |
| 2118 | DeclContext *TU = Context ? Context->getTranslationUnitDecl() : 0; |
| 2119 | DeclContextOffsets[TU].push_back(Info); |
| 2120 | if (TU) |
| 2121 | TU->setHasExternalLexicalStorage(true); |
| 2122 | |
Sebastian Redl | 4b1f490 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2123 | break; |
| 2124 | } |
| 2125 | |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2126 | case UPDATE_VISIBLE: { |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2127 | unsigned Idx = 0; |
| 2128 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2129 | void *Table = ASTDeclContextNameLookupTable::Create( |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2130 | (const unsigned char *)BlobStart + Record[Idx++], |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2131 | (const unsigned char *)BlobStart, |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 2132 | ASTDeclContextNameLookupTrait(*this, F)); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2133 | // FIXME: Complete hack to check for the TU |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2134 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID && Context) { // Is it the TU? |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2135 | DeclContextInfo Info = { |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2136 | &F, Table, /* No lexical information */ 0, 0 |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2137 | }; |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2138 | |
| 2139 | DeclContext *TU = Context->getTranslationUnitDecl(); |
| 2140 | DeclContextOffsets[TU].push_back(Info); |
| 2141 | TU->setHasExternalVisibleStorage(true); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2142 | } else |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2143 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2144 | break; |
| 2145 | } |
| 2146 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2147 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2148 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2149 | for (unsigned i = 0, e = Record.size(); i < e; /* in loop */) { |
| 2150 | DeclID First = ReadDeclID(F, Record, i); |
| 2151 | DeclID Latest = ReadDeclID(F, Record, i); |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2152 | FirstLatestDeclIDs[First] = Latest; |
| 2153 | } |
| 2154 | break; |
| 2155 | } |
| 2156 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2157 | case LANGUAGE_OPTIONS: |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2158 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2159 | return IgnorePCH; |
| 2160 | break; |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2161 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2162 | case IDENTIFIER_TABLE: |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2163 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2164 | if (Record[0]) { |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2165 | F.IdentifierLookupTable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2166 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2167 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2168 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2169 | ASTIdentifierLookupTrait(*this, F)); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2170 | if (PP) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2171 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2172 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2173 | } |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2174 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2175 | break; |
| 2176 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2177 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2178 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2179 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2180 | return Failure; |
| 2181 | } |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2182 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2183 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2184 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2185 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 19d2635 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 2186 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2187 | if (F.LocalNumIdentifiers > 0) { |
| 2188 | // Introduce the global -> local mapping for identifiers within this |
| 2189 | // module. |
| 2190 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 2191 | &F)); |
| 2192 | |
| 2193 | // Introduce the local -> global mapping for identifiers within this |
| 2194 | // module. |
| 2195 | F.IdentifierRemap.insert( |
| 2196 | std::make_pair(LocalBaseIdentifierID, |
| 2197 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
| 2198 | |
| 2199 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2200 | + F.LocalNumIdentifiers); |
| 2201 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2202 | break; |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2203 | } |
| 2204 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2205 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2206 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2207 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2208 | break; |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2209 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2210 | case SPECIAL_TYPES: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 2211 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2212 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2213 | break; |
| 2214 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2215 | case STATISTICS: |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2216 | TotalNumStatements += Record[0]; |
| 2217 | TotalNumMacros += Record[1]; |
| 2218 | TotalLexicalDeclContexts += Record[2]; |
| 2219 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2220 | break; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2221 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2222 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2223 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2224 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | 9007380 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2225 | break; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2226 | |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2227 | case DELEGATING_CTORS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2228 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2229 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2230 | break; |
| 2231 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2232 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 1c4bfe5 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 2233 | if (Record.size() % 4 != 0) { |
| 2234 | Error("invalid weak identifiers record"); |
| 2235 | return Failure; |
| 2236 | } |
| 2237 | |
| 2238 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 2239 | // files. This isn't the way to do it :) |
| 2240 | WeakUndeclaredIdentifiers.clear(); |
| 2241 | |
| 2242 | // Translate the weak, undeclared identifiers into global IDs. |
| 2243 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2244 | WeakUndeclaredIdentifiers.push_back( |
| 2245 | getGlobalIdentifierID(F, Record[I++])); |
| 2246 | WeakUndeclaredIdentifiers.push_back( |
| 2247 | getGlobalIdentifierID(F, Record[I++])); |
| 2248 | WeakUndeclaredIdentifiers.push_back( |
| 2249 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2250 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2251 | } |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2252 | break; |
| 2253 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2254 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2255 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2256 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2257 | break; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2258 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2259 | case SELECTOR_OFFSETS: { |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2260 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2261 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2262 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2263 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 2264 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2265 | if (F.LocalNumSelectors > 0) { |
| 2266 | // Introduce the global -> local mapping for selectors within this |
| 2267 | // module. |
| 2268 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 2269 | |
| 2270 | // Introduce the local -> global mapping for selectors within this |
| 2271 | // module. |
| 2272 | F.SelectorRemap.insert(std::make_pair(LocalBaseSelectorID, |
| 2273 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2274 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2275 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 2276 | } |
| 2277 | break; |
| 2278 | } |
| 2279 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2280 | case METHOD_POOL: |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2281 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2282 | if (Record[0]) |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2283 | F.SelectorLookupTable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2284 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2285 | F.SelectorLookupTableData + Record[0], |
| 2286 | F.SelectorLookupTableData, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2287 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2288 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2289 | break; |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2290 | |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2291 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 2292 | if (!Record.empty()) { |
| 2293 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2294 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 2295 | Record[Idx++])); |
| 2296 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2297 | getRawEncoding()); |
| 2298 | } |
| 2299 | } |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2300 | break; |
| 2301 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2302 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2303 | if (!Record.empty() && Listener) |
| 2304 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2305 | break; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2306 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2307 | case SOURCE_LOCATION_OFFSETS: { |
| 2308 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2309 | F.LocalNumSLocEntries = Record[0]; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2310 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
| 2311 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, Record[1]); |
| 2312 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2313 | // we invert it. Because we invert it, though, we need the other end of |
| 2314 | // the range. |
| 2315 | unsigned RangeStart = |
| 2316 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2317 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2318 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2319 | |
| 2320 | // Initialize the remapping table. |
| 2321 | // Invalid stays invalid. |
| 2322 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2323 | // This module. Base was 2 when being compiled. |
| 2324 | F.SLocRemap.insert(std::make_pair(2U, |
| 2325 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2326 | |
| 2327 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2328 | break; |
| 2329 | } |
| 2330 | |
Douglas Gregor | 5a1797c | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 2331 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2332 | // Additional remapping information. |
| 2333 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2334 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2335 | |
| 2336 | // Continuous range maps we may be updating in our module. |
| 2337 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2338 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2339 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2340 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2341 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2342 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2343 | MacroDefinitionRemap(F.MacroDefinitionRemap); |
| 2344 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2345 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2346 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2347 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 2348 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2349 | while(Data < DataEnd) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2350 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2351 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2352 | Data += Len; |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 2353 | Module *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2354 | if (!OM) { |
| 2355 | Error("SourceLocation remap refers to unknown module"); |
| 2356 | return Failure; |
| 2357 | } |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2358 | |
| 2359 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 2360 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
| 2361 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
| 2362 | uint32_t MacroDefinitionIDOffset = io::ReadUnalignedLE32(Data); |
| 2363 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 2364 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2365 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2366 | |
| 2367 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 2368 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 2369 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2370 | IdentifierRemap.insert( |
| 2371 | std::make_pair(IdentifierIDOffset, |
| 2372 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2373 | PreprocessedEntityRemap.insert( |
| 2374 | std::make_pair(PreprocessedEntityIDOffset, |
| 2375 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2376 | MacroDefinitionRemap.insert( |
| 2377 | std::make_pair(MacroDefinitionIDOffset, |
| 2378 | OM->BaseMacroDefinitionID - MacroDefinitionIDOffset)); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2379 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 2380 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2381 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 2382 | OM->BaseDeclID - DeclIDOffset)); |
| 2383 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2384 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2385 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2386 | } |
| 2387 | break; |
| 2388 | } |
| 2389 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2390 | case SOURCE_MANAGER_LINE_TABLE: |
| 2391 | if (ParseLineTable(F, Record)) |
| 2392 | return Failure; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2393 | break; |
| 2394 | |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2395 | case FILE_SOURCE_LOCATION_OFFSETS: |
| 2396 | F.SLocFileOffsets = (const uint32_t *)BlobStart; |
| 2397 | F.LocalNumSLocFileEntries = Record[0]; |
| 2398 | break; |
| 2399 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2400 | case SOURCE_LOCATION_PRELOADS: { |
| 2401 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2402 | // which is based off F.SLocEntryBaseID. |
| 2403 | PreloadSLocEntries.reserve(PreloadSLocEntries.size() + Record.size()); |
| 2404 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2405 | PreloadSLocEntries.push_back(int(Record[I] - 1) + F.SLocEntryBaseID); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2406 | break; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2407 | } |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2408 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2409 | case STAT_CACHE: { |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2410 | if (!DisableStatCache) { |
| 2411 | ASTStatCache *MyStatCache = |
| 2412 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2413 | (const unsigned char *)BlobStart, |
| 2414 | NumStatHits, NumStatMisses); |
| 2415 | FileMgr.addStatCache(MyStatCache); |
| 2416 | F.StatCache = MyStatCache; |
| 2417 | } |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2418 | break; |
Douglas Gregor | d2eb58a | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2419 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2420 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2421 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2422 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2423 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2424 | break; |
| 2425 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2426 | case VTABLE_USES: |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2427 | if (Record.size() % 3 != 0) { |
| 2428 | Error("Invalid VTABLE_USES record"); |
| 2429 | return Failure; |
| 2430 | } |
| 2431 | |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2432 | // Later tables overwrite earlier ones. |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2433 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2434 | // the right way to do this. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2435 | VTableUses.clear(); |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2436 | |
| 2437 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2438 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2439 | VTableUses.push_back( |
| 2440 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2441 | VTableUses.push_back(Record[Idx++]); |
| 2442 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2443 | break; |
| 2444 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2445 | case DYNAMIC_CLASSES: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2446 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2447 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2448 | break; |
| 2449 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2450 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | bbbc367 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2451 | if (PendingInstantiations.size() % 2 != 0) { |
| 2452 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
| 2453 | return Failure; |
| 2454 | } |
| 2455 | |
| 2456 | // Later lists of pending instantiations overwrite earlier ones. |
| 2457 | // FIXME: This is most certainly wrong for modules. |
| 2458 | PendingInstantiations.clear(); |
| 2459 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2460 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2461 | PendingInstantiations.push_back( |
| 2462 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2463 | } |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2464 | break; |
| 2465 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2466 | case SEMA_DECL_REFS: |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2467 | // Later tables overwrite earlier ones. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2468 | // FIXME: Modules will have some trouble with this. |
| 2469 | SemaDeclRefs.clear(); |
| 2470 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2471 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2472 | break; |
| 2473 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2474 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2475 | // The primary AST will be the last to get here, so it will be the one |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2476 | // that's used. |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2477 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2478 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2479 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2480 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2481 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2482 | case ORIGINAL_FILE_ID: |
| 2483 | OriginalFileID = FileID::get(Record[0]); |
| 2484 | break; |
| 2485 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2486 | case ORIGINAL_PCH_DIR: |
| 2487 | // The primary AST will be the last to get here, so it will be the one |
| 2488 | // that's used. |
| 2489 | OriginalDir.assign(BlobStart, BlobLen); |
| 2490 | break; |
| 2491 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2492 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 8bd0929 | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2493 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2494 | StringRef ASTBranch(BlobStart, BlobLen); |
| 2495 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2496 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | d54f3a1 | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2497 | return IgnorePCH; |
| 2498 | } |
| 2499 | break; |
| 2500 | } |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2501 | |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2502 | case MACRO_DEFINITION_OFFSETS: { |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2503 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2504 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2505 | unsigned LocalBasePreprocessedEntityID = Record[1]; |
| 2506 | F.LocalNumMacroDefinitions = Record[2]; |
| 2507 | unsigned LocalBaseMacroID = Record[3]; |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2508 | |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2509 | unsigned StartingID; |
| 2510 | if (PP) { |
| 2511 | if (!PP->getPreprocessingRecord()) |
| 2512 | PP->createPreprocessingRecord(true); |
| 2513 | if (!PP->getPreprocessingRecord()->getExternalSource()) |
| 2514 | PP->getPreprocessingRecord()->SetExternalSource(*this); |
| 2515 | StartingID |
| 2516 | = PP->getPreprocessingRecord() |
| 2517 | ->allocateLoadedEntities(F.NumPreallocatedPreprocessingEntities); |
| 2518 | } else { |
| 2519 | // FIXME: We'll eventually want to kill this path, since it assumes |
| 2520 | // a particular allocation strategy in the preprocessing record. |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2521 | StartingID = getTotalNumPreprocessedEntities() |
| 2522 | - F.NumPreallocatedPreprocessingEntities; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2523 | } |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2524 | F.BaseMacroDefinitionID = getTotalNumMacroDefinitions(); |
| 2525 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2526 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2527 | if (F.NumPreallocatedPreprocessingEntities > 0) { |
| 2528 | // Introduce the global -> local mapping for preprocessed entities in |
| 2529 | // this module. |
| 2530 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2531 | |
| 2532 | // Introduce the local -> global mapping for preprocessed entities in |
| 2533 | // this module. |
| 2534 | F.PreprocessedEntityRemap.insert( |
| 2535 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2536 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2537 | } |
| 2538 | |
| 2539 | |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2540 | if (F.LocalNumMacroDefinitions > 0) { |
| 2541 | // Introduce the global -> local mapping for macro definitions within |
| 2542 | // this module. |
| 2543 | GlobalMacroDefinitionMap.insert( |
| 2544 | std::make_pair(getTotalNumMacroDefinitions() + 1, &F)); |
| 2545 | |
| 2546 | // Introduce the local -> global mapping for macro definitions within |
| 2547 | // this module. |
| 2548 | F.MacroDefinitionRemap.insert( |
| 2549 | std::make_pair(LocalBaseMacroID, |
| 2550 | F.BaseMacroDefinitionID - LocalBaseMacroID)); |
| 2551 | |
| 2552 | MacroDefinitionsLoaded.resize( |
Douglas Gregor | 270e014 | 2011-07-20 01:29:15 +0000 | [diff] [blame] | 2553 | MacroDefinitionsLoaded.size() + F.LocalNumMacroDefinitions); |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2556 | break; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2559 | case DECL_UPDATE_OFFSETS: { |
| 2560 | if (Record.size() % 2 != 0) { |
| 2561 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2562 | return Failure; |
| 2563 | } |
| 2564 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2565 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2566 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2567 | break; |
| 2568 | } |
| 2569 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2570 | case DECL_REPLACEMENTS: { |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2571 | if (Record.size() % 2 != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2572 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2573 | return Failure; |
| 2574 | } |
| 2575 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2576 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
| 2577 | = std::make_pair(&F, Record[I+1]); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2578 | break; |
| 2579 | } |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2580 | |
| 2581 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2582 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2583 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2584 | return Failure; |
| 2585 | } |
| 2586 | |
| 2587 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2588 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 3766fdb | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2589 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2590 | break; |
| 2591 | } |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2592 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2593 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2594 | if (Record.size() % 2 != 0) { |
| 2595 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2596 | return Failure; |
| 2597 | } |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2598 | |
| 2599 | if (F.PragmaDiagMappings.empty()) |
| 2600 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2601 | else |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2602 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2603 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2604 | break; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2605 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2606 | case CUDA_SPECIAL_DECL_REFS: |
| 2607 | // Later tables overwrite earlier ones. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2608 | // FIXME: Modules will have trouble with this. |
| 2609 | CUDASpecialDeclRefs.clear(); |
| 2610 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2611 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2612 | break; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2613 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2614 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2615 | F.HeaderFileInfoTableData = BlobStart; |
| 2616 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2617 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2618 | if (Record[0]) { |
| 2619 | F.HeaderFileInfoTable |
| 2620 | = HeaderFileInfoLookupTable::Create( |
| 2621 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2622 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2623 | HeaderFileInfoTrait(*this, F, |
| 2624 | PP? &PP->getHeaderSearchInfo() : 0, |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2625 | BlobStart + Record[2])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2626 | if (PP) |
| 2627 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2628 | } |
| 2629 | break; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2630 | } |
| 2631 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2632 | case FP_PRAGMA_OPTIONS: |
| 2633 | // Later tables overwrite earlier ones. |
| 2634 | FPPragmaOptions.swap(Record); |
| 2635 | break; |
| 2636 | |
| 2637 | case OPENCL_EXTENSIONS: |
| 2638 | // Later tables overwrite earlier ones. |
| 2639 | OpenCLExtensions.swap(Record); |
| 2640 | break; |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2641 | |
| 2642 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2643 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2644 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2645 | break; |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2646 | |
| 2647 | case KNOWN_NAMESPACES: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2648 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2649 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2650 | break; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2651 | } |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2652 | First = false; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2653 | } |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2654 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2655 | return Failure; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2656 | } |
| 2657 | |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2658 | ASTReader::ASTReadResult ASTReader::validateFileEntries() { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2659 | for (ModuleIterator I = ModuleMgr.begin(), |
| 2660 | E = ModuleMgr.end(); I != E; ++I) { |
| 2661 | Module *F = *I; |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2662 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
| 2663 | |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2664 | for (unsigned i = 0, e = F->LocalNumSLocFileEntries; i != e; ++i) { |
| 2665 | SLocEntryCursor.JumpToBit(F->SLocFileOffsets[i]); |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2666 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 2667 | if (Code == llvm::bitc::END_BLOCK || |
| 2668 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 2669 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 2670 | Error("incorrectly-formatted source location entry in AST file"); |
| 2671 | return Failure; |
| 2672 | } |
| 2673 | |
| 2674 | RecordData Record; |
| 2675 | const char *BlobStart; |
| 2676 | unsigned BlobLen; |
| 2677 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 2678 | default: |
| 2679 | Error("incorrectly-formatted source location entry in AST file"); |
| 2680 | return Failure; |
| 2681 | |
| 2682 | case SM_SLOC_FILE_ENTRY: { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2683 | StringRef Filename(BlobStart, BlobLen); |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2684 | const FileEntry *File = getFileEntry(Filename); |
| 2685 | |
| 2686 | if (File == 0) { |
| 2687 | std::string ErrorStr = "could not find file '"; |
| 2688 | ErrorStr += Filename; |
| 2689 | ErrorStr += "' referenced by AST file"; |
| 2690 | Error(ErrorStr.c_str()); |
| 2691 | return IgnorePCH; |
| 2692 | } |
| 2693 | |
| 2694 | if (Record.size() < 6) { |
| 2695 | Error("source location entry is incorrect"); |
| 2696 | return Failure; |
| 2697 | } |
| 2698 | |
| 2699 | // The stat info from the FileEntry came from the cached stat |
| 2700 | // info of the PCH, so we cannot trust it. |
| 2701 | struct stat StatBuf; |
| 2702 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 2703 | StatBuf.st_size = File->getSize(); |
| 2704 | StatBuf.st_mtime = File->getModificationTime(); |
| 2705 | } |
| 2706 | |
| 2707 | if (((off_t)Record[4] != StatBuf.st_size |
| 2708 | #if !defined(LLVM_ON_WIN32) |
| 2709 | // In our regression testing, the Windows file system seems to |
| 2710 | // have inconsistent modification times that sometimes |
| 2711 | // erroneously trigger this error-handling path. |
| 2712 | || (time_t)Record[5] != StatBuf.st_mtime |
| 2713 | #endif |
| 2714 | )) { |
| 2715 | Error(diag::err_fe_pch_file_modified, Filename); |
| 2716 | return IgnorePCH; |
| 2717 | } |
| 2718 | |
| 2719 | break; |
| 2720 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2721 | } |
| 2722 | } |
| 2723 | } |
| 2724 | |
| 2725 | return Success; |
| 2726 | } |
| 2727 | |
Sebastian Redl | 009e7f2 | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2728 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2729 | ModuleKind Type) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2730 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) { |
Sebastian Redl | 2abc038 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2731 | case Failure: return Failure; |
| 2732 | case IgnorePCH: return IgnorePCH; |
| 2733 | case Success: break; |
| 2734 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2735 | |
| 2736 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2737 | |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2738 | if (!DisableValidation) { |
| 2739 | switch(validateFileEntries()) { |
| 2740 | case Failure: return Failure; |
| 2741 | case IgnorePCH: return IgnorePCH; |
| 2742 | case Success: break; |
| 2743 | } |
| 2744 | } |
| 2745 | |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2746 | // Preload SLocEntries. |
| 2747 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2748 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2749 | if (Result != Success) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2750 | return Failure; |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2751 | } |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2752 | PreloadSLocEntries.clear(); |
| 2753 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2754 | // Check the predefines buffers. |
Douglas Gregor | 9125bd6 | 2011-07-27 16:30:06 +0000 | [diff] [blame] | 2755 | if (!DisableValidation && Type != MK_Module && CheckPredefinesBuffers()) |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2756 | return IgnorePCH; |
| 2757 | |
| 2758 | if (PP) { |
| 2759 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2760 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2761 | // loaded into the IdentifierTable before we intercepted the |
| 2762 | // creation of identifiers. Iterate through the list of known |
| 2763 | // identifiers and determine whether we have to establish |
| 2764 | // preprocessor definitions or top-level identifier declaration |
| 2765 | // chains for those identifiers. |
| 2766 | // |
| 2767 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2768 | // since de-serializing declarations or macro definitions can add |
| 2769 | // new entries into the identifier table, invalidating the |
| 2770 | // iterators. |
Douglas Gregor | 9125bd6 | 2011-07-27 16:30:06 +0000 | [diff] [blame] | 2771 | // |
| 2772 | // FIXME: We need a lazier way to load this information, e.g., by marking |
| 2773 | // the identifier data as 'dirty', so that it will be looked up in the |
| 2774 | // AST file(s) if it is uttered in the source. This could save us some |
| 2775 | // module load time. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2776 | SmallVector<IdentifierInfo *, 128> Identifiers; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2777 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2778 | IdEnd = PP->getIdentifierTable().end(); |
| 2779 | Id != IdEnd; ++Id) |
| 2780 | Identifiers.push_back(Id->second); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2781 | // We need to search the tables in all files. |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2782 | for (ModuleIterator J = ModuleMgr.begin(), |
| 2783 | M = ModuleMgr.end(); J != M; ++J) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2784 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2785 | = (ASTIdentifierLookupTable *)(*J)->IdentifierLookupTable; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2786 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2787 | // ones. |
| 2788 | if (!IdTable) |
| 2789 | continue; |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2790 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2791 | IdentifierInfo *II = Identifiers[I]; |
| 2792 | // Look in the on-disk hash tables for an entry for this identifier |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2793 | ASTIdentifierLookupTrait Info(*this, *(*J), II); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2794 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2795 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2796 | if (Pos == IdTable->end()) |
| 2797 | continue; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2798 | |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2799 | // Dereferencing the iterator has the effect of populating the |
| 2800 | // IdentifierInfo node with the various declarations it needs. |
| 2801 | (void)*Pos; |
| 2802 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | if (Context) |
| 2807 | InitializeContext(*Context); |
| 2808 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2809 | if (DeserializationListener) |
| 2810 | DeserializationListener->ReaderInitialized(this); |
| 2811 | |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2812 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2813 | // the source manager to the file source file from which the preamble was |
| 2814 | // built. This is the only valid way to use a precompiled preamble. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2815 | if (Type == MK_Preamble) { |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2816 | if (OriginalFileID.isInvalid()) { |
| 2817 | SourceLocation Loc |
| 2818 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2819 | if (Loc.isValid()) |
| 2820 | OriginalFileID = SourceMgr.getDecomposedLoc(Loc).first; |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2821 | } |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2822 | else { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2823 | OriginalFileID = FileID::get(ModuleMgr.getPrimaryModule().SLocEntryBaseID |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2824 | + OriginalFileID.getOpaqueValue() - 1); |
| 2825 | } |
| 2826 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2827 | if (!OriginalFileID.isInvalid()) |
| 2828 | SourceMgr.SetPreambleFileID(OriginalFileID); |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2829 | } |
| 2830 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2831 | return Success; |
| 2832 | } |
| 2833 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2834 | ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2835 | ModuleKind Type, |
| 2836 | Module *ImportedBy) { |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2837 | Module *M; |
| 2838 | bool NewModule; |
| 2839 | std::string ErrorStr; |
| 2840 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
| 2841 | ErrorStr); |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2842 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2843 | if (!M) { |
| 2844 | // We couldn't load the module. |
| 2845 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 2846 | + ErrorStr; |
| 2847 | Error(Msg); |
| 2848 | return Failure; |
| 2849 | } |
| 2850 | |
| 2851 | if (!NewModule) { |
| 2852 | // We've already loaded this module. |
| 2853 | return Success; |
| 2854 | } |
| 2855 | |
| 2856 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 2857 | // module? |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2858 | if (FileName != "-") { |
| 2859 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2860 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2861 | } |
| 2862 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2863 | Module &F = *M; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2864 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2865 | Stream.init(F.StreamFile); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2866 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2867 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2868 | // Sniff for the signature. |
| 2869 | if (Stream.Read(8) != 'C' || |
| 2870 | Stream.Read(8) != 'P' || |
| 2871 | Stream.Read(8) != 'C' || |
| 2872 | Stream.Read(8) != 'H') { |
| 2873 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2874 | return Failure; |
| 2875 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2876 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2877 | while (!Stream.AtEndOfStream()) { |
| 2878 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2879 | |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2880 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2881 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2882 | return Failure; |
| 2883 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2884 | |
| 2885 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2886 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2887 | // We only know the AST subblock ID. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2888 | switch (BlockID) { |
| 2889 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2890 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2891 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2892 | return Failure; |
| 2893 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2894 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2895 | case AST_BLOCK_ID: |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2896 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2897 | case Success: |
| 2898 | break; |
| 2899 | |
| 2900 | case Failure: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2901 | return Failure; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2902 | |
| 2903 | case IgnorePCH: |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2904 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2905 | // AST block, skipping subblocks, to see if there are other |
| 2906 | // AST blocks elsewhere. |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2907 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2908 | // FIXME: We can't clear loaded slocentries anymore. |
| 2909 | //SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2910 | |
| 2911 | // Remove the stat cache. |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2912 | if (F.StatCache) |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2913 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2914 | |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2915 | return IgnorePCH; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2916 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2917 | break; |
| 2918 | default: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2919 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2920 | Error("malformed block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2921 | return Failure; |
| 2922 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2923 | break; |
| 2924 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2925 | } |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2926 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2927 | // Once read, set the Module bit base offset and update the size in |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2928 | // bits of all files we've seen. |
| 2929 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 2930 | TotalModulesSizeInBits += F.SizeInBits; |
| 2931 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
Sebastian Redl | 2abc038 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2932 | return Success; |
| 2933 | } |
| 2934 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2935 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2936 | PP = &pp; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2937 | |
| 2938 | if (unsigned N = getTotalNumPreprocessedEntities()) { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2939 | if (!PP->getPreprocessingRecord()) |
Douglas Gregor | 998caea | 2011-05-06 16:33:08 +0000 | [diff] [blame] | 2940 | PP->createPreprocessingRecord(true); |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2941 | PP->getPreprocessingRecord()->SetExternalSource(*this); |
| 2942 | PP->getPreprocessingRecord()->allocateLoadedEntities(N); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2943 | } |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2944 | |
| 2945 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2946 | PP->getHeaderSearchInfo().SetExternalSource(this); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2949 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2950 | Context = &Ctx; |
| 2951 | assert(Context && "Passed null context!"); |
| 2952 | |
| 2953 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2954 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2955 | PP->setExternalSource(this); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2956 | |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2957 | // If we have an update block for the TU waiting, we have to add it before |
| 2958 | // deserializing the decl. |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2959 | TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl(); |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2960 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2961 | if (DCU != DeclContextOffsets.end()) { |
| 2962 | // Insertion could invalidate map, so grab vector. |
| 2963 | DeclContextInfos T; |
| 2964 | T.swap(DCU->second); |
| 2965 | DeclContextOffsets.erase(DCU); |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2966 | DeclContextOffsets[TU].swap(T); |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2967 | } |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2968 | |
| 2969 | // If there's a listener, notify them that we "read" the translation unit. |
| 2970 | if (DeserializationListener) |
| 2971 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, TU); |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2972 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2973 | // Make sure we load the declaration update records for the translation unit, |
| 2974 | // if there are any. |
| 2975 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, TU); |
| 2976 | |
| 2977 | // Note that the translation unit has external lexical and visible storage. |
| 2978 | TU->setHasExternalLexicalStorage(true); |
| 2979 | TU->setHasExternalVisibleStorage(true); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2980 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2981 | // FIXME: Find a better way to deal with collisions between these |
| 2982 | // built-in types. Right now, we just ignore the problem. |
| 2983 | |
| 2984 | // Load the special types. |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2985 | if (Context->getBuiltinVaListType().isNull()) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2986 | Context->setBuiltinVaListType( |
| 2987 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2988 | } |
| 2989 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2990 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) { |
| 2991 | if (Context->ObjCProtoType.isNull()) |
Douglas Gregor | 09c4aa8 | 2011-08-11 22:04:35 +0000 | [diff] [blame] | 2992 | Context->ObjCProtoType = GetType(Proto); |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2993 | } |
| 2994 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2995 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 2996 | if (!Context->CFConstantStringTypeDecl) |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2997 | Context->setCFConstantStringType(GetType(String)); |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 3001 | QualType FileType = GetType(File); |
| 3002 | if (FileType.isNull()) { |
| 3003 | Error("FILE type is NULL"); |
| 3004 | return; |
| 3005 | } |
| 3006 | |
| 3007 | if (!Context->FILEDecl) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3008 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 3009 | Context->setFILEDecl(Typedef->getDecl()); |
| 3010 | else { |
| 3011 | const TagType *Tag = FileType->getAs<TagType>(); |
| 3012 | if (!Tag) { |
| 3013 | Error("Invalid FILE type in AST file"); |
| 3014 | return; |
| 3015 | } |
| 3016 | Context->setFILEDecl(Tag->getDecl()); |
| 3017 | } |
Douglas Gregor | 27821ce | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 3018 | } |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
| 3022 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 3023 | if (Jmp_bufType.isNull()) { |
| 3024 | Error("jmp_buf type is NULL"); |
| 3025 | return; |
| 3026 | } |
| 3027 | |
| 3028 | if (!Context->jmp_bufDecl) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3029 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 3030 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 3031 | else { |
| 3032 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 3033 | if (!Tag) { |
| 3034 | Error("Invalid jmp_buf type in AST file"); |
| 3035 | return; |
| 3036 | } |
| 3037 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 3038 | } |
Mike Stump | a4de80b | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 3039 | } |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
| 3043 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 3044 | if (Sigjmp_bufType.isNull()) { |
| 3045 | Error("sigjmp_buf type is NULL"); |
| 3046 | return; |
| 3047 | } |
| 3048 | |
| 3049 | if (!Context->sigjmp_bufDecl) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3050 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 3051 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 3052 | else { |
| 3053 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 3054 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 3055 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 3056 | } |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3057 | } |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3058 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 3059 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 3060 | if (unsigned ObjCIdRedef |
| 3061 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 3062 | if (Context->ObjCIdRedefinitionType.isNull()) |
| 3063 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 3064 | } |
| 3065 | |
| 3066 | if (unsigned ObjCClassRedef |
| 3067 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 3068 | if (Context->ObjCClassRedefinitionType.isNull()) |
| 3069 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 3070 | } |
| 3071 | |
| 3072 | if (unsigned ObjCSelRedef |
| 3073 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 3074 | if (Context->ObjCSelRedefinitionType.isNull()) |
| 3075 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 3076 | } |
| 3077 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3078 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3079 | |
| 3080 | // If there were any CUDA special declarations, deserialize them. |
| 3081 | if (!CUDASpecialDeclRefs.empty()) { |
| 3082 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 3083 | Context->setcudaConfigureCallDecl( |
| 3084 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 3085 | } |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3086 | } |
| 3087 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3088 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3089 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3090 | /// file. |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3091 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 71731d6 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 3092 | FileManager &FileMgr, |
Daniel Dunbar | 3b95148 | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 3093 | Diagnostic &Diags) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3094 | // Open the AST file. |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3095 | std::string ErrStr; |
| 3096 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 5159f61 | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 3097 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3098 | if (!Buffer) { |
Daniel Dunbar | 3b95148 | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 3099 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3100 | return std::string(); |
| 3101 | } |
| 3102 | |
| 3103 | // Initialize the stream |
| 3104 | llvm::BitstreamReader StreamFile; |
| 3105 | llvm::BitstreamCursor Stream; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3106 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3107 | (const unsigned char *)Buffer->getBufferEnd()); |
| 3108 | Stream.init(StreamFile); |
| 3109 | |
| 3110 | // Sniff for the signature. |
| 3111 | if (Stream.Read(8) != 'C' || |
| 3112 | Stream.Read(8) != 'P' || |
| 3113 | Stream.Read(8) != 'C' || |
| 3114 | Stream.Read(8) != 'H') { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3115 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3116 | return std::string(); |
| 3117 | } |
| 3118 | |
| 3119 | RecordData Record; |
| 3120 | while (!Stream.AtEndOfStream()) { |
| 3121 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3122 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3123 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3124 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3125 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3126 | // We only know the AST subblock ID. |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3127 | switch (BlockID) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3128 | case AST_BLOCK_ID: |
| 3129 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3130 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3131 | return std::string(); |
| 3132 | } |
| 3133 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3134 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3135 | default: |
| 3136 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3137 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3138 | return std::string(); |
| 3139 | } |
| 3140 | break; |
| 3141 | } |
| 3142 | continue; |
| 3143 | } |
| 3144 | |
| 3145 | if (Code == llvm::bitc::END_BLOCK) { |
| 3146 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3147 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3148 | return std::string(); |
| 3149 | } |
| 3150 | continue; |
| 3151 | } |
| 3152 | |
| 3153 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3154 | Stream.ReadAbbrevRecord(); |
| 3155 | continue; |
| 3156 | } |
| 3157 | |
| 3158 | Record.clear(); |
| 3159 | const char *BlobStart = 0; |
| 3160 | unsigned BlobLen = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3161 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3162 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3163 | return std::string(BlobStart, BlobLen); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3164 | } |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3165 | |
| 3166 | return std::string(); |
| 3167 | } |
| 3168 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3169 | /// \brief Parse the record that corresponds to a LangOptions data |
| 3170 | /// structure. |
| 3171 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3172 | /// This routine parses the language options from the AST file and then gives |
| 3173 | /// them to the AST listener if one is set. |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3174 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3175 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3176 | bool ASTReader::ParseLanguageOptions( |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3177 | const SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3178 | if (Listener) { |
| 3179 | LangOptions LangOpts; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3180 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3181 | #define PARSE_LANGOPT(Option) \ |
| 3182 | LangOpts.Option = Record[Idx]; \ |
| 3183 | ++Idx |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3184 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3185 | unsigned Idx = 0; |
| 3186 | PARSE_LANGOPT(Trigraphs); |
| 3187 | PARSE_LANGOPT(BCPLComment); |
| 3188 | PARSE_LANGOPT(DollarIdents); |
| 3189 | PARSE_LANGOPT(AsmPreprocessor); |
| 3190 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | e03aa55 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 3191 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3192 | PARSE_LANGOPT(ImplicitInt); |
| 3193 | PARSE_LANGOPT(Digraphs); |
| 3194 | PARSE_LANGOPT(HexFloats); |
| 3195 | PARSE_LANGOPT(C99); |
Peter Collingbourne | a686b5f | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 3196 | PARSE_LANGOPT(C1X); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3197 | PARSE_LANGOPT(Microsoft); |
| 3198 | PARSE_LANGOPT(CPlusPlus); |
| 3199 | PARSE_LANGOPT(CPlusPlus0x); |
| 3200 | PARSE_LANGOPT(CXXOperatorNames); |
| 3201 | PARSE_LANGOPT(ObjC1); |
| 3202 | PARSE_LANGOPT(ObjC2); |
| 3203 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 4587803 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 3204 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | 13f3b2f | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 3205 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | 1d56c9e | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 3206 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Douglas Gregor | a860e6a | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 3207 | PARSE_LANGOPT(ObjCInferRelatedResultType); |
Fariborz Jahanian | 62c5602 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 3208 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3209 | PARSE_LANGOPT(PascalStrings); |
| 3210 | PARSE_LANGOPT(WritableStrings); |
| 3211 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 3212 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3213 | PARSE_LANGOPT(Exceptions); |
Anders Carlsson | ce8dd3a | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 3214 | PARSE_LANGOPT(ObjCExceptions); |
Anders Carlsson | 6bbd268 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 3215 | PARSE_LANGOPT(CXXExceptions); |
| 3216 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | dbe3927 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 3217 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3218 | PARSE_LANGOPT(NeXTRuntime); |
| 3219 | PARSE_LANGOPT(Freestanding); |
| 3220 | PARSE_LANGOPT(NoBuiltin); |
| 3221 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | b3286fe | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 3222 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3223 | PARSE_LANGOPT(Blocks); |
| 3224 | PARSE_LANGOPT(EmitAllDecls); |
| 3225 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3226 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 3227 | Record[Idx++]); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3228 | PARSE_LANGOPT(HeinousExtensions); |
| 3229 | PARSE_LANGOPT(Optimize); |
| 3230 | PARSE_LANGOPT(OptimizeSize); |
| 3231 | PARSE_LANGOPT(Static); |
| 3232 | PARSE_LANGOPT(PICLevel); |
| 3233 | PARSE_LANGOPT(GNUInline); |
| 3234 | PARSE_LANGOPT(NoInline); |
Chandler Carruth | 7ffce73 | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 3235 | PARSE_LANGOPT(Deprecated); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3236 | PARSE_LANGOPT(AccessControl); |
| 3237 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | ed4e295 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 3238 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | a88942a | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 3239 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3240 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 457a04e | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 3241 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 3242 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3243 | Record[Idx++]); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3244 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 3245 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 546d079 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 3246 | PARSE_LANGOPT(CUDA); |
Mike Stump | d954638 | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 3247 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3248 | PARSE_LANGOPT(DefaultFPContract); |
Roman Divacky | dc1f68d | 2011-03-01 17:36:40 +0000 | [diff] [blame] | 3249 | PARSE_LANGOPT(ElideConstructors); |
| 3250 | PARSE_LANGOPT(SpellChecking); |
Roman Divacky | 65b88cd | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 3251 | PARSE_LANGOPT(MRTD); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3252 | PARSE_LANGOPT(ObjCAutoRefCount); |
Douglas Gregor | 49b236a | 2011-08-04 15:46:00 +0000 | [diff] [blame] | 3253 | PARSE_LANGOPT(ObjCInferRelatedReturnType); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3254 | #undef PARSE_LANGOPT |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3255 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3256 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3257 | } |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3258 | |
| 3259 | return false; |
| 3260 | } |
| 3261 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3262 | void ASTReader::ReadPreprocessedEntities() { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3263 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
| 3264 | Module &F = *(*I); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3265 | if (!F.PreprocessorDetailCursor.getBitStreamReader()) |
| 3266 | continue; |
| 3267 | |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3268 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3269 | F.PreprocessorDetailCursor.JumpToBit(F.PreprocessorDetailStartOffset); |
| 3270 | while (LoadPreprocessedEntity(F)) { } |
| 3271 | } |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3272 | } |
| 3273 | |
Douglas Gregor | 46c5001 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 3274 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3275 | RecordLocation Loc = getLocalBitOffset(Offset); |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3276 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3277 | // Keep track of where we are in the stream, then jump back there |
| 3278 | // after reading this entity. |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3279 | SavedStreamPosition SavedPosition(Loc.F->PreprocessorDetailCursor); |
| 3280 | Loc.F->PreprocessorDetailCursor.JumpToBit(Loc.Offset); |
| 3281 | return LoadPreprocessedEntity(*Loc.F); |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3284 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3285 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
| 3286 | Module &F = *(*I); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 3287 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3288 | HeaderFileInfoTrait Trait(*this, F, &PP->getHeaderSearchInfo(), |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 3289 | F.HeaderFileFrameworkStrings, |
| 3290 | FE->getName()); |
| 3291 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3292 | HeaderFileInfoLookupTable *Table |
| 3293 | = static_cast<HeaderFileInfoLookupTable *>(F.HeaderFileInfoTable); |
| 3294 | if (!Table) |
| 3295 | continue; |
| 3296 | |
| 3297 | // Look in the on-disk hash table for an entry for this file name. |
| 3298 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE->getName(), |
| 3299 | &Trait); |
| 3300 | if (Pos == Table->end()) |
| 3301 | continue; |
| 3302 | |
| 3303 | HeaderFileInfo HFI = *Pos; |
| 3304 | if (Listener) |
| 3305 | Listener->ReadHeaderFileInfo(HFI, FE->getUID()); |
| 3306 | |
| 3307 | return HFI; |
| 3308 | } |
| 3309 | |
| 3310 | return HeaderFileInfo(); |
| 3311 | } |
| 3312 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3313 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3314 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
| 3315 | Module &F = *(*I); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3316 | unsigned Idx = 0; |
| 3317 | while (Idx < F.PragmaDiagMappings.size()) { |
| 3318 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 3319 | while (1) { |
| 3320 | assert(Idx < F.PragmaDiagMappings.size() && |
| 3321 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 3322 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 3323 | break; // Something is messed up but at least avoid infinite loop in |
| 3324 | // release build. |
| 3325 | } |
| 3326 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 3327 | if (DiagID == (unsigned)-1) { |
| 3328 | break; // no more diag/map pairs for this location. |
| 3329 | } |
| 3330 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
| 3331 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 3332 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3333 | } |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3334 | } |
| 3335 | } |
| 3336 | |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3337 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3338 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3339 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | 3500568 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 3340 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 3341 | Module *M = I->second; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3342 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3343 | } |
| 3344 | |
| 3345 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3346 | /// |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3347 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 3348 | /// routine actually reads the record corresponding to the type at the given |
| 3349 | /// location. It is a helper routine for GetType, which deals with reading type |
| 3350 | /// IDs. |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3351 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3352 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3353 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3354 | |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3355 | // Keep track of where we are in the stream, then jump back there |
| 3356 | // after reading this type. |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3357 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3358 | |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3359 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | eaa4ade | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3360 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3361 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3362 | Deserializing AType(this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3363 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3364 | unsigned Idx = 0; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3365 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3366 | RecordData Record; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3367 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3368 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 3369 | case TYPE_EXT_QUAL: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3370 | if (Record.size() != 2) { |
| 3371 | Error("Incorrect encoding of extended qualifier type"); |
| 3372 | return QualType(); |
| 3373 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3374 | QualType Base = readType(*Loc.F, Record, Idx); |
| 3375 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3376 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 455b8f4 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3377 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3378 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3379 | case TYPE_COMPLEX: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3380 | if (Record.size() != 1) { |
| 3381 | Error("Incorrect encoding of complex type"); |
| 3382 | return QualType(); |
| 3383 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3384 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3385 | return Context->getComplexType(ElemType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3386 | } |
| 3387 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3388 | case TYPE_POINTER: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3389 | if (Record.size() != 1) { |
| 3390 | Error("Incorrect encoding of pointer type"); |
| 3391 | return QualType(); |
| 3392 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3393 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3394 | return Context->getPointerType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3395 | } |
| 3396 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3397 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3398 | if (Record.size() != 1) { |
| 3399 | Error("Incorrect encoding of block pointer type"); |
| 3400 | return QualType(); |
| 3401 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3402 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3403 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3404 | } |
| 3405 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3406 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3407 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3408 | Error("Incorrect encoding of lvalue reference type"); |
| 3409 | return QualType(); |
| 3410 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3411 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3412 | return Context->getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3413 | } |
| 3414 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3415 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3416 | if (Record.size() != 1) { |
| 3417 | Error("Incorrect encoding of rvalue reference type"); |
| 3418 | return QualType(); |
| 3419 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3420 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3421 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3422 | } |
| 3423 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3424 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | ee776bc | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3425 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3426 | Error("Incorrect encoding of member pointer type"); |
| 3427 | return QualType(); |
| 3428 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3429 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 3430 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0cdc832 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3431 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3432 | return QualType(); |
| 3433 | |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3434 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3435 | } |
| 3436 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3437 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3438 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3439 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3440 | unsigned IndexTypeQuals = Record[2]; |
| 3441 | unsigned Idx = 3; |
| 3442 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3443 | return Context->getConstantArrayType(ElementType, Size, |
| 3444 | ASM, IndexTypeQuals); |
| 3445 | } |
| 3446 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3447 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3448 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3449 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3450 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3451 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3452 | } |
| 3453 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3454 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3455 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3456 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3457 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3458 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3459 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 3460 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3461 | ASM, IndexTypeQuals, |
| 3462 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3463 | } |
| 3464 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3465 | case TYPE_VECTOR: { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3466 | if (Record.size() != 3) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3467 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3468 | return QualType(); |
| 3469 | } |
| 3470 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3471 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3472 | unsigned NumElements = Record[1]; |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3473 | unsigned VecKind = Record[2]; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3474 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3475 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3476 | } |
| 3477 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3478 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3479 | if (Record.size() != 3) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3480 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3481 | return QualType(); |
| 3482 | } |
| 3483 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3484 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3485 | unsigned NumElements = Record[1]; |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3486 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3487 | } |
| 3488 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3489 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3490 | if (Record.size() != 6) { |
Douglas Gregor | 6f00bf8 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3491 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3492 | return QualType(); |
| 3493 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3494 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3495 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 3496 | (CallingConv)Record[4], Record[5]); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 3497 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3498 | } |
| 3499 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3500 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3501 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3502 | |
| 3503 | FunctionProtoType::ExtProtoInfo EPI; |
| 3504 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3505 | /*hasregparm*/ Record[2], |
| 3506 | /*regparm*/ Record[3], |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3507 | static_cast<CallingConv>(Record[4]), |
| 3508 | /*produces*/ Record[5]); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3509 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3510 | unsigned Idx = 6; |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3511 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3512 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3513 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3514 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3515 | |
| 3516 | EPI.Variadic = Record[Idx++]; |
| 3517 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3518 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3519 | ExceptionSpecificationType EST = |
| 3520 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3521 | EPI.ExceptionSpecType = EST; |
| 3522 | if (EST == EST_Dynamic) { |
| 3523 | EPI.NumExceptions = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3524 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3525 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3526 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3527 | EPI.Exceptions = Exceptions.data(); |
| 3528 | } else if (EST == EST_ComputedNoexcept) { |
| 3529 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
| 3530 | } |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 3531 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3532 | EPI); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3533 | } |
| 3534 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3535 | case TYPE_UNRESOLVED_USING: { |
| 3536 | unsigned Idx = 0; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3537 | return Context->getTypeDeclType( |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3538 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 3539 | } |
| 3540 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3541 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3542 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3543 | Error("incorrect encoding of typedef type"); |
| 3544 | return QualType(); |
| 3545 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3546 | unsigned Idx = 0; |
| 3547 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3548 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | f86c939 | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3549 | if (!Canonical.isNull()) |
| 3550 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3551 | return Context->getTypedefType(Decl, Canonical); |
| 3552 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3553 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3554 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3555 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3556 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3557 | case TYPE_TYPEOF: { |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3558 | if (Record.size() != 1) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3559 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3560 | return QualType(); |
| 3561 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3562 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3563 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3564 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3565 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3566 | case TYPE_DECLTYPE: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3567 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3568 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3569 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3570 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 3571 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3572 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
| 3573 | return Context->getUnaryTransformType(BaseType, UnderlyingType, UKind); |
| 3574 | } |
| 3575 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3576 | case TYPE_AUTO: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3577 | return Context->getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3578 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3579 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3580 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3581 | Error("incorrect encoding of record type"); |
| 3582 | return QualType(); |
| 3583 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3584 | unsigned Idx = 0; |
| 3585 | bool IsDependent = Record[Idx++]; |
| 3586 | QualType T |
| 3587 | = Context->getRecordType(ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx)); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3588 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3589 | return T; |
| 3590 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3591 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3592 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3593 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3594 | Error("incorrect encoding of enum type"); |
| 3595 | return QualType(); |
| 3596 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3597 | unsigned Idx = 0; |
| 3598 | bool IsDependent = Record[Idx++]; |
| 3599 | QualType T |
| 3600 | = Context->getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3601 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3602 | return T; |
| 3603 | } |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3604 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3605 | case TYPE_ATTRIBUTED: { |
| 3606 | if (Record.size() != 3) { |
| 3607 | Error("incorrect encoding of attributed type"); |
| 3608 | return QualType(); |
| 3609 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3610 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 3611 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3612 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 3613 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 3614 | } |
| 3615 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3616 | case TYPE_PAREN: { |
| 3617 | if (Record.size() != 1) { |
| 3618 | Error("incorrect encoding of paren type"); |
| 3619 | return QualType(); |
| 3620 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3621 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3622 | return Context->getParenType(InnerType); |
| 3623 | } |
| 3624 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3625 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | 1732850 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3626 | if (Record.size() != 2) { |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3627 | Error("incorrect encoding of pack expansion type"); |
| 3628 | return QualType(); |
| 3629 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3630 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3631 | if (Pattern.isNull()) |
| 3632 | return QualType(); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3633 | llvm::Optional<unsigned> NumExpansions; |
| 3634 | if (Record[1]) |
| 3635 | NumExpansions = Record[1] - 1; |
| 3636 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3637 | } |
| 3638 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3639 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3640 | unsigned Idx = 0; |
| 3641 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3642 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3643 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3644 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3645 | } |
| 3646 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3647 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3648 | unsigned Idx = 0; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3649 | ObjCInterfaceDecl *ItfD |
| 3650 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3651 | return Context->getObjCInterfaceType(ItfD); |
| 3652 | } |
| 3653 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3654 | case TYPE_OBJC_OBJECT: { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3655 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3656 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3657 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3658 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3659 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3660 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3661 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3662 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3663 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3664 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | 6e054af | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3665 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3666 | QualType Pointee = readType(*Loc.F, Record, Idx); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3667 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | 6e054af | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3668 | } |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3669 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3670 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3671 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3672 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 3673 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3674 | return |
| 3675 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3676 | Replacement); |
| 3677 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3678 | |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3679 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3680 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3681 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3682 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3683 | return Context->getSubstTemplateTypeParmPackType( |
| 3684 | cast<TemplateTypeParmType>(Parm), |
| 3685 | ArgPack); |
| 3686 | } |
| 3687 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3688 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3689 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3690 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | dab33c5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3691 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3692 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | dab33c5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3693 | return |
| 3694 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3695 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3696 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3697 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3698 | unsigned Idx = 0; |
| 3699 | unsigned Depth = Record[Idx++]; |
| 3700 | unsigned Index = Record[Idx++]; |
| 3701 | bool Pack = Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3702 | TemplateTypeParmDecl *D |
| 3703 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 3704 | return Context->getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3705 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3706 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3707 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3708 | unsigned Idx = 0; |
| 3709 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3710 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3711 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3712 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | f86c939 | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3713 | if (!Canon.isNull()) |
| 3714 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | e929095 | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3715 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3716 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3717 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3718 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3719 | unsigned Idx = 0; |
| 3720 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3721 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3722 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3723 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3724 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3725 | Args.reserve(NumArgs); |
| 3726 | while (NumArgs--) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3727 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3728 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3729 | Args.size(), Args.data()); |
| 3730 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3731 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3732 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3733 | unsigned Idx = 0; |
| 3734 | |
| 3735 | // ArrayType |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3736 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3737 | ArrayType::ArraySizeModifier ASM |
| 3738 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3739 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3740 | |
| 3741 | // DependentSizedArrayType |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3742 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3743 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3744 | |
| 3745 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3746 | IndexTypeQuals, Brackets); |
| 3747 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3748 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3749 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3750 | unsigned Idx = 0; |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3751 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3752 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3753 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3754 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3755 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3756 | QualType T; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3757 | if (Underlying.isNull()) |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3758 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3759 | Args.size()); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3760 | else |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3761 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3762 | Args.size(), Underlying); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3763 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3764 | return T; |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3765 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3766 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3767 | // Suppress a GCC warning |
| 3768 | return QualType(); |
| 3769 | } |
| 3770 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3771 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3772 | ASTReader &Reader; |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3773 | Module &F; |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3774 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3775 | const ASTReader::RecordData &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3776 | unsigned &Idx; |
| 3777 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3778 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3779 | unsigned &I) { |
| 3780 | return Reader.ReadSourceLocation(F, R, I); |
| 3781 | } |
| 3782 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3783 | template<typename T> |
| 3784 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 3785 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 3786 | } |
| 3787 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3788 | public: |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3789 | TypeLocReader(ASTReader &Reader, Module &F, |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3790 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3791 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3792 | { } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3793 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3794 | // We want compile-time assurance that we've enumerated all of |
| 3795 | // these, so unfortunately we have to declare them first, then |
| 3796 | // define them out-of-line. |
| 3797 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3798 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3799 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3800 | #include "clang/AST/TypeLocNodes.def" |
| 3801 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3802 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3803 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3804 | }; |
| 3805 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3806 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3807 | // nothing to do |
| 3808 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3809 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3810 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3811 | if (TL.needsExtraLocalData()) { |
| 3812 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3813 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3814 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3815 | TL.setModeAttr(Record[Idx++]); |
| 3816 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3817 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3818 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3819 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3820 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3821 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3822 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3823 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3824 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3825 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3826 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3827 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3828 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3829 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3830 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3831 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3832 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3833 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3834 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3835 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3836 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3837 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3838 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3839 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3840 | if (Record[Idx++]) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3841 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3842 | else |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3843 | TL.setSizeExpr(0); |
| 3844 | } |
| 3845 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3846 | VisitArrayTypeLoc(TL); |
| 3847 | } |
| 3848 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3849 | VisitArrayTypeLoc(TL); |
| 3850 | } |
| 3851 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3852 | VisitArrayTypeLoc(TL); |
| 3853 | } |
| 3854 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3855 | DependentSizedArrayTypeLoc TL) { |
| 3856 | VisitArrayTypeLoc(TL); |
| 3857 | } |
| 3858 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3859 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3860 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3861 | } |
| 3862 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3863 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3864 | } |
| 3865 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3866 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3867 | } |
| 3868 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3869 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 3870 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3871 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3872 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3873 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3874 | } |
| 3875 | } |
| 3876 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3877 | VisitFunctionTypeLoc(TL); |
| 3878 | } |
| 3879 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3880 | VisitFunctionTypeLoc(TL); |
| 3881 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3882 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3883 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3884 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3885 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3886 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3887 | } |
| 3888 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3889 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3890 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3891 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3892 | } |
| 3893 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3894 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3895 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3896 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3897 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3898 | } |
| 3899 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3900 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3901 | } |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3902 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 3903 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 3904 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3905 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3906 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 3907 | } |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3908 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3909 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3910 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3911 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3912 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3913 | } |
| 3914 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3915 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3916 | } |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3917 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3918 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3919 | if (TL.hasAttrOperand()) { |
| 3920 | SourceRange range; |
| 3921 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3922 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3923 | TL.setAttrOperandParensRange(range); |
| 3924 | } |
| 3925 | if (TL.hasAttrExprOperand()) { |
| 3926 | if (Record[Idx++]) |
| 3927 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3928 | else |
| 3929 | TL.setAttrExprOperand(0); |
| 3930 | } else if (TL.hasAttrEnumOperand()) |
| 3931 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3932 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3933 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3934 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3935 | } |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3936 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3937 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3938 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3939 | } |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3940 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3941 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3942 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3943 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3944 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3945 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3946 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3947 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3948 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3949 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3950 | TL.setArgLocInfo(i, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3951 | Reader.GetTemplateArgumentLocInfo(F, |
| 3952 | TL.getTypePtr()->getArg(i).getKind(), |
| 3953 | Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3954 | } |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3955 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3956 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3957 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3958 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3959 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3960 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3961 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3962 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3963 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3964 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3965 | } |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3966 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3967 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3968 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3969 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3970 | } |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3971 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3972 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3973 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3974 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3975 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3976 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3977 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3978 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3979 | TL.setArgLocInfo(I, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3980 | Reader.GetTemplateArgumentLocInfo(F, |
| 3981 | TL.getTypePtr()->getArg(I).getKind(), |
| 3982 | Record, Idx)); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3983 | } |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3984 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3985 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3986 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3987 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3988 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3989 | } |
| 3990 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3991 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3992 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3993 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3994 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3995 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3996 | } |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3997 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3998 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3999 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4000 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4001 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4002 | const RecordData &Record, |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4003 | unsigned &Idx) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4004 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4005 | if (InfoTy.isNull()) |
| 4006 | return 0; |
| 4007 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4008 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4009 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4010 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4011 | TLR.Visit(TL); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4012 | return TInfo; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4013 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4014 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4015 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4016 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 4017 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4018 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4019 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4020 | QualType T; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4021 | switch ((PredefinedTypeIDs)Index) { |
| 4022 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 4023 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 4024 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4025 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4026 | case PREDEF_TYPE_CHAR_U_ID: |
| 4027 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4028 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4029 | T = Context->CharTy; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4030 | break; |
| 4031 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4032 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 4033 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 4034 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 4035 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 4036 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 4037 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 4038 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 4039 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 4040 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 4041 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 4042 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 4043 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 4044 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 4045 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 4046 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 4047 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 4048 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
John McCall | 0009fcc | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 4049 | case PREDEF_TYPE_BOUND_MEMBER: T = Context->BoundMemberTy; break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4050 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
John McCall | 3199634 | 2011-04-07 08:22:57 +0000 | [diff] [blame] | 4051 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context->UnknownAnyTy; break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4052 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 4053 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 4054 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 4055 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 4056 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 4057 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4058 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context->getAutoDeductType(); break; |
| 4059 | |
| 4060 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
| 4061 | T = Context->getAutoRRefDeductType(); |
| 4062 | break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4066 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4067 | } |
| 4068 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4069 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4070 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 409183f | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4071 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4072 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4073 | if (TypesLoaded[Index].isNull()) |
| 4074 | return QualType(); |
| 4075 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4076 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4077 | if (DeserializationListener) |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4078 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 4079 | TypesLoaded[Index]); |
Sebastian Redl | 409183f | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4080 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4081 | |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4082 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4083 | } |
| 4084 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4085 | QualType ASTReader::getLocalType(Module &F, unsigned LocalID) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4086 | return GetType(getGlobalTypeID(F, LocalID)); |
| 4087 | } |
| 4088 | |
| 4089 | serialization::TypeID |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4090 | ASTReader::getGlobalTypeID(Module &F, unsigned LocalID) const { |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4091 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 4092 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 4093 | |
| 4094 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 4095 | return LocalID; |
| 4096 | |
| 4097 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4098 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 4099 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 4100 | |
| 4101 | unsigned GlobalIndex = LocalIndex + I->second; |
| 4102 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 4103 | } |
| 4104 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4105 | TemplateArgumentLocInfo |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4106 | ASTReader::GetTemplateArgumentLocInfo(Module &F, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4107 | TemplateArgument::ArgKind Kind, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4108 | const RecordData &Record, |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4109 | unsigned &Index) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4110 | switch (Kind) { |
| 4111 | case TemplateArgument::Expression: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4112 | return ReadExpr(F); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4113 | case TemplateArgument::Type: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4114 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4115 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4116 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4117 | Index); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4118 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4119 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4120 | SourceLocation()); |
| 4121 | } |
| 4122 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4123 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4124 | Index); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4125 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4126 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4127 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4128 | EllipsisLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4129 | } |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4130 | case TemplateArgument::Null: |
| 4131 | case TemplateArgument::Integral: |
| 4132 | case TemplateArgument::Declaration: |
| 4133 | case TemplateArgument::Pack: |
| 4134 | return TemplateArgumentLocInfo(); |
| 4135 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 4136 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4137 | return TemplateArgumentLocInfo(); |
| 4138 | } |
| 4139 | |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4140 | TemplateArgumentLoc |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4141 | ASTReader::ReadTemplateArgumentLoc(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4142 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4143 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4144 | |
| 4145 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 4146 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 4147 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 4148 | } |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4149 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4150 | Record, Index)); |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4151 | } |
| 4152 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4153 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4154 | return GetDecl(ID); |
| 4155 | } |
| 4156 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4157 | uint64_t ASTReader::readCXXBaseSpecifiers(Module &M, const RecordData &Record, |
| 4158 | unsigned &Idx){ |
| 4159 | if (Idx >= Record.size()) |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4160 | return 0; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4161 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4162 | unsigned LocalID = Record[Idx++]; |
| 4163 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4167 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4168 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4169 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4170 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4171 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 4172 | RecordData Record; |
| 4173 | unsigned Code = Cursor.ReadCode(); |
| 4174 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 4175 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 4176 | Error("Malformed AST file: missing C++ base specifiers"); |
| 4177 | return 0; |
| 4178 | } |
| 4179 | |
| 4180 | unsigned Idx = 0; |
| 4181 | unsigned NumBases = Record[Idx++]; |
| 4182 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 4183 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 4184 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4185 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4186 | return Bases; |
| 4187 | } |
| 4188 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4189 | serialization::DeclID |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4190 | ASTReader::getGlobalDeclID(Module &F, unsigned LocalID) const { |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4191 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4192 | return LocalID; |
| 4193 | |
| 4194 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4195 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4196 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 4197 | |
| 4198 | return LocalID + I->second; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4199 | } |
| 4200 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4201 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4202 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 4203 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4204 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4205 | return 0; |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4206 | |
| 4207 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
| 4208 | assert(Context && "No context available?"); |
| 4209 | return Context->getTranslationUnitDecl(); |
Douglas Gregor | 3ea7269 | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 4210 | |
| 4211 | case PREDEF_DECL_OBJC_ID_ID: |
| 4212 | assert(Context && "No context available?"); |
| 4213 | return Context->getObjCIdDecl(); |
Douglas Gregor | 0a58618 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4214 | |
Douglas Gregor | 52e0280 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4215 | case PREDEF_DECL_OBJC_SEL_ID: |
| 4216 | assert(Context && "No context available?"); |
| 4217 | return Context->getObjCSelDecl(); |
| 4218 | |
Douglas Gregor | 0a58618 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4219 | case PREDEF_DECL_OBJC_CLASS_ID: |
| 4220 | assert(Context && "No context available?"); |
| 4221 | return Context->getObjCClassDecl(); |
Douglas Gregor | 801c99d | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4222 | |
| 4223 | case PREDEF_DECL_INT_128_ID: |
| 4224 | assert(Context && "No context available?"); |
| 4225 | return Context->getInt128Decl(); |
| 4226 | |
| 4227 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
| 4228 | assert(Context && "No context available?"); |
| 4229 | return Context->getUInt128Decl(); |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4230 | } |
| 4231 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4232 | return 0; |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4233 | } |
| 4234 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4235 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4236 | |
| 4237 | if (Index > DeclsLoaded.size()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4238 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4239 | return 0; |
| 4240 | } |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4241 | |
| 4242 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4243 | ReadDeclRecord(ID); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4244 | if (DeserializationListener) |
| 4245 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 4246 | } |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4247 | |
| 4248 | return DeclsLoaded[Index]; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4249 | } |
| 4250 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4251 | serialization::DeclID ASTReader::ReadDeclID(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4252 | const RecordData &Record, |
| 4253 | unsigned &Idx) { |
| 4254 | if (Idx >= Record.size()) { |
| 4255 | Error("Corrupted AST file"); |
| 4256 | return 0; |
| 4257 | } |
| 4258 | |
| 4259 | return getGlobalDeclID(F, Record[Idx++]); |
| 4260 | } |
| 4261 | |
Chris Lattner | 9c28af0 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 4262 | /// \brief Resolve the offset of a statement into a statement. |
| 4263 | /// |
| 4264 | /// This operation will read a new statement from the external |
| 4265 | /// source each time it is called, and is meant to be used via a |
| 4266 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4267 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | d9f526f | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4268 | // Switch case IDs are per Decl. |
| 4269 | ClearSwitchCaseIDs(); |
| 4270 | |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4271 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4272 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4273 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 4274 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 3c3aa61 | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 4275 | } |
| 4276 | |
Douglas Gregor | 3d0adb3 | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4277 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4278 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4279 | SmallVectorImpl<Decl*> &Decls) { |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4280 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 4281 | // at least. |
Sebastian Redl | da6a21c | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 4282 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 4283 | // so make a copy of the vector. |
| 4284 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4285 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 4286 | I != E; ++I) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4287 | // IDs can be 0 if this context doesn't contain declarations. |
| 4288 | if (!I->LexicalDecls) |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4289 | continue; |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4290 | |
| 4291 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4292 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 4293 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 4294 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 4295 | continue; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4296 | |
Douglas Gregor | f224ae0 | 2011-07-21 23:29:11 +0000 | [diff] [blame] | 4297 | Decl *D = GetLocalDecl(*I->F, ID->second); |
Sebastian Redl | da6a21c | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 4298 | assert(D && "Null decl in lexical decls"); |
| 4299 | Decls.push_back(D); |
| 4300 | } |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4301 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4302 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4303 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 3d0adb3 | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4304 | return ELR_Success; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4305 | } |
| 4306 | |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4307 | DeclContext::lookup_result |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4308 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4309 | DeclarationName Name) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4310 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4311 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4312 | if (!Name) |
| 4313 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 4314 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4315 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4316 | SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 471ac2f | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 4317 | // There might be visible decls in multiple parts of the chain, for the TU |
Sebastian Redl | 9617e7e | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 4318 | // and namespaces. For any given name, the last available results replace |
| 4319 | // all earlier ones. For this reason, we walk in reverse. |
Argyrios Kyrtzidis | 1d233f9 | 2011-08-11 23:26:42 +0000 | [diff] [blame] | 4320 | // Copy the DeclContextInfos vector instead of using a reference to the |
| 4321 | // vector stored in the map, because DeclContextOffsets can change while |
| 4322 | // we load declarations with GetLocalDeclAs. |
| 4323 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 9617e7e | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 4324 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4325 | I != E; ++I) { |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4326 | if (!I->NameLookupTableData) |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4327 | continue; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4328 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4329 | ASTDeclContextNameLookupTable *LookupTable = |
| 4330 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 4331 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 4332 | if (Pos == LookupTable->end()) |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4333 | continue; |
| 4334 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4335 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 4336 | for (; Data.first != Data.second; ++Data.first) { |
| 4337 | NamedDecl *ND = GetLocalDeclAs<NamedDecl>(*I->F, *Data.first); |
| 4338 | if (!ND) |
| 4339 | continue; |
| 4340 | |
| 4341 | if (ND->getDeclName() != Name) { |
| 4342 | assert(!Name.getCXXNameType().isNull() && |
| 4343 | "Name mismatch without a type"); |
| 4344 | continue; |
| 4345 | } |
| 4346 | |
| 4347 | Decls.push_back(ND); |
| 4348 | } |
| 4349 | |
| 4350 | // If we rejected all of the declarations we found, e.g., because the |
| 4351 | // name didn't actually match, continue looking through DeclContexts. |
| 4352 | if (Decls.empty()) |
| 4353 | continue; |
| 4354 | |
Sebastian Redl | 9617e7e | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 4355 | break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4356 | } |
| 4357 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4358 | ++NumVisibleDeclContextsRead; |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4359 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4360 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4361 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4362 | } |
| 4363 | |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 4364 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 4365 | assert(DC->hasExternalVisibleStorage() && |
| 4366 | "DeclContext has no visible decls in storage"); |
| 4367 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4368 | SmallVector<NamedDecl *, 64> Decls; |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 4369 | // There might be visible decls in multiple parts of the chain, for the TU |
| 4370 | // and namespaces. |
| 4371 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 4372 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 4373 | I != E; ++I) { |
| 4374 | if (!I->NameLookupTableData) |
| 4375 | continue; |
| 4376 | |
| 4377 | ASTDeclContextNameLookupTable *LookupTable = |
| 4378 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 4379 | for (ASTDeclContextNameLookupTable::item_iterator |
| 4380 | ItemI = LookupTable->item_begin(), |
| 4381 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 4382 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 4383 | = *ItemI; |
| 4384 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 4385 | Decls.clear(); |
| 4386 | for (; Data.first != Data.second; ++Data.first) |
Douglas Gregor | f224ae0 | 2011-07-21 23:29:11 +0000 | [diff] [blame] | 4387 | Decls.push_back(GetLocalDeclAs<NamedDecl>(*I->F, *Data.first)); |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 4388 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 4389 | } |
| 4390 | } |
| 4391 | } |
| 4392 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4393 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4394 | assert(Consumer); |
| 4395 | while (!InterestingDecls.empty()) { |
| 4396 | DeclGroupRef DG(InterestingDecls.front()); |
| 4397 | InterestingDecls.pop_front(); |
Sebastian Redl | eaa4ade | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 4398 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4399 | } |
| 4400 | } |
| 4401 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4402 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | b985eeb | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 4403 | this->Consumer = Consumer; |
| 4404 | |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4405 | if (!Consumer) |
| 4406 | return; |
| 4407 | |
| 4408 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4409 | // Force deserialization of this decl, which will cause it to be queued for |
| 4410 | // passing to the consumer. |
Daniel Dunbar | 865c2a7 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 4411 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4412 | } |
Douglas Gregor | f005eac | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 4413 | |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4414 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4415 | } |
| 4416 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4417 | void ASTReader::PrintStats() { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4418 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4419 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4420 | unsigned NumTypesLoaded |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4421 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4422 | QualType()); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4423 | unsigned NumDeclsLoaded |
| 4424 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 4425 | (Decl *)0); |
| 4426 | unsigned NumIdentifiersLoaded |
| 4427 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 4428 | IdentifiersLoaded.end(), |
| 4429 | (IdentifierInfo *)0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4430 | unsigned NumSelectorsLoaded |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4431 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 4432 | SelectorsLoaded.end(), |
| 4433 | Selector()); |
Douglas Gregor | c3b1dd1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 4434 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4435 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 4436 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 4437 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4438 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 4439 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 4440 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4441 | if (!TypesLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4442 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4443 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 4444 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 4445 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4446 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4447 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 4448 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4449 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4450 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4451 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4452 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4453 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4454 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4455 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4456 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4457 | if (TotalNumStatements) |
| 4458 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4459 | NumStatementsRead, TotalNumStatements, |
| 4460 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4461 | if (TotalNumMacros) |
| 4462 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4463 | NumMacrosRead, TotalNumMacros, |
| 4464 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4465 | if (TotalLexicalDeclContexts) |
| 4466 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4467 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4468 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4469 | * 100)); |
| 4470 | if (TotalVisibleDeclContexts) |
| 4471 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4472 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4473 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4474 | * 100)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4475 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4476 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4477 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4478 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4479 | * 100)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4480 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4481 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4482 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4483 | dump(); |
| 4484 | std::fprintf(stderr, "\n"); |
| 4485 | } |
| 4486 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4487 | template<typename Key, typename Module, unsigned InitialCapacity> |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4488 | static void |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4489 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4490 | const ContinuousRangeMap<Key, Module *, |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4491 | InitialCapacity> &Map) { |
| 4492 | if (Map.begin() == Map.end()) |
| 4493 | return; |
| 4494 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4495 | typedef ContinuousRangeMap<Key, Module *, InitialCapacity> MapType; |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4496 | llvm::errs() << Name << ":\n"; |
| 4497 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 4498 | I != IEnd; ++I) { |
| 4499 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 4500 | << "\n"; |
| 4501 | } |
| 4502 | } |
| 4503 | |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4504 | void ASTReader::dump() { |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4505 | llvm::errs() << "*** PCH/Module Remappings:\n"; |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4506 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4507 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 4508 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4509 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4510 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 4511 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
| 4512 | dumpModuleIDMap("Global macro definition map", GlobalMacroDefinitionMap); |
| 4513 | dumpModuleIDMap("Global preprocessed entity map", |
| 4514 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4515 | |
| 4516 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 4517 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 4518 | MEnd = ModuleMgr.end(); |
| 4519 | M != MEnd; ++M) |
| 4520 | (*M)->dump(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4521 | } |
| 4522 | |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4523 | /// Return the amount of memory used by memory buffers, breaking down |
| 4524 | /// by heap-backed versus mmap'ed memory. |
| 4525 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4526 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 4527 | E = ModuleMgr.end(); I != E; ++I) { |
| 4528 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4529 | size_t bytes = buf->getBufferSize(); |
| 4530 | switch (buf->getBufferKind()) { |
| 4531 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 4532 | sizes.malloc_bytes += bytes; |
| 4533 | break; |
| 4534 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 4535 | sizes.mmap_bytes += bytes; |
| 4536 | break; |
| 4537 | } |
| 4538 | } |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4539 | } |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4540 | } |
| 4541 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4542 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4543 | SemaObj = &S; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4544 | S.ExternalSource = this; |
| 4545 | |
Douglas Gregor | 7cd60f7 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4546 | // Makes sure any declarations that were deserialized "too early" |
| 4547 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4548 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4549 | if (SemaObj->TUScope) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4550 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4551 | |
| 4552 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4553 | } |
Douglas Gregor | 7cd60f7 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4554 | PreloadedDecls.clear(); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4555 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4556 | // Load the offsets of the declarations that Sema references. |
| 4557 | // They will be lazily deserialized when needed. |
| 4558 | if (!SemaDeclRefs.empty()) { |
| 4559 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | b0f3ae6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 4560 | if (!SemaObj->StdNamespace) |
| 4561 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4562 | if (!SemaObj->StdBadAlloc) |
| 4563 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4564 | } |
| 4565 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4566 | if (!FPPragmaOptions.empty()) { |
| 4567 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4568 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4569 | } |
| 4570 | |
| 4571 | if (!OpenCLExtensions.empty()) { |
| 4572 | unsigned I = 0; |
| 4573 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4574 | #include "clang/Basic/OpenCLExtensions.def" |
| 4575 | |
| 4576 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4577 | } |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4578 | } |
| 4579 | |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4580 | namespace { |
| 4581 | /// \brief Visitor class used to look up identifirs in |
| 4582 | class IdentifierLookupVisitor { |
| 4583 | StringRef Name; |
| 4584 | IdentifierInfo *Found; |
| 4585 | public: |
| 4586 | explicit IdentifierLookupVisitor(StringRef Name) : Name(Name), Found() { } |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4587 | |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4588 | static bool visit(Module &M, void *UserData) { |
| 4589 | IdentifierLookupVisitor *This |
| 4590 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 4591 | |
| 4592 | ASTIdentifierLookupTable *IdTable |
| 4593 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 4594 | if (!IdTable) |
| 4595 | return false; |
| 4596 | |
| 4597 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 4598 | This->Name.size()); |
| 4599 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
| 4600 | if (Pos == IdTable->end()) |
| 4601 | return false; |
| 4602 | |
| 4603 | // Dereferencing the iterator has the effect of building the |
| 4604 | // IdentifierInfo node and populating it with the various |
| 4605 | // declarations it needs. |
| 4606 | This->Found = *Pos; |
| 4607 | return true; |
| 4608 | } |
| 4609 | |
| 4610 | // \brief Retrieve the identifier info found within the module |
| 4611 | // files. |
| 4612 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 4613 | }; |
| 4614 | } |
| 4615 | |
| 4616 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4617 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart)); |
| 4618 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
| 4619 | return Visitor.getIdentifierInfo(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4620 | } |
| 4621 | |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4622 | namespace clang { |
| 4623 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4624 | /// identifiers stored within a set of AST files. |
| 4625 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4626 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4627 | const ASTReader &Reader; |
| 4628 | |
| 4629 | /// \brief The current index into the chain of AST files stored in |
| 4630 | /// the AST reader. |
| 4631 | unsigned Index; |
| 4632 | |
| 4633 | /// \brief The current position within the identifier lookup table |
| 4634 | /// of the current AST file. |
| 4635 | ASTIdentifierLookupTable::key_iterator Current; |
| 4636 | |
| 4637 | /// \brief The end position within the identifier lookup table of |
| 4638 | /// the current AST file. |
| 4639 | ASTIdentifierLookupTable::key_iterator End; |
| 4640 | |
| 4641 | public: |
| 4642 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4643 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4644 | virtual StringRef Next(); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4645 | }; |
| 4646 | } |
| 4647 | |
| 4648 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4649 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4650 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4651 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4652 | Current = IdTable->key_begin(); |
| 4653 | End = IdTable->key_end(); |
| 4654 | } |
| 4655 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4656 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4657 | while (Current == End) { |
| 4658 | // If we have exhausted all of our AST files, we're done. |
| 4659 | if (Index == 0) |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4660 | return StringRef(); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4661 | |
| 4662 | --Index; |
| 4663 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4664 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 4665 | IdentifierLookupTable; |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4666 | Current = IdTable->key_begin(); |
| 4667 | End = IdTable->key_end(); |
| 4668 | } |
| 4669 | |
| 4670 | // We have any identifiers remaining in the current AST file; return |
| 4671 | // the next one. |
| 4672 | std::pair<const char*, unsigned> Key = *Current; |
| 4673 | ++Current; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4674 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4675 | } |
| 4676 | |
| 4677 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4678 | return new ASTIdentifierIterator(*this); |
| 4679 | } |
| 4680 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4681 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4682 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4683 | // Find this selector in a hash table. We want to find the most recent entry. |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4684 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
| 4685 | Module &F = *(*I); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4686 | if (!F.SelectorLookupTable) |
| 4687 | continue; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4688 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4689 | ASTSelectorLookupTable *PoolTable |
| 4690 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 4691 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4692 | if (Pos != PoolTable->end()) { |
| 4693 | ++NumSelectorsRead; |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4694 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4695 | // disable this tracking when called via LoadSelector. |
| 4696 | // Also, should entries without methods count as misses? |
| 4697 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4698 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4699 | if (DeserializationListener) |
| 4700 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 4701 | return std::make_pair(Data.Instance, Data.Factory); |
| 4702 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4703 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4704 | |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4705 | ++NumMethodPoolMisses; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4706 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4707 | } |
| 4708 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4709 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4710 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4711 | Namespaces.clear(); |
| 4712 | |
| 4713 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 4714 | if (NamespaceDecl *Namespace |
| 4715 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 4716 | Namespaces.push_back(Namespace); |
| 4717 | } |
| 4718 | } |
| 4719 | |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4720 | void ASTReader::ReadTentativeDefinitions( |
| 4721 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 4722 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4723 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 4724 | if (Var) |
| 4725 | TentativeDefs.push_back(Var); |
| 4726 | } |
| 4727 | TentativeDefinitions.clear(); |
| 4728 | } |
| 4729 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4730 | void ASTReader::ReadUnusedFileScopedDecls( |
| 4731 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 4732 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4733 | DeclaratorDecl *D |
| 4734 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4735 | if (D) |
| 4736 | Decls.push_back(D); |
| 4737 | } |
| 4738 | UnusedFileScopedDecls.clear(); |
| 4739 | } |
| 4740 | |
Douglas Gregor | bae3120 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 4741 | void ASTReader::ReadDelegatingConstructors( |
| 4742 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 4743 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 4744 | CXXConstructorDecl *D |
| 4745 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 4746 | if (D) |
| 4747 | Decls.push_back(D); |
| 4748 | } |
| 4749 | DelegatingCtorDecls.clear(); |
| 4750 | } |
| 4751 | |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4752 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 4753 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 4754 | TypedefNameDecl *D |
| 4755 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 4756 | if (D) |
| 4757 | Decls.push_back(D); |
| 4758 | } |
| 4759 | ExtVectorDecls.clear(); |
| 4760 | } |
| 4761 | |
Douglas Gregor | 3200219 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 4762 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 4763 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 4764 | CXXRecordDecl *D |
| 4765 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 4766 | if (D) |
| 4767 | Decls.push_back(D); |
| 4768 | } |
| 4769 | DynamicClasses.clear(); |
| 4770 | } |
| 4771 | |
Douglas Gregor | dc5c958 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 4772 | void |
| 4773 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 4774 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4775 | NamedDecl *D |
| 4776 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4777 | if (D) |
| 4778 | Decls.push_back(D); |
| 4779 | } |
| 4780 | LocallyScopedExternalDecls.clear(); |
| 4781 | } |
| 4782 | |
Douglas Gregor | 72e357f | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 4783 | void ASTReader::ReadReferencedSelectors( |
| 4784 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 4785 | if (ReferencedSelectorsData.empty()) |
| 4786 | return; |
| 4787 | |
| 4788 | // If there are @selector references added them to its pool. This is for |
| 4789 | // implementation of -Wselector. |
| 4790 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 4791 | unsigned I = 0; |
| 4792 | while (I < DataSize) { |
| 4793 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 4794 | SourceLocation SelLoc |
| 4795 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 4796 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 4797 | } |
| 4798 | ReferencedSelectorsData.clear(); |
| 4799 | } |
| 4800 | |
Douglas Gregor | 1c4bfe5 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 4801 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 4802 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 4803 | if (WeakUndeclaredIdentifiers.empty()) |
| 4804 | return; |
| 4805 | |
| 4806 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 4807 | IdentifierInfo *WeakId |
| 4808 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4809 | IdentifierInfo *AliasId |
| 4810 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4811 | SourceLocation Loc |
| 4812 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 4813 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 4814 | WeakInfo WI(AliasId, Loc); |
| 4815 | WI.setUsed(Used); |
| 4816 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 4817 | } |
| 4818 | WeakUndeclaredIdentifiers.clear(); |
| 4819 | } |
| 4820 | |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 4821 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 4822 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 4823 | ExternalVTableUse VT; |
| 4824 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4825 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 4826 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 4827 | VTables.push_back(VT); |
| 4828 | } |
| 4829 | |
| 4830 | VTableUses.clear(); |
| 4831 | } |
| 4832 | |
Douglas Gregor | e39f97c | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 4833 | void ASTReader::ReadPendingInstantiations( |
| 4834 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 4835 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 4836 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 4837 | SourceLocation Loc |
| 4838 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 4839 | Pending.push_back(std::make_pair(D, Loc)); |
| 4840 | } |
| 4841 | PendingInstantiations.clear(); |
| 4842 | } |
| 4843 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4844 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4845 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4846 | ReadMethodPool(Sel); |
| 4847 | } |
| 4848 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4849 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4850 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | 6f00bf8 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4851 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4852 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4853 | if (DeserializationListener) |
| 4854 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4855 | } |
| 4856 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4857 | /// \brief Set the globally-visible declarations associated with the given |
| 4858 | /// identifier. |
| 4859 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4860 | /// If the AST reader is currently in a state where the given declaration IDs |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4861 | /// cannot safely be resolved, they are queued until it is safe to resolve |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4862 | /// them. |
| 4863 | /// |
| 4864 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4865 | /// declarations. |
| 4866 | /// |
| 4867 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4868 | /// visible at global scope. |
| 4869 | /// |
| 4870 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4871 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4872 | /// will not be placed onto the pending queue. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4873 | void |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4874 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4875 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4876 | bool Nonrecursive) { |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4877 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4878 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4879 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4880 | PII.II = II; |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4881 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4882 | return; |
| 4883 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4884 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4885 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4886 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4887 | if (SemaObj) { |
Douglas Gregor | 6fd55e0 | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4888 | if (SemaObj->TUScope) { |
| 4889 | // Introduce this declaration into the translation-unit scope |
| 4890 | // and add it to the declaration chain for this identifier, so |
| 4891 | // that (unqualified) name lookup will find it. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4892 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 6fd55e0 | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4893 | } |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4894 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4895 | } else { |
| 4896 | // Queue this declaration so that it will be added to the |
| 4897 | // translation unit scope and identifier's declaration chain |
| 4898 | // once a Sema object is known. |
| 4899 | PreloadedDecls.push_back(D); |
| 4900 | } |
| 4901 | } |
| 4902 | } |
| 4903 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4904 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4905 | if (ID == 0) |
| 4906 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4907 | |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4908 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4909 | Error("no identifier table in AST file"); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4910 | return 0; |
| 4911 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4912 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4913 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4914 | ID -= 1; |
| 4915 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 19d2635 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 4916 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 4917 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4918 | Module *M = I->second; |
| 4919 | unsigned Index = ID - M->BaseIdentifierID; |
| 4920 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | 5287b4e | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4921 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4922 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4923 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | ca42a51 | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4924 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4925 | // unsigned integers. This is important to avoid integer overflow when |
| 4926 | // we cast them to 'unsigned'. |
Ted Kremenek | 49c5232 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4927 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4928 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4929 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4930 | IdentifiersLoaded[ID] |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4931 | = &PP->getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4932 | if (DeserializationListener) |
| 4933 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4934 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4935 | |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4936 | return IdentifiersLoaded[ID]; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4937 | } |
| 4938 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4939 | IdentifierInfo *ASTReader::getLocalIdentifier(Module &M, unsigned LocalID) { |
| 4940 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 4941 | } |
| 4942 | |
| 4943 | IdentifierID ASTReader::getGlobalIdentifierID(Module &M, unsigned LocalID) { |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 4944 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 4945 | return LocalID; |
| 4946 | |
| 4947 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4948 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 4949 | assert(I != M.IdentifierRemap.end() |
| 4950 | && "Invalid index into identifier index remap"); |
| 4951 | |
| 4952 | return LocalID + I->second; |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4953 | } |
| 4954 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4955 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | 49f754f | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 4956 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4957 | } |
| 4958 | |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 4959 | Selector ASTReader::getLocalSelector(Module &M, unsigned LocalID) { |
| 4960 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 4961 | } |
| 4962 | |
| 4963 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4964 | if (ID == 0) |
| 4965 | return Selector(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4966 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4967 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4968 | Error("selector ID out of range in AST file"); |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4969 | return Selector(); |
| 4970 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4971 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4972 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4973 | // Load this selector from the selector table. |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4974 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 4975 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4976 | Module &M = *I->second; |
| 4977 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 4978 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4979 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4980 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4981 | if (DeserializationListener) |
| 4982 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4983 | } |
| 4984 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4985 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4986 | } |
| 4987 | |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 4988 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | d720daf | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4989 | return DecodeSelector(ID); |
| 4990 | } |
| 4991 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4992 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4993 | // ID 0 (the null selector) is considered an external selector. |
| 4994 | return getTotalNumSelectors() + 1; |
Douglas Gregor | d720daf | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4995 | } |
| 4996 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 4997 | serialization::SelectorID |
| 4998 | ASTReader::getGlobalSelectorID(Module &M, unsigned LocalID) const { |
| 4999 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 5000 | return LocalID; |
| 5001 | |
| 5002 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5003 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 5004 | assert(I != M.SelectorRemap.end() |
| 5005 | && "Invalid index into identifier index remap"); |
| 5006 | |
| 5007 | return LocalID + I->second; |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 5008 | } |
| 5009 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5010 | DeclarationName |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5011 | ASTReader::ReadDeclarationName(Module &F, |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5012 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5013 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 5014 | switch (Kind) { |
| 5015 | case DeclarationName::Identifier: |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5016 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5017 | |
| 5018 | case DeclarationName::ObjCZeroArgSelector: |
| 5019 | case DeclarationName::ObjCOneArgSelector: |
| 5020 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 5021 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5022 | |
| 5023 | case DeclarationName::CXXConstructorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 5024 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5025 | Context->getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5026 | |
| 5027 | case DeclarationName::CXXDestructorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 5028 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5029 | Context->getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5030 | |
| 5031 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 5032 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5033 | Context->getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5034 | |
| 5035 | case DeclarationName::CXXOperatorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 5036 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5037 | (OverloadedOperatorKind)Record[Idx++]); |
| 5038 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5039 | case DeclarationName::CXXLiteralOperatorName: |
| 5040 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5041 | GetIdentifierInfo(F, Record, Idx)); |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5042 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5043 | case DeclarationName::CXXUsingDirective: |
| 5044 | return DeclarationName::getUsingDirectiveName(); |
| 5045 | } |
| 5046 | |
| 5047 | // Required to silence GCC warning |
| 5048 | return DeclarationName(); |
| 5049 | } |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5050 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5051 | void ASTReader::ReadDeclarationNameLoc(Module &F, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5052 | DeclarationNameLoc &DNLoc, |
| 5053 | DeclarationName Name, |
| 5054 | const RecordData &Record, unsigned &Idx) { |
| 5055 | switch (Name.getNameKind()) { |
| 5056 | case DeclarationName::CXXConstructorName: |
| 5057 | case DeclarationName::CXXDestructorName: |
| 5058 | case DeclarationName::CXXConversionFunctionName: |
| 5059 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5060 | break; |
| 5061 | |
| 5062 | case DeclarationName::CXXOperatorName: |
| 5063 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 5064 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5065 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 5066 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5067 | break; |
| 5068 | |
| 5069 | case DeclarationName::CXXLiteralOperatorName: |
| 5070 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 5071 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5072 | break; |
| 5073 | |
| 5074 | case DeclarationName::Identifier: |
| 5075 | case DeclarationName::ObjCZeroArgSelector: |
| 5076 | case DeclarationName::ObjCOneArgSelector: |
| 5077 | case DeclarationName::ObjCMultiArgSelector: |
| 5078 | case DeclarationName::CXXUsingDirective: |
| 5079 | break; |
| 5080 | } |
| 5081 | } |
| 5082 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5083 | void ASTReader::ReadDeclarationNameInfo(Module &F, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5084 | DeclarationNameInfo &NameInfo, |
| 5085 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5086 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5087 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 5088 | DeclarationNameLoc DNLoc; |
| 5089 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 5090 | NameInfo.setInfo(DNLoc); |
| 5091 | } |
| 5092 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5093 | void ASTReader::ReadQualifierInfo(Module &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5094 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5095 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5096 | unsigned NumTPLists = Record[Idx++]; |
| 5097 | Info.NumTemplParamLists = NumTPLists; |
| 5098 | if (NumTPLists) { |
| 5099 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 5100 | for (unsigned i=0; i != NumTPLists; ++i) |
| 5101 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 5102 | } |
| 5103 | } |
| 5104 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5105 | TemplateName |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5106 | ASTReader::ReadTemplateName(Module &F, const RecordData &Record, |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5107 | unsigned &Idx) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5108 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5109 | switch (Kind) { |
| 5110 | case TemplateName::Template: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5111 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5112 | |
| 5113 | case TemplateName::OverloadedTemplate: { |
| 5114 | unsigned size = Record[Idx++]; |
| 5115 | UnresolvedSet<8> Decls; |
| 5116 | while (size--) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5117 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5118 | |
| 5119 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 5120 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5121 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5122 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5123 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5124 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5125 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5126 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 5127 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5128 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5129 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5130 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5131 | if (Record[Idx++]) // isIdentifier |
| 5132 | return Context->getDependentTemplateName(NNS, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5133 | GetIdentifierInfo(F, Record, |
| 5134 | Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5135 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5136 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5137 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5138 | |
| 5139 | case TemplateName::SubstTemplateTemplateParm: { |
| 5140 | TemplateTemplateParmDecl *param |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5141 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5142 | if (!param) return TemplateName(); |
| 5143 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
| 5144 | return Context->getSubstTemplateTemplateParm(param, replacement); |
| 5145 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5146 | |
| 5147 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5148 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5149 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5150 | if (!Param) |
| 5151 | return TemplateName(); |
| 5152 | |
| 5153 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 5154 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 5155 | return TemplateName(); |
| 5156 | |
| 5157 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 5158 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5159 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5160 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5161 | assert(0 && "Unhandled template name kind!"); |
| 5162 | return TemplateName(); |
| 5163 | } |
| 5164 | |
| 5165 | TemplateArgument |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5166 | ASTReader::ReadTemplateArgument(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 5167 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5168 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 5169 | switch (Kind) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5170 | case TemplateArgument::Null: |
| 5171 | return TemplateArgument(); |
| 5172 | case TemplateArgument::Type: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5173 | return TemplateArgument(readType(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5174 | case TemplateArgument::Declaration: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5175 | return TemplateArgument(ReadDecl(F, Record, Idx)); |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5176 | case TemplateArgument::Integral: { |
| 5177 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5178 | QualType T = readType(F, Record, Idx); |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5179 | return TemplateArgument(Value, T); |
| 5180 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5181 | case TemplateArgument::Template: |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5182 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5183 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5184 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5185 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 5186 | if (unsigned NumExpansions = Record[Idx++]) |
| 5187 | NumTemplateExpansions = NumExpansions - 1; |
| 5188 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 5189 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5190 | case TemplateArgument::Expression: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5191 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5192 | case TemplateArgument::Pack: { |
| 5193 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5194 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 5195 | for (unsigned I = 0; I != NumArgs; ++I) |
| 5196 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 5197 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5198 | } |
| 5199 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5200 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5201 | assert(0 && "Unhandled template argument kind!"); |
| 5202 | return TemplateArgument(); |
| 5203 | } |
| 5204 | |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5205 | TemplateParameterList * |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5206 | ASTReader::ReadTemplateParameterList(Module &F, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5207 | const RecordData &Record, unsigned &Idx) { |
| 5208 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 5209 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 5210 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5211 | |
| 5212 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5213 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5214 | Params.reserve(NumParams); |
| 5215 | while (NumParams--) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5216 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5217 | |
| 5218 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5219 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 5220 | Params.data(), Params.size(), RAngleLoc); |
| 5221 | return TemplateParams; |
| 5222 | } |
| 5223 | |
| 5224 | void |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5225 | ASTReader:: |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5226 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5227 | Module &F, const RecordData &Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5228 | unsigned &Idx) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5229 | unsigned NumTemplateArgs = Record[Idx++]; |
| 5230 | TemplArgs.reserve(NumTemplateArgs); |
| 5231 | while (NumTemplateArgs--) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5232 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5233 | } |
| 5234 | |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5235 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5236 | void ASTReader::ReadUnresolvedSet(Module &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5237 | const RecordData &Record, unsigned &Idx) { |
| 5238 | unsigned NumDecls = Record[Idx++]; |
| 5239 | while (NumDecls--) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5240 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5241 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 5242 | Set.addDecl(D, AS); |
| 5243 | } |
| 5244 | } |
| 5245 | |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5246 | CXXBaseSpecifier |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5247 | ASTReader::ReadCXXBaseSpecifier(Module &F, |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5248 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5249 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 5250 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 5251 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5252 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5253 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5254 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5255 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5256 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5257 | EllipsisLoc); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5258 | Result.setInheritConstructors(inheritConstructors); |
| 5259 | return Result; |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5260 | } |
| 5261 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5262 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5263 | ASTReader::ReadCXXCtorInitializers(Module &F, const RecordData &Record, |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5264 | unsigned &Idx) { |
| 5265 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5266 | unsigned NumInitializers = Record[Idx++]; |
| 5267 | if (NumInitializers) { |
| 5268 | ASTContext &C = *getContext(); |
| 5269 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5270 | CtorInitializers |
| 5271 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5272 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 5273 | TypeSourceInfo *BaseClassInfo = 0; |
| 5274 | bool IsBaseVirtual = false; |
| 5275 | FieldDecl *Member = 0; |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5276 | IndirectFieldDecl *IndirectMember = 0; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5277 | CXXConstructorDecl *Target = 0; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5278 | |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5279 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 5280 | switch (Type) { |
| 5281 | case CTOR_INITIALIZER_BASE: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5282 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5283 | IsBaseVirtual = Record[Idx++]; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5284 | break; |
| 5285 | |
| 5286 | case CTOR_INITIALIZER_DELEGATING: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5287 | Target = ReadDeclAs<CXXConstructorDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5288 | break; |
| 5289 | |
| 5290 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5291 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5292 | break; |
| 5293 | |
| 5294 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5295 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5296 | break; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5297 | } |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5298 | |
Douglas Gregor | 44e7df6 | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 5299 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5300 | Expr *Init = ReadExpr(F); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5301 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 5302 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5303 | bool IsWritten = Record[Idx++]; |
| 5304 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5305 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5306 | if (IsWritten) { |
| 5307 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5308 | } else { |
| 5309 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5310 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 5311 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5312 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5313 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5314 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5315 | CXXCtorInitializer *BOMInit; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5316 | if (Type == CTOR_INITIALIZER_BASE) { |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5317 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 5318 | LParenLoc, Init, RParenLoc, |
| 5319 | MemberOrEllipsisLoc); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5320 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
| 5321 | BOMInit = new (C) CXXCtorInitializer(C, MemberOrEllipsisLoc, LParenLoc, |
| 5322 | Target, Init, RParenLoc); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5323 | } else if (IsWritten) { |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5324 | if (Member) |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5325 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 5326 | LParenLoc, Init, RParenLoc); |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5327 | else |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5328 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 5329 | MemberOrEllipsisLoc, LParenLoc, |
| 5330 | Init, RParenLoc); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5331 | } else { |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5332 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 5333 | LParenLoc, Init, RParenLoc, |
| 5334 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5335 | } |
| 5336 | |
Argyrios Kyrtzidis | d05f3e3 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 5337 | if (IsWritten) |
| 5338 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5339 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5340 | } |
| 5341 | } |
| 5342 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5343 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5344 | } |
| 5345 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5346 | NestedNameSpecifier * |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5347 | ASTReader::ReadNestedNameSpecifier(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5348 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5349 | unsigned N = Record[Idx++]; |
| 5350 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 5351 | for (unsigned I = 0; I != N; ++I) { |
| 5352 | NestedNameSpecifier::SpecifierKind Kind |
| 5353 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5354 | switch (Kind) { |
| 5355 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5356 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5357 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 5358 | break; |
| 5359 | } |
| 5360 | |
| 5361 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5362 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5363 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 5364 | break; |
| 5365 | } |
| 5366 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5367 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5368 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5369 | NNS = NestedNameSpecifier::Create(*Context, Prev, Alias); |
| 5370 | break; |
| 5371 | } |
| 5372 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5373 | case NestedNameSpecifier::TypeSpec: |
| 5374 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5375 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 0cdc832 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 5376 | if (!T) |
| 5377 | return 0; |
| 5378 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5379 | bool Template = Record[Idx++]; |
| 5380 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 5381 | break; |
| 5382 | } |
| 5383 | |
| 5384 | case NestedNameSpecifier::Global: { |
| 5385 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 5386 | // No associated value, and there can't be a prefix. |
| 5387 | break; |
| 5388 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5389 | } |
Argyrios Kyrtzidis | ad65c69 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 5390 | Prev = NNS; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5391 | } |
| 5392 | return NNS; |
| 5393 | } |
| 5394 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5395 | NestedNameSpecifierLoc |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5396 | ASTReader::ReadNestedNameSpecifierLoc(Module &F, const RecordData &Record, |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5397 | unsigned &Idx) { |
| 5398 | unsigned N = Record[Idx++]; |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5399 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5400 | for (unsigned I = 0; I != N; ++I) { |
| 5401 | NestedNameSpecifier::SpecifierKind Kind |
| 5402 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5403 | switch (Kind) { |
| 5404 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5405 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5406 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5407 | Builder.Extend(*Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5408 | break; |
| 5409 | } |
| 5410 | |
| 5411 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5412 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5413 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5414 | Builder.Extend(*Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5415 | break; |
| 5416 | } |
| 5417 | |
| 5418 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5419 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5420 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5421 | Builder.Extend(*Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5422 | break; |
| 5423 | } |
| 5424 | |
| 5425 | case NestedNameSpecifier::TypeSpec: |
| 5426 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5427 | bool Template = Record[Idx++]; |
| 5428 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 5429 | if (!T) |
| 5430 | return NestedNameSpecifierLoc(); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5431 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5432 | |
| 5433 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
| 5434 | Builder.Extend(*Context, |
| 5435 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 5436 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5437 | break; |
| 5438 | } |
| 5439 | |
| 5440 | case NestedNameSpecifier::Global: { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5441 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5442 | Builder.MakeGlobal(*Context, ColonColonLoc); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5443 | break; |
| 5444 | } |
| 5445 | } |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5446 | } |
| 5447 | |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5448 | return Builder.getWithLocInContext(*Context); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5449 | } |
| 5450 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5451 | SourceRange |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5452 | ASTReader::ReadSourceRange(Module &F, const RecordData &Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5453 | unsigned &Idx) { |
| 5454 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 5455 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 6d3bc08 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 5456 | return SourceRange(beg, end); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5457 | } |
| 5458 | |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5459 | /// \brief Read an integral value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5460 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5461 | unsigned BitWidth = Record[Idx++]; |
| 5462 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 5463 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 5464 | Idx += NumWords; |
| 5465 | return Result; |
| 5466 | } |
| 5467 | |
| 5468 | /// \brief Read a signed integral value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5469 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5470 | bool isUnsigned = Record[Idx++]; |
| 5471 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 5472 | } |
| 5473 | |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5474 | /// \brief Read a floating-point value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5475 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5476 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 5477 | } |
| 5478 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5479 | // \brief Read a string |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5480 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5481 | unsigned Len = Record[Idx++]; |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 5482 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5483 | Idx += Len; |
| 5484 | return Result; |
| 5485 | } |
| 5486 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 5487 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 5488 | unsigned &Idx) { |
| 5489 | unsigned Major = Record[Idx++]; |
| 5490 | unsigned Minor = Record[Idx++]; |
| 5491 | unsigned Subminor = Record[Idx++]; |
| 5492 | if (Minor == 0) |
| 5493 | return VersionTuple(Major); |
| 5494 | if (Subminor == 0) |
| 5495 | return VersionTuple(Major, Minor - 1); |
| 5496 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 5497 | } |
| 5498 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5499 | CXXTemporary *ASTReader::ReadCXXTemporary(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5500 | const RecordData &Record, |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5501 | unsigned &Idx) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5502 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5503 | return CXXTemporary::Create(*Context, Decl); |
| 5504 | } |
| 5505 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5506 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 5507 | return Diag(SourceLocation(), DiagID); |
| 5508 | } |
| 5509 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5510 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5511 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5512 | } |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5513 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5514 | /// \brief Retrieve the identifier table associated with the |
| 5515 | /// preprocessor. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5516 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 5517 | assert(PP && "Forgot to set Preprocessor ?"); |
| 5518 | return PP->getIdentifierTable(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5519 | } |
| 5520 | |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5521 | /// \brief Record that the given ID maps to the given switch-case |
| 5522 | /// statement. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5523 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5524 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 5525 | SwitchCaseStmts[ID] = SC; |
| 5526 | } |
| 5527 | |
| 5528 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5529 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5530 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 5531 | return SwitchCaseStmts[ID]; |
| 5532 | } |
Douglas Gregor | 6cc68a4 | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 5533 | |
Argyrios Kyrtzidis | d9f526f | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 5534 | void ASTReader::ClearSwitchCaseIDs() { |
| 5535 | SwitchCaseStmts.clear(); |
| 5536 | } |
| 5537 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5538 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5539 | assert(NumCurrentElementsDeserializing && |
| 5540 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 5541 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5542 | // If any identifiers with corresponding top-level declarations have |
| 5543 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5544 | while (!PendingIdentifierInfos.empty()) { |
| 5545 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 5546 | PendingIdentifierInfos.front().DeclIDs, true); |
| 5547 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5548 | } |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5549 | |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 5550 | // Ready to load previous declarations of Decls that were delayed. |
| 5551 | while (!PendingPreviousDecls.empty()) { |
| 5552 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 5553 | PendingPreviousDecls.front().second); |
| 5554 | PendingPreviousDecls.pop_front(); |
| 5555 | } |
| 5556 | |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5557 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 5558 | // decls to the consumer. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5559 | if (Consumer) |
| 5560 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | ad5f95c | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 5561 | |
| 5562 | assert(PendingForwardRefs.size() == 0 && |
| 5563 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5564 | } |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5565 | --NumCurrentElementsDeserializing; |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5566 | } |
Douglas Gregor | b473b07 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5567 | |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5568 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 5569 | StringRef isysroot, bool DisableValidation, |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5570 | bool DisableStatCache) |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5571 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 5572 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 5573 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
Jonathan D. Turner | ecc2740 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5574 | Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), |
| 5575 | RelocatablePCH(false), isysroot(isysroot), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5576 | DisableValidation(DisableValidation), |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5577 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5578 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5579 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 5580 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 5581 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 5582 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 3766fdb | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 5583 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 5584 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
| 5585 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5586 | { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5587 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5588 | } |
| 5589 | |
| 5590 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 5591 | Diagnostic &Diags, StringRef isysroot, |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5592 | bool DisableValidation, bool DisableStatCache) |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5593 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
Jonathan D. Turner | ecc2740 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5594 | Diags(Diags), SemaObj(0), PP(0), Context(0), |
| 5595 | Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5596 | RelocatablePCH(false), isysroot(isysroot), |
| 5597 | DisableValidation(DisableValidation), DisableStatCache(DisableStatCache), |
| 5598 | NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), |
| 5599 | TotalNumSLocEntries(0), NumStatementsRead(0), |
| 5600 | TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), |
| 5601 | NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
Sebastian Redl | c1d035f | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 5602 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 5603 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
Jonathan D. Turner | 3766fdb | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 5604 | TotalVisibleDeclContexts(0), TotalModulesSizeInBits(0), |
| 5605 | NumCurrentElementsDeserializing(0), NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5606 | { |
| 5607 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5608 | } |
| 5609 | |
| 5610 | ASTReader::~ASTReader() { |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5611 | // Delete all visible decl lookup tables |
| 5612 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 5613 | E = DeclContextOffsets.end(); |
| 5614 | I != E; ++I) { |
| 5615 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 5616 | J != F; ++J) { |
| 5617 | if (J->NameLookupTableData) |
| 5618 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 5619 | J->NameLookupTableData); |
| 5620 | } |
| 5621 | } |
| 5622 | for (DeclContextVisibleUpdatesPending::iterator |
| 5623 | I = PendingVisibleUpdates.begin(), |
| 5624 | E = PendingVisibleUpdates.end(); |
| 5625 | I != E; ++I) { |
| 5626 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5627 | F = I->second.end(); |
| 5628 | J != F; ++J) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5629 | delete static_cast<ASTDeclContextNameLookupTable*>(J->first); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5630 | } |
| 5631 | } |
| 5632 | |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5633 | //===----------------------------------------------------------------------===// |
| 5634 | // Module implementation |
| 5635 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5636 | Module::Module(ModuleKind Kind) |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5637 | : Kind(Kind), DirectlyImported(false), SizeInBits(0), |
| 5638 | LocalNumSLocEntries(0), SLocEntryBaseID(0), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5639 | SLocEntryBaseOffset(0), SLocEntryOffsets(0), |
| 5640 | SLocFileOffsets(0), LocalNumIdentifiers(0), |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 5641 | IdentifierOffsets(0), BaseIdentifierID(0), IdentifierTableData(0), |
| 5642 | IdentifierLookupTable(0), BasePreprocessedEntityID(0), |
| 5643 | LocalNumMacroDefinitions(0), MacroDefinitionOffsets(0), |
| 5644 | BaseMacroDefinitionID(0), LocalNumHeaderFileInfos(0), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5645 | HeaderFileInfoTableData(0), HeaderFileInfoTable(0), |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 5646 | HeaderFileFrameworkStrings(0), |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 5647 | LocalNumSelectors(0), SelectorOffsets(0), BaseSelectorID(0), |
Sebastian Redl | 949fe9e | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5648 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 5649 | DeclOffsets(0), BaseDeclID(0), |
| 5650 | LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 5651 | LocalNumTypes(0), TypeOffsets(0), BaseTypeIndex(0), StatCache(0), |
Jonathan D. Turner | 269f256 | 2011-07-28 23:15:22 +0000 | [diff] [blame] | 5652 | NumPreallocatedPreprocessingEntities(0) |
Douglas Gregor | b473b07 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5653 | {} |
| 5654 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5655 | Module::~Module() { |
Douglas Gregor | b473b07 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5656 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5657 | delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); |
Douglas Gregor | b473b07 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5658 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 5659 | } |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 5660 | |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 5661 | template<typename Key, typename Offset, unsigned InitialCapacity> |
| 5662 | static void |
| 5663 | dumpLocalRemap(StringRef Name, |
| 5664 | const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) { |
| 5665 | if (Map.begin() == Map.end()) |
| 5666 | return; |
| 5667 | |
| 5668 | typedef ContinuousRangeMap<Key, Offset, InitialCapacity> MapType; |
| 5669 | llvm::errs() << " " << Name << ":\n"; |
| 5670 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 5671 | I != IEnd; ++I) { |
| 5672 | llvm::errs() << " " << I->first << " -> " << I->second |
| 5673 | << "\n"; |
| 5674 | } |
| 5675 | } |
| 5676 | |
| 5677 | void Module::dump() { |
| 5678 | llvm::errs() << "\nModule: " << FileName << "\n"; |
| 5679 | if (!Imports.empty()) { |
| 5680 | llvm::errs() << " Imports: "; |
| 5681 | for (unsigned I = 0, N = Imports.size(); I != N; ++I) { |
| 5682 | if (I) |
| 5683 | llvm::errs() << ", "; |
| 5684 | llvm::errs() << Imports[I]->FileName; |
| 5685 | } |
| 5686 | llvm::errs() << "\n"; |
| 5687 | } |
| 5688 | |
| 5689 | // Remapping tables. |
| 5690 | llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset |
| 5691 | << '\n'; |
Douglas Gregor | fddf530 | 2011-08-04 19:00:50 +0000 | [diff] [blame] | 5692 | dumpLocalRemap("Source location offset local -> global map", SLocRemap); |
| 5693 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 5694 | llvm::errs() << " Base identifier ID: " << BaseIdentifierID << '\n' |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 5695 | << " Number of identifiers: " << LocalNumIdentifiers << '\n'; |
Douglas Gregor | fddf530 | 2011-08-04 19:00:50 +0000 | [diff] [blame] | 5696 | dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap); |
| 5697 | |
| 5698 | llvm::errs() << " Base selector ID: " << BaseSelectorID << '\n' |
| 5699 | << " Number of selectors: " << LocalNumSelectors << '\n'; |
| 5700 | dumpLocalRemap("Selector ID local -> global map", SelectorRemap); |
| 5701 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 5702 | llvm::errs() << " Base preprocessed entity ID: " << BasePreprocessedEntityID |
| 5703 | << '\n' |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5704 | << " Number of preprocessed entities: " |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 5705 | << NumPreallocatedPreprocessingEntities << '\n'; |
Douglas Gregor | fddf530 | 2011-08-04 19:00:50 +0000 | [diff] [blame] | 5706 | dumpLocalRemap("Preprocessed entity ID local -> global map", |
| 5707 | PreprocessedEntityRemap); |
| 5708 | |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 5709 | llvm::errs() << " Base macro definition ID: " << BaseMacroDefinitionID |
| 5710 | << '\n' |
| 5711 | << " Number of macro definitions: " << LocalNumMacroDefinitions |
| 5712 | << '\n'; |
Douglas Gregor | fddf530 | 2011-08-04 19:00:50 +0000 | [diff] [blame] | 5713 | dumpLocalRemap("Macro definition ID local -> global map", |
| 5714 | MacroDefinitionRemap); |
| 5715 | |
| 5716 | llvm::errs() << " Base type index: " << BaseTypeIndex << '\n' |
| 5717 | << " Number of types: " << LocalNumTypes << '\n'; |
| 5718 | dumpLocalRemap("Type index local -> global map", TypeRemap); |
| 5719 | |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5720 | llvm::errs() << " Base decl ID: " << BaseDeclID << '\n' |
| 5721 | << " Number of decls: " << LocalNumDecls << '\n'; |
Douglas Gregor | fddf530 | 2011-08-04 19:00:50 +0000 | [diff] [blame] | 5722 | dumpLocalRemap("Decl ID local -> global map", DeclRemap); |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 5723 | } |
| 5724 | |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5725 | //===----------------------------------------------------------------------===// |
| 5726 | // Module manager implementation |
| 5727 | //===----------------------------------------------------------------------===// |
| 5728 | |
Jonathan D. Turner | ecc2740 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5729 | Module *ModuleManager::lookup(StringRef Name) { |
| 5730 | const FileEntry *Entry = FileMgr.getFile(Name); |
| 5731 | return Modules[Entry]; |
| 5732 | } |
| 5733 | |
Jonathan D. Turner | db1c9e3 | 2011-08-02 17:40:32 +0000 | [diff] [blame] | 5734 | llvm::MemoryBuffer *ModuleManager::lookupBuffer(StringRef Name) { |
| 5735 | const FileEntry *Entry = FileMgr.getFile(Name); |
| 5736 | return InMemoryBuffers[Entry]; |
| 5737 | } |
| 5738 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 5739 | std::pair<Module *, bool> |
| 5740 | ModuleManager::addModule(StringRef FileName, ModuleKind Type, |
| 5741 | Module *ImportedBy, std::string &ErrorStr) { |
Chad Rosier | 222e187 | 2011-08-18 19:06:24 +0000 | [diff] [blame] | 5742 | const FileEntry *Entry = FileMgr.getFile(FileName); |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 5743 | if (!Entry && FileName != "-") { |
| 5744 | ErrorStr = "file not found"; |
| 5745 | return std::make_pair(static_cast<Module*>(0), false); |
| 5746 | } |
| 5747 | |
| 5748 | // Check whether we already loaded this module, before |
| 5749 | Module *&ModuleEntry = Modules[Entry]; |
| 5750 | bool NewModule = false; |
| 5751 | if (!ModuleEntry) { |
| 5752 | // Allocate a new module. |
| 5753 | Module *New = new Module(Type); |
| 5754 | New->FileName = FileName.str(); |
| 5755 | Chain.push_back(New); |
| 5756 | NewModule = true; |
| 5757 | ModuleEntry = New; |
| 5758 | |
| 5759 | // Load the contents of the module |
| 5760 | if (llvm::MemoryBuffer *Buffer = lookupBuffer(FileName)) { |
| 5761 | // The buffer was already provided for us. |
| 5762 | assert(Buffer && "Passed null buffer"); |
| 5763 | New->Buffer.reset(Buffer); |
| 5764 | } else { |
| 5765 | // Open the AST file. |
| 5766 | llvm::error_code ec; |
| 5767 | if (FileName == "-") { |
| 5768 | ec = llvm::MemoryBuffer::getSTDIN(New->Buffer); |
| 5769 | if (ec) |
| 5770 | ErrorStr = ec.message(); |
| 5771 | } else |
| 5772 | New->Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrorStr)); |
| 5773 | |
| 5774 | if (!New->Buffer) |
| 5775 | return std::make_pair(static_cast<Module*>(0), false); |
| 5776 | } |
| 5777 | |
| 5778 | // Initialize the stream |
| 5779 | New->StreamFile.init((const unsigned char *)New->Buffer->getBufferStart(), |
| 5780 | (const unsigned char *)New->Buffer->getBufferEnd()); } |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 5781 | |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5782 | if (ImportedBy) { |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 5783 | ModuleEntry->ImportedBy.insert(ImportedBy); |
| 5784 | ImportedBy->Imports.insert(ModuleEntry); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5785 | } else { |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 5786 | ModuleEntry->DirectlyImported = true; |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 5787 | } |
| 5788 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 5789 | return std::make_pair(ModuleEntry, NewModule); |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 5790 | } |
| 5791 | |
Jonathan D. Turner | db1c9e3 | 2011-08-02 17:40:32 +0000 | [diff] [blame] | 5792 | void ModuleManager::addInMemoryBuffer(StringRef FileName, |
| 5793 | llvm::MemoryBuffer *Buffer) { |
| 5794 | |
| 5795 | const FileEntry *Entry = FileMgr.getVirtualFile(FileName, |
| 5796 | Buffer->getBufferSize(), 0); |
| 5797 | InMemoryBuffers[Entry] = Buffer; |
| 5798 | } |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 5799 | |
Jonathan D. Turner | ecc2740 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5800 | ModuleManager::ModuleManager(const FileSystemOptions &FSO) : FileMgr(FSO) { } |
| 5801 | |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 5802 | ModuleManager::~ModuleManager() { |
| 5803 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 5804 | delete Chain[e - i - 1]; |
| 5805 | } |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5806 | |
| 5807 | void ModuleManager::visit(bool (*Visitor)(Module &M, void *UserData), |
| 5808 | void *UserData) { |
| 5809 | unsigned N = size(); |
| 5810 | |
| 5811 | // Record the number of incoming edges for each module. When we |
| 5812 | // encounter a module with no incoming edges, push it into the queue |
| 5813 | // to seed the queue. |
| 5814 | SmallVector<Module *, 4> Queue; |
| 5815 | Queue.reserve(N); |
| 5816 | llvm::DenseMap<Module *, unsigned> UnusedIncomingEdges; |
| 5817 | for (ModuleIterator M = begin(), MEnd = end(); M != MEnd; ++M) { |
| 5818 | if (unsigned Size = (*M)->ImportedBy.size()) |
| 5819 | UnusedIncomingEdges[*M] = Size; |
| 5820 | else |
| 5821 | Queue.push_back(*M); |
| 5822 | } |
| 5823 | |
| 5824 | llvm::SmallPtrSet<Module *, 4> Skipped; |
| 5825 | unsigned QueueStart = 0; |
| 5826 | while (QueueStart < Queue.size()) { |
| 5827 | Module *CurrentModule = Queue[QueueStart++]; |
| 5828 | |
| 5829 | // Check whether this module should be skipped. |
| 5830 | if (Skipped.count(CurrentModule)) |
| 5831 | continue; |
| 5832 | |
| 5833 | if (Visitor(*CurrentModule, UserData)) { |
| 5834 | // The visitor has requested that cut off visitation of any |
| 5835 | // module that the current module depends on. To indicate this |
| 5836 | // behavior, we mark all of the reachable modules as having N |
| 5837 | // incoming edges (which is impossible otherwise). |
| 5838 | SmallVector<Module *, 4> Stack; |
| 5839 | Stack.push_back(CurrentModule); |
| 5840 | Skipped.insert(CurrentModule); |
| 5841 | while (!Stack.empty()) { |
| 5842 | Module *NextModule = Stack.back(); |
| 5843 | Stack.pop_back(); |
| 5844 | |
| 5845 | // For any module that this module depends on, push it on the |
| 5846 | // stack (if it hasn't already been marked as visited). |
| 5847 | for (llvm::SetVector<Module *>::iterator |
| 5848 | M = NextModule->Imports.begin(), |
| 5849 | MEnd = NextModule->Imports.end(); |
| 5850 | M != MEnd; ++M) { |
| 5851 | if (Skipped.insert(*M)) |
| 5852 | Stack.push_back(*M); |
| 5853 | } |
| 5854 | } |
| 5855 | continue; |
| 5856 | } |
| 5857 | |
| 5858 | // For any module that this module depends on, push it on the |
| 5859 | // stack (if it hasn't already been marked as visited). |
| 5860 | for (llvm::SetVector<Module *>::iterator M = CurrentModule->Imports.begin(), |
| 5861 | MEnd = CurrentModule->Imports.end(); |
| 5862 | M != MEnd; ++M) { |
| 5863 | |
| 5864 | // Remove our current module as an impediment to visiting the |
| 5865 | // module we depend on. If we were the last unvisited module |
| 5866 | // that depends on this particular module, push it into the |
| 5867 | // queue to be visited. |
| 5868 | unsigned &NumUnusedEdges = UnusedIncomingEdges[*M]; |
| 5869 | if (NumUnusedEdges && (--NumUnusedEdges == 0)) |
| 5870 | Queue.push_back(*M); |
| 5871 | } |
| 5872 | } |
| 5873 | } |