Sebastian Redl | 904c9c8 | 2010-08-18 23:57:11 +0000 | [diff] [blame] | 1 | //===--- ASTReader.cpp - AST File Reader ------------------------*- C++ -*-===// |
Douglas Gregor | 2cf2634 | 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 | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 10 | // This file defines the ASTReader class, which reads AST files. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 13 | |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTReader.h" |
| 15 | #include "clang/Serialization/ASTDeserializationListener.h" |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 16 | #include "ASTCommon.h" |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 17 | #include "clang/Frontend/FrontendDiagnostic.h" |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/Utils.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 19 | #include "clang/Sema/Sema.h" |
John McCall | 5f1e094 | 2010-08-24 08:50:51 +0000 | [diff] [blame] | 20 | #include "clang/Sema/Scope.h" |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 21 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 22 | #include "clang/AST/ASTContext.h" |
John McCall | 2a7fb27 | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 24 | #include "clang/AST/Expr.h" |
John McCall | 7a1fad3 | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 26 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 27 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 28 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 29 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 30 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 31 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 32 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 33 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 34 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 35 | #include "clang/Basic/FileManager.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 36 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 37 | #include "clang/Basic/Version.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 38 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 39 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 40 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 41 | #include "llvm/Support/ErrorHandling.h" |
Daniel Dunbar | d5b2197 | 2009-11-18 19:50:41 +0000 | [diff] [blame] | 42 | #include "llvm/System/Path.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 43 | #include <algorithm> |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 44 | #include <iterator> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 45 | #include <cstdio> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 46 | #include <sys/stat.h> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 47 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 48 | using namespace clang::serialization; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 49 | |
| 50 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 51 | // PCH validator implementation |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 52 | //===----------------------------------------------------------------------===// |
| 53 | |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 54 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 55 | |
| 56 | bool |
| 57 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 58 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 59 | #define PARSE_LANGOPT_BENIGN(Option) |
| 60 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 61 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 62 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 63 | return true; \ |
| 64 | } |
| 65 | |
| 66 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 67 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 68 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 69 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 70 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 71 | PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 72 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 73 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 74 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 75 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
| 76 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
| 77 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 78 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 79 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 80 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 81 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 82 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 83 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 84 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
| 85 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 86 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 87 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 88 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 89 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 90 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 91 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 92 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 93 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 94 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 95 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 96 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 97 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 98 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 99 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 100 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 101 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 102 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 103 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 104 | diag::warn_pch_heinous_extensions); |
| 105 | // FIXME: Most of the options below are benign if the macro wasn't |
| 106 | // used. Unfortunately, this means that a PCH compiled without |
| 107 | // optimization can't be used with optimization turned on, even |
| 108 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 109 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 110 | // doesn't matter. We could consider making this some special kind |
| 111 | // of check. |
| 112 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 113 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 114 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 115 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 116 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 117 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
| 118 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 119 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 120 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 121 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 122 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 124 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 125 | return true; |
| 126 | } |
| 127 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 128 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 129 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 130 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 131 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 132 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 133 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 134 | PARSE_LANGOPT_BENIGN(SpellChecking); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 135 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 136 | #undef PARSE_LANGOPT_BENIGN |
| 137 | |
| 138 | return false; |
| 139 | } |
| 140 | |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 141 | bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) { |
| 142 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 143 | return false; |
| 144 | |
| 145 | Reader.Diag(diag::warn_pch_target_triple) |
| 146 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 147 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 150 | struct EmptyStringRef { |
Benjamin Kramer | ec1b1cc | 2010-07-14 23:19:41 +0000 | [diff] [blame] | 151 | bool operator ()(llvm::StringRef r) const { return r.empty(); } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 152 | }; |
| 153 | struct EmptyBlock { |
| 154 | bool operator ()(const PCHPredefinesBlock &r) const { return r.Data.empty(); } |
| 155 | }; |
| 156 | |
| 157 | static bool EqualConcatenations(llvm::SmallVector<llvm::StringRef, 2> L, |
| 158 | PCHPredefinesBlocks R) { |
| 159 | // First, sum up the lengths. |
| 160 | unsigned LL = 0, RL = 0; |
| 161 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 162 | LL += L[I].size(); |
| 163 | } |
| 164 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 165 | RL += R[I].Data.size(); |
| 166 | } |
| 167 | if (LL != RL) |
| 168 | return false; |
| 169 | if (LL == 0 && RL == 0) |
| 170 | return true; |
| 171 | |
| 172 | // Kick out empty parts, they confuse the algorithm below. |
| 173 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 174 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 175 | |
| 176 | // Do it the hard way. At this point, both vectors must be non-empty. |
| 177 | llvm::StringRef LR = L[0], RR = R[0].Data; |
| 178 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 179 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 180 | for (;;) { |
| 181 | // Compare the current pieces. |
| 182 | if (LR.size() == RR.size()) { |
| 183 | // If they're the same length, it's pretty easy. |
| 184 | if (LR != RR) |
| 185 | return false; |
| 186 | // Both pieces are done, advance. |
| 187 | ++LI; |
| 188 | ++RI; |
| 189 | // If either string is done, they're both done, since they're the same |
| 190 | // length. |
| 191 | if (LI == LN) { |
| 192 | assert(RI == RN && "Strings not the same length after all?"); |
| 193 | return true; |
| 194 | } |
| 195 | LR = L[LI]; |
| 196 | RR = R[RI].Data; |
| 197 | } else if (LR.size() < RR.size()) { |
| 198 | // Right piece is longer. |
| 199 | if (!RR.startswith(LR)) |
| 200 | return false; |
| 201 | ++LI; |
| 202 | assert(LI != LN && "Strings not the same length after all?"); |
| 203 | RR = RR.substr(LR.size()); |
| 204 | LR = L[LI]; |
| 205 | } else { |
| 206 | // Left piece is longer. |
| 207 | if (!LR.startswith(RR)) |
| 208 | return false; |
| 209 | ++RI; |
| 210 | assert(RI != RN && "Strings not the same length after all?"); |
| 211 | LR = LR.substr(RR.size()); |
| 212 | RR = R[RI].Data; |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | static std::pair<FileID, llvm::StringRef::size_type> |
| 218 | FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) { |
| 219 | std::pair<FileID, llvm::StringRef::size_type> Res; |
| 220 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 221 | Res.second = Buffers[I].Data.find(MacroDef); |
| 222 | if (Res.second != llvm::StringRef::npos) { |
| 223 | Res.first = Buffers[I].BufferID; |
| 224 | break; |
| 225 | } |
| 226 | } |
| 227 | return Res; |
| 228 | } |
| 229 | |
| 230 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 231 | llvm::StringRef OriginalFileName, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 232 | std::string &SuggestedPredefines) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 233 | // We are in the context of an implicit include, so the predefines buffer will |
| 234 | // have a #include entry for the PCH file itself (as normalized by the |
| 235 | // preprocessor initialization). Find it and skip over it in the checking |
| 236 | // below. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 237 | llvm::SmallString<256> PCHInclude; |
| 238 | PCHInclude += "#include \""; |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 239 | PCHInclude += NormalizeDashIncludePath(OriginalFileName); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 240 | PCHInclude += "\"\n"; |
| 241 | std::pair<llvm::StringRef,llvm::StringRef> Split = |
| 242 | llvm::StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 243 | llvm::StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 244 | if (Left == PP.getPredefines()) { |
| 245 | Error("Missing PCH include entry!"); |
| 246 | return true; |
| 247 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 248 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 249 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 250 | // command line, we're done. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 251 | llvm::SmallVector<llvm::StringRef, 2> CommandLine; |
| 252 | CommandLine.push_back(Left); |
| 253 | CommandLine.push_back(Right); |
| 254 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 255 | return false; |
| 256 | |
| 257 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 258 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 259 | // The predefines buffers are different. Determine what the differences are, |
| 260 | // and whether they require us to reject the PCH file. |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 261 | llvm::SmallVector<llvm::StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 262 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 263 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 264 | |
| 265 | llvm::SmallVector<llvm::StringRef, 8> CmdLineLines; |
| 266 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 267 | |
| 268 | // Pick out implicit #includes after the PCH and don't consider them for |
| 269 | // validation; we will insert them into SuggestedPredefines so that the |
| 270 | // preprocessor includes them. |
| 271 | std::string IncludesAfterPCH; |
| 272 | llvm::SmallVector<llvm::StringRef, 8> AfterPCHLines; |
| 273 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 274 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 275 | if (AfterPCHLines[i].startswith("#include ")) { |
| 276 | IncludesAfterPCH += AfterPCHLines[i]; |
| 277 | IncludesAfterPCH += '\n'; |
| 278 | } else { |
| 279 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | // Make sure we add the includes last into SuggestedPredefines before we |
| 284 | // exit this function. |
| 285 | struct AddIncludesRAII { |
| 286 | std::string &SuggestedPredefines; |
| 287 | std::string &IncludesAfterPCH; |
| 288 | |
| 289 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 290 | std::string &IncludesAfterPCH) |
| 291 | : SuggestedPredefines(SuggestedPredefines), |
| 292 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 293 | ~AddIncludesRAII() { |
| 294 | SuggestedPredefines += IncludesAfterPCH; |
| 295 | } |
| 296 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 297 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 298 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 299 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 300 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 301 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 302 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 303 | // Determine which predefines that were used to build the PCH file are missing |
| 304 | // from the command line. |
| 305 | std::vector<llvm::StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 306 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 307 | CmdLineLines.begin(), CmdLineLines.end(), |
| 308 | std::back_inserter(MissingPredefines)); |
| 309 | |
| 310 | bool MissingDefines = false; |
| 311 | bool ConflictingDefines = false; |
| 312 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 313 | llvm::StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 314 | if (Missing.startswith("#include ")) { |
| 315 | // An -include was specified when generating the PCH; it is included in |
| 316 | // the PCH, just ignore it. |
| 317 | continue; |
| 318 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 319 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 320 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 321 | return true; |
| 322 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 323 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 324 | // This is a macro definition. Determine the name of the macro we're |
| 325 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 326 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 327 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 328 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 329 | assert(EndOfMacroName != std::string::npos && |
| 330 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 331 | llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 332 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 333 | // Determine whether this macro was given a different definition on the |
| 334 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 335 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 336 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 337 | llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 338 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 339 | MacroDefStart); |
| 340 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 341 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 342 | // Different macro; we're done. |
| 343 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 344 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 345 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 346 | |
| 347 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 348 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 350 | (*ConflictPos)[MacroDefLen] != '(') |
| 351 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 352 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 353 | // We found a conflicting macro definition. |
| 354 | break; |
| 355 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 357 | if (ConflictPos != CmdLineLines.end()) { |
| 358 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 359 | << MacroName; |
| 360 | |
| 361 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 362 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 363 | FindMacro(Buffers, Missing); |
| 364 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 365 | SourceLocation PCHMissingLoc = |
| 366 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 367 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 368 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 369 | |
| 370 | ConflictingDefines = true; |
| 371 | continue; |
| 372 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 374 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 375 | // definition from the PCH file. Warn the user that they made a mistake. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 376 | if (ConflictingDefines) |
| 377 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 378 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 379 | if (!MissingDefines) { |
| 380 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 381 | MissingDefines = true; |
| 382 | } |
| 383 | |
| 384 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 385 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 386 | FindMacro(Buffers, Missing); |
| 387 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 388 | SourceLocation PCHMissingLoc = |
| 389 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 390 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 391 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 392 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 393 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 394 | if (ConflictingDefines) |
| 395 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 396 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 397 | // Determine what predefines were introduced based on command-line |
| 398 | // parameters that were not present when building the PCH |
| 399 | // file. Extra #defines are okay, so long as the identifiers being |
| 400 | // defined were not used within the precompiled header. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 401 | std::vector<llvm::StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 402 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 403 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 405 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 406 | llvm::StringRef &Extra = ExtraPredefines[I]; |
| 407 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 408 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 409 | return true; |
| 410 | } |
| 411 | |
| 412 | // This is an extra macro definition. Determine the name of the |
| 413 | // macro we're defining. |
| 414 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 416 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 417 | assert(EndOfMacroName != std::string::npos && |
| 418 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 419 | llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 420 | |
| 421 | // Check whether this name was used somewhere in the PCH file. If |
| 422 | // so, defining it as a macro could change behavior, so we reject |
| 423 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 424 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 425 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 426 | return true; |
| 427 | } |
| 428 | |
| 429 | // Add this definition to the suggested predefines buffer. |
| 430 | SuggestedPredefines += Extra; |
| 431 | SuggestedPredefines += '\n'; |
| 432 | } |
| 433 | |
| 434 | // If we get here, it's because the predefines buffer had compatible |
| 435 | // contents. Accept the PCH file. |
| 436 | return false; |
| 437 | } |
| 438 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 439 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 440 | unsigned ID) { |
| 441 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 442 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | void PCHValidator::ReadCounter(unsigned Value) { |
| 446 | PP.setCounterValue(Value); |
| 447 | } |
| 448 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 449 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 450 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 451 | //===----------------------------------------------------------------------===// |
| 452 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 453 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 454 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 455 | DeserializationListener = Listener; |
| 456 | if (DeserializationListener) |
| 457 | DeserializationListener->SetReader(this); |
| 458 | } |
| 459 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 460 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 461 | namespace { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 462 | class ASTSelectorLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 463 | ASTReader &Reader; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 464 | |
| 465 | public: |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 466 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 467 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 468 | ObjCMethodList Instance, Factory; |
| 469 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 470 | |
| 471 | typedef Selector external_key_type; |
| 472 | typedef external_key_type internal_key_type; |
| 473 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 474 | explicit ASTSelectorLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 475 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 476 | static bool EqualKey(const internal_key_type& a, |
| 477 | const internal_key_type& b) { |
| 478 | return a == b; |
| 479 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 480 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 481 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 482 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 483 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 484 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 485 | // This hopefully will just get inlined and removed by the optimizer. |
| 486 | static const internal_key_type& |
| 487 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 488 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 489 | static std::pair<unsigned, unsigned> |
| 490 | ReadKeyDataLength(const unsigned char*& d) { |
| 491 | using namespace clang::io; |
| 492 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 493 | unsigned DataLen = ReadUnalignedLE16(d); |
| 494 | return std::make_pair(KeyLen, DataLen); |
| 495 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 496 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 497 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 498 | using namespace clang::io; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 499 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 500 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 501 | IdentifierInfo *FirstII |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 502 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 503 | if (N == 0) |
| 504 | return SelTable.getNullarySelector(FirstII); |
| 505 | else if (N == 1) |
| 506 | return SelTable.getUnarySelector(FirstII); |
| 507 | |
| 508 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 509 | Args.push_back(FirstII); |
| 510 | for (unsigned I = 1; I != N; ++I) |
| 511 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 512 | |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 513 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 514 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 515 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 516 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 517 | using namespace clang::io; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 518 | |
| 519 | data_type Result; |
| 520 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 521 | Result.ID = ReadUnalignedLE32(d); |
| 522 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 523 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 524 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 525 | // Load instance methods |
| 526 | ObjCMethodList *Prev = 0; |
| 527 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 529 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 530 | if (!Result.Instance.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 531 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 532 | Result.Instance.Method = Method; |
| 533 | Prev = &Result.Instance; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 534 | continue; |
| 535 | } |
| 536 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 537 | ObjCMethodList *Mem = |
| 538 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 539 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 540 | Prev = Prev->Next; |
| 541 | } |
| 542 | |
| 543 | // Load factory methods |
| 544 | Prev = 0; |
| 545 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 546 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 547 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 548 | if (!Result.Factory.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 549 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 550 | Result.Factory.Method = Method; |
| 551 | Prev = &Result.Factory; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 552 | continue; |
| 553 | } |
| 554 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 555 | ObjCMethodList *Mem = |
| 556 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 557 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 558 | Prev = Prev->Next; |
| 559 | } |
| 560 | |
| 561 | return Result; |
| 562 | } |
| 563 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 564 | |
| 565 | } // end anonymous namespace |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 566 | |
| 567 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 568 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 569 | ASTSelectorLookupTable; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 570 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 571 | namespace clang { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 572 | class ASTIdentifierLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 573 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 574 | ASTReader::PerFileData &F; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 575 | |
| 576 | // If we know the IdentifierInfo in advance, it is here and we will |
| 577 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 578 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 579 | IdentifierInfo *KnownII; |
| 580 | |
| 581 | public: |
| 582 | typedef IdentifierInfo * data_type; |
| 583 | |
| 584 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 585 | |
| 586 | typedef external_key_type internal_key_type; |
| 587 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 588 | ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 589 | IdentifierInfo *II = 0) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 590 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 591 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 592 | static bool EqualKey(const internal_key_type& a, |
| 593 | const internal_key_type& b) { |
| 594 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 595 | : false; |
| 596 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 597 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 598 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 599 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 600 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 601 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 602 | // This hopefully will just get inlined and removed by the optimizer. |
| 603 | static const internal_key_type& |
| 604 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 605 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 606 | static std::pair<unsigned, unsigned> |
| 607 | ReadKeyDataLength(const unsigned char*& d) { |
| 608 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 609 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 610 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 611 | return std::make_pair(KeyLen, DataLen); |
| 612 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 613 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 614 | static std::pair<const char*, unsigned> |
| 615 | ReadKey(const unsigned char* d, unsigned n) { |
| 616 | assert(n >= 2 && d[n-1] == '\0'); |
| 617 | return std::make_pair((const char*) d, n-1); |
| 618 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 619 | |
| 620 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 621 | const unsigned char* d, |
| 622 | unsigned DataLen) { |
| 623 | using namespace clang::io; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 624 | IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 625 | bool IsInteresting = ID & 0x01; |
| 626 | |
| 627 | // Wipe out the "is interesting" bit. |
| 628 | ID = ID >> 1; |
| 629 | |
| 630 | if (!IsInteresting) { |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 631 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 632 | // and associate it with the persistent ID. |
| 633 | IdentifierInfo *II = KnownII; |
| 634 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 635 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 636 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 637 | II->setIsFromAST(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 638 | return II; |
| 639 | } |
| 640 | |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 641 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 642 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 643 | Bits >>= 1; |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 644 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 645 | Bits >>= 1; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 646 | bool Poisoned = Bits & 0x01; |
| 647 | Bits >>= 1; |
| 648 | bool ExtensionToken = Bits & 0x01; |
| 649 | Bits >>= 1; |
| 650 | bool hasMacroDefinition = Bits & 0x01; |
| 651 | Bits >>= 1; |
| 652 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 653 | Bits >>= 10; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 654 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 655 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 656 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 657 | |
| 658 | // Build the IdentifierInfo itself and link the identifier ID with |
| 659 | // the new IdentifierInfo. |
| 660 | IdentifierInfo *II = KnownII; |
| 661 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 662 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 663 | Reader.SetIdentifierInfo(ID, II); |
| 664 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 665 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 666 | // Token IDs are read-only. |
| 667 | if (HasRevertedTokenIDToIdentifier) |
| 668 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 669 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 670 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 671 | "Incorrect extension token flag"); |
| 672 | (void)ExtensionToken; |
| 673 | II->setIsPoisoned(Poisoned); |
| 674 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 675 | "Incorrect C++ operator keyword flag"); |
| 676 | (void)CPlusPlusOperatorKeyword; |
| 677 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 678 | // If this identifier is a macro, deserialize the macro |
| 679 | // definition. |
| 680 | if (hasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 681 | uint32_t Offset = ReadUnalignedLE32(d); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 682 | Reader.ReadMacroRecord(F, Offset); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 683 | DataLen -= 4; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 684 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 685 | |
| 686 | // Read all of the declarations visible at global scope with this |
| 687 | // name. |
Chris Lattner | 6bf690f | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 688 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 689 | if (DataLen > 0) { |
| 690 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 691 | for (; DataLen > 0; DataLen -= 4) |
| 692 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 693 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 694 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 695 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 696 | II->setIsFromAST(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 697 | return II; |
| 698 | } |
| 699 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 700 | |
| 701 | } // end anonymous namespace |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 702 | |
| 703 | /// \brief The on-disk hash table used to contain information about |
| 704 | /// all of the identifiers in the program. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 705 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 706 | ASTIdentifierLookupTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 707 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 708 | namespace { |
| 709 | class ASTDeclContextNameLookupTrait { |
| 710 | ASTReader &Reader; |
| 711 | |
| 712 | public: |
| 713 | /// \brief Pair of begin/end iterators for DeclIDs. |
| 714 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 715 | |
| 716 | /// \brief Special internal key for declaration names. |
| 717 | /// The hash table creates keys for comparison; we do not create |
| 718 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 719 | struct DeclNameKey { |
| 720 | DeclarationName::NameKind Kind; |
| 721 | uint64_t Data; |
| 722 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 723 | }; |
| 724 | |
| 725 | typedef DeclarationName external_key_type; |
| 726 | typedef DeclNameKey internal_key_type; |
| 727 | |
| 728 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
| 729 | |
| 730 | static bool EqualKey(const internal_key_type& a, |
| 731 | const internal_key_type& b) { |
| 732 | return a.Kind == b.Kind && a.Data == b.Data; |
| 733 | } |
| 734 | |
| 735 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 736 | llvm::FoldingSetNodeID ID; |
| 737 | ID.AddInteger(Key.Kind); |
| 738 | |
| 739 | switch (Key.Kind) { |
| 740 | case DeclarationName::Identifier: |
| 741 | case DeclarationName::CXXLiteralOperatorName: |
| 742 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 743 | break; |
| 744 | case DeclarationName::ObjCZeroArgSelector: |
| 745 | case DeclarationName::ObjCOneArgSelector: |
| 746 | case DeclarationName::ObjCMultiArgSelector: |
| 747 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 748 | break; |
| 749 | case DeclarationName::CXXConstructorName: |
| 750 | case DeclarationName::CXXDestructorName: |
| 751 | case DeclarationName::CXXConversionFunctionName: |
| 752 | ID.AddInteger((TypeID)Key.Data); |
| 753 | break; |
| 754 | case DeclarationName::CXXOperatorName: |
| 755 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 756 | break; |
| 757 | case DeclarationName::CXXUsingDirective: |
| 758 | break; |
| 759 | } |
| 760 | |
| 761 | return ID.ComputeHash(); |
| 762 | } |
| 763 | |
| 764 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 765 | DeclNameKey Key; |
| 766 | Key.Kind = Name.getNameKind(); |
| 767 | switch (Name.getNameKind()) { |
| 768 | case DeclarationName::Identifier: |
| 769 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 770 | break; |
| 771 | case DeclarationName::ObjCZeroArgSelector: |
| 772 | case DeclarationName::ObjCOneArgSelector: |
| 773 | case DeclarationName::ObjCMultiArgSelector: |
| 774 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 775 | break; |
| 776 | case DeclarationName::CXXConstructorName: |
| 777 | case DeclarationName::CXXDestructorName: |
| 778 | case DeclarationName::CXXConversionFunctionName: |
| 779 | Key.Data = Reader.GetTypeID(Name.getCXXNameType()); |
| 780 | break; |
| 781 | case DeclarationName::CXXOperatorName: |
| 782 | Key.Data = Name.getCXXOverloadedOperator(); |
| 783 | break; |
| 784 | case DeclarationName::CXXLiteralOperatorName: |
| 785 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 786 | break; |
| 787 | case DeclarationName::CXXUsingDirective: |
| 788 | break; |
| 789 | } |
| 790 | |
| 791 | return Key; |
| 792 | } |
| 793 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 794 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 795 | ASTContext *Context = Reader.getContext(); |
| 796 | switch (Key.Kind) { |
| 797 | case DeclarationName::Identifier: |
| 798 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 799 | |
| 800 | case DeclarationName::ObjCZeroArgSelector: |
| 801 | case DeclarationName::ObjCOneArgSelector: |
| 802 | case DeclarationName::ObjCMultiArgSelector: |
| 803 | return DeclarationName(Selector(Key.Data)); |
| 804 | |
| 805 | case DeclarationName::CXXConstructorName: |
| 806 | return Context->DeclarationNames.getCXXConstructorName( |
| 807 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 808 | |
| 809 | case DeclarationName::CXXDestructorName: |
| 810 | return Context->DeclarationNames.getCXXDestructorName( |
| 811 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 812 | |
| 813 | case DeclarationName::CXXConversionFunctionName: |
| 814 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 815 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 816 | |
| 817 | case DeclarationName::CXXOperatorName: |
| 818 | return Context->DeclarationNames.getCXXOperatorName( |
| 819 | (OverloadedOperatorKind)Key.Data); |
| 820 | |
| 821 | case DeclarationName::CXXLiteralOperatorName: |
| 822 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 823 | (IdentifierInfo*)Key.Data); |
| 824 | |
| 825 | case DeclarationName::CXXUsingDirective: |
| 826 | return DeclarationName::getUsingDirectiveName(); |
| 827 | } |
| 828 | |
| 829 | llvm_unreachable("Invalid Name Kind ?"); |
| 830 | } |
| 831 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 832 | static std::pair<unsigned, unsigned> |
| 833 | ReadKeyDataLength(const unsigned char*& d) { |
| 834 | using namespace clang::io; |
| 835 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 836 | unsigned DataLen = ReadUnalignedLE16(d); |
| 837 | return std::make_pair(KeyLen, DataLen); |
| 838 | } |
| 839 | |
| 840 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 841 | using namespace clang::io; |
| 842 | |
| 843 | DeclNameKey Key; |
| 844 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 845 | switch (Key.Kind) { |
| 846 | case DeclarationName::Identifier: |
| 847 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 848 | break; |
| 849 | case DeclarationName::ObjCZeroArgSelector: |
| 850 | case DeclarationName::ObjCOneArgSelector: |
| 851 | case DeclarationName::ObjCMultiArgSelector: |
| 852 | Key.Data = |
| 853 | (uint64_t)Reader.DecodeSelector(ReadUnalignedLE32(d)).getAsOpaquePtr(); |
| 854 | break; |
| 855 | case DeclarationName::CXXConstructorName: |
| 856 | case DeclarationName::CXXDestructorName: |
| 857 | case DeclarationName::CXXConversionFunctionName: |
| 858 | Key.Data = ReadUnalignedLE32(d); // TypeID |
| 859 | break; |
| 860 | case DeclarationName::CXXOperatorName: |
| 861 | Key.Data = *d++; // OverloadedOperatorKind |
| 862 | break; |
| 863 | case DeclarationName::CXXLiteralOperatorName: |
| 864 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 865 | break; |
| 866 | case DeclarationName::CXXUsingDirective: |
| 867 | break; |
| 868 | } |
| 869 | |
| 870 | return Key; |
| 871 | } |
| 872 | |
| 873 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 874 | unsigned DataLen) { |
| 875 | using namespace clang::io; |
| 876 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 877 | DeclID *Start = (DeclID *)d; |
| 878 | return std::make_pair(Start, Start + NumDecls); |
| 879 | } |
| 880 | }; |
| 881 | |
| 882 | } // end anonymous namespace |
| 883 | |
| 884 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 885 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 886 | ASTDeclContextNameLookupTable; |
| 887 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 888 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 889 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 890 | DeclContextInfo &Info) { |
| 891 | SavedStreamPosition SavedPosition(Cursor); |
| 892 | // First the lexical decls. |
| 893 | if (Offsets.first != 0) { |
| 894 | Cursor.JumpToBit(Offsets.first); |
| 895 | |
| 896 | RecordData Record; |
| 897 | const char *Blob; |
| 898 | unsigned BlobLen; |
| 899 | unsigned Code = Cursor.ReadCode(); |
| 900 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 901 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 902 | Error("Expected lexical block"); |
| 903 | return true; |
| 904 | } |
| 905 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame^] | 906 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 907 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 908 | } else { |
| 909 | Info.LexicalDecls = 0; |
| 910 | Info.NumLexicalDecls = 0; |
| 911 | } |
| 912 | |
| 913 | // Now the lookup table. |
| 914 | if (Offsets.second != 0) { |
| 915 | Cursor.JumpToBit(Offsets.second); |
| 916 | |
| 917 | RecordData Record; |
| 918 | const char *Blob; |
| 919 | unsigned BlobLen; |
| 920 | unsigned Code = Cursor.ReadCode(); |
| 921 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 922 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 923 | Error("Expected visible lookup table block"); |
| 924 | return true; |
| 925 | } |
| 926 | Info.NameLookupTableData |
| 927 | = ASTDeclContextNameLookupTable::Create( |
| 928 | (const unsigned char *)Blob + Record[0], |
| 929 | (const unsigned char *)Blob, |
| 930 | ASTDeclContextNameLookupTrait(*this)); |
Sebastian Redl | 0ea8f7f | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 931 | } else { |
| 932 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | return false; |
| 936 | } |
| 937 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 938 | void ASTReader::Error(const char *Msg) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 939 | Diag(diag::err_fe_pch_malformed) << Msg; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 940 | } |
| 941 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 942 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 943 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 944 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 945 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 946 | ActualOriginalFileName, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 947 | SuggestedPredefines); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 948 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 951 | //===----------------------------------------------------------------------===// |
| 952 | // Source Manager Deserialization |
| 953 | //===----------------------------------------------------------------------===// |
| 954 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 955 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 956 | /// \returns true if there was an error. |
| 957 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 958 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 959 | unsigned Idx = 0; |
| 960 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 961 | |
| 962 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 963 | std::map<int, int> FileIDs; |
| 964 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 965 | // Extract the file name |
| 966 | unsigned FilenameLen = Record[Idx++]; |
| 967 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 968 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 969 | MaybeAddSystemRootToFilename(Filename); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 970 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 971 | Filename.size()); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | // Parse the line entries |
| 975 | std::vector<LineEntry> Entries; |
| 976 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 977 | int FID = Record[Idx++]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 978 | |
| 979 | // Extract the line entries |
| 980 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 981 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 982 | Entries.clear(); |
| 983 | Entries.reserve(NumEntries); |
| 984 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 985 | unsigned FileOffset = Record[Idx++]; |
| 986 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 987 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 988 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 989 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 990 | unsigned IncludeOffset = Record[Idx++]; |
| 991 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 992 | FileKind, IncludeOffset)); |
| 993 | } |
| 994 | LineTable.AddEntry(FID, Entries); |
| 995 | } |
| 996 | |
| 997 | return false; |
| 998 | } |
| 999 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1000 | namespace { |
| 1001 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1002 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1003 | public: |
| 1004 | const bool hasStat; |
| 1005 | const ino_t ino; |
| 1006 | const dev_t dev; |
| 1007 | const mode_t mode; |
| 1008 | const time_t mtime; |
| 1009 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1010 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1011 | ASTStatData(ino_t i, dev_t d, mode_t mo, time_t m, off_t s) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1012 | : hasStat(true), ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
| 1013 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1014 | ASTStatData() |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1015 | : hasStat(false), ino(0), dev(0), mode(0), mtime(0), size(0) {} |
| 1016 | }; |
| 1017 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1018 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1019 | public: |
| 1020 | typedef const char *external_key_type; |
| 1021 | typedef const char *internal_key_type; |
| 1022 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1023 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1024 | |
| 1025 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1026 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1030 | |
| 1031 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1032 | return strcmp(a, b) == 0; |
| 1033 | } |
| 1034 | |
| 1035 | static std::pair<unsigned, unsigned> |
| 1036 | ReadKeyDataLength(const unsigned char*& d) { |
| 1037 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1038 | unsigned DataLen = (unsigned) *d++; |
| 1039 | return std::make_pair(KeyLen + 1, DataLen); |
| 1040 | } |
| 1041 | |
| 1042 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1043 | return (const char *)d; |
| 1044 | } |
| 1045 | |
| 1046 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1047 | unsigned /*DataLen*/) { |
| 1048 | using namespace clang::io; |
| 1049 | |
| 1050 | if (*d++ == 1) |
| 1051 | return data_type(); |
| 1052 | |
| 1053 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1054 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1055 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1056 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1057 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1058 | return data_type(ino, dev, mode, mtime, size); |
| 1059 | } |
| 1060 | }; |
| 1061 | |
| 1062 | /// \brief stat() cache for precompiled headers. |
| 1063 | /// |
| 1064 | /// This cache is very similar to the stat cache used by pretokenized |
| 1065 | /// headers. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1066 | class ASTStatCache : public StatSysCallCache { |
| 1067 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1068 | CacheTy *Cache; |
| 1069 | |
| 1070 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1071 | public: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1072 | ASTStatCache(const unsigned char *Buckets, |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1073 | const unsigned char *Base, |
| 1074 | unsigned &NumStatHits, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1075 | unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1076 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1077 | Cache = CacheTy::Create(Buckets, Base); |
| 1078 | } |
| 1079 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1080 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1081 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1082 | int stat(const char *path, struct stat *buf) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1083 | // Do the lookup for the file's data in the AST file. |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1084 | CacheTy::iterator I = Cache->find(path); |
| 1085 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1086 | // If we don't get a hit in the AST file just forward to 'stat'. |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1087 | if (I == Cache->end()) { |
| 1088 | ++NumStatMisses; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 1089 | return StatSysCallCache::stat(path, buf); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1090 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1091 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1092 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1093 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1095 | if (!Data.hasStat) |
| 1096 | return 1; |
| 1097 | |
| 1098 | buf->st_ino = Data.ino; |
| 1099 | buf->st_dev = Data.dev; |
| 1100 | buf->st_mtime = Data.mtime; |
| 1101 | buf->st_mode = Data.mode; |
| 1102 | buf->st_size = Data.size; |
| 1103 | return 0; |
| 1104 | } |
| 1105 | }; |
| 1106 | } // end anonymous namespace |
| 1107 | |
| 1108 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1109 | /// \brief Read a source manager block |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1110 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1111 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1112 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1113 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1114 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1115 | // Set the source-location entry cursor to the current position in |
| 1116 | // the stream. This cursor will be used to read the contents of the |
| 1117 | // source manager block initially, and then lazily read |
| 1118 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1119 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1120 | |
| 1121 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1122 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1123 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1124 | return Failure; |
| 1125 | } |
| 1126 | |
| 1127 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1128 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1129 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1130 | return Failure; |
| 1131 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1132 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1133 | RecordData Record; |
| 1134 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1135 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1136 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1137 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1138 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1139 | return Failure; |
| 1140 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1141 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1142 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1143 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1144 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1145 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1146 | SLocEntryCursor.ReadSubBlockID(); |
| 1147 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1148 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1149 | return Failure; |
| 1150 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1151 | continue; |
| 1152 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1153 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1154 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1155 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1156 | continue; |
| 1157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1158 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1159 | // Read a record. |
| 1160 | const char *BlobStart; |
| 1161 | unsigned BlobLen; |
| 1162 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1163 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1164 | default: // Default behavior: ignore. |
| 1165 | break; |
| 1166 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1167 | case SM_LINE_TABLE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1168 | if (ParseLineTable(F, Record)) |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1169 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1170 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1171 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1172 | case SM_SLOC_FILE_ENTRY: |
| 1173 | case SM_SLOC_BUFFER_ENTRY: |
| 1174 | case SM_SLOC_INSTANTIATION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1175 | // Once we hit one of the source location entries, we're done. |
| 1176 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | } |
| 1180 | |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1181 | /// \brief Get a cursor that's correctly positioned for reading the source |
| 1182 | /// location entry with the given ID. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1183 | ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1184 | assert(ID != 0 && ID <= TotalNumSLocEntries && |
| 1185 | "SLocCursorForID should only be called for real IDs."); |
| 1186 | |
| 1187 | ID -= 1; |
| 1188 | PerFileData *F = 0; |
| 1189 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1190 | F = Chain[N - I - 1]; |
| 1191 | if (ID < F->LocalNumSLocEntries) |
| 1192 | break; |
| 1193 | ID -= F->LocalNumSLocEntries; |
| 1194 | } |
| 1195 | assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); |
| 1196 | |
| 1197 | F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1198 | return F; |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1201 | /// \brief Read in the source location entry with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1202 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1203 | if (ID == 0) |
| 1204 | return Success; |
| 1205 | |
| 1206 | if (ID > TotalNumSLocEntries) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1207 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1208 | return Failure; |
| 1209 | } |
| 1210 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1211 | PerFileData *F = SLocCursorForID(ID); |
| 1212 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1213 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1214 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1215 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1216 | if (Code == llvm::bitc::END_BLOCK || |
| 1217 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1218 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1219 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1220 | return Failure; |
| 1221 | } |
| 1222 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1223 | RecordData Record; |
| 1224 | const char *BlobStart; |
| 1225 | unsigned BlobLen; |
| 1226 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1227 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1228 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1229 | return Failure; |
| 1230 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1231 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1232 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1233 | MaybeAddSystemRootToFilename(Filename); |
| 1234 | const FileEntry *File = FileMgr.getFile(Filename); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1235 | if (File == 0) { |
| 1236 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1237 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1238 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1239 | Error(ErrorStr.c_str()); |
| 1240 | return Failure; |
| 1241 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1243 | if (Record.size() < 10) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1244 | Error("source location entry is incorrect"); |
| 1245 | return Failure; |
| 1246 | } |
| 1247 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1248 | if (!DisableValidation && |
| 1249 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1250 | #if !defined(LLVM_ON_WIN32) |
| 1251 | // In our regression testing, the Windows file system seems to |
| 1252 | // have inconsistent modification times that sometimes |
| 1253 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1254 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1255 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1256 | )) { |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1257 | Diag(diag::err_fe_pch_file_modified) |
| 1258 | << Filename; |
| 1259 | return Failure; |
| 1260 | } |
| 1261 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1262 | FileID FID = SourceMgr.createFileID(File, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1263 | ReadSourceLocation(*F, Record[1]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1264 | (SrcMgr::CharacteristicKind)Record[2], |
| 1265 | ID, Record[0]); |
| 1266 | if (Record[3]) |
| 1267 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1268 | .setHasLineDirectives(); |
| 1269 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 1270 | // Reconstruct header-search information for this file. |
| 1271 | HeaderFileInfo HFI; |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1272 | HFI.isImport = Record[6]; |
| 1273 | HFI.DirInfo = Record[7]; |
| 1274 | HFI.NumIncludes = Record[8]; |
| 1275 | HFI.ControllingMacroID = Record[9]; |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 1276 | if (Listener) |
| 1277 | Listener->ReadHeaderFileInfo(HFI, File->getUID()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1278 | break; |
| 1279 | } |
| 1280 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1281 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1282 | const char *Name = BlobStart; |
| 1283 | unsigned Offset = Record[0]; |
| 1284 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1285 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1286 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1287 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1288 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1289 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1290 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1291 | return Failure; |
| 1292 | } |
| 1293 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1294 | llvm::MemoryBuffer *Buffer |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1295 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1296 | Name); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1297 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1298 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1299 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1300 | PCHPredefinesBlock Block = { |
| 1301 | BufferID, |
| 1302 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1303 | }; |
| 1304 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1305 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1306 | |
| 1307 | break; |
| 1308 | } |
| 1309 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1310 | case SM_SLOC_INSTANTIATION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1311 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1312 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1313 | ReadSourceLocation(*F, Record[2]), |
| 1314 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1315 | Record[4], |
| 1316 | ID, |
| 1317 | Record[0]); |
| 1318 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1319 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | return Success; |
| 1323 | } |
| 1324 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1325 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1326 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1327 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1328 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1329 | unsigned BlockID) { |
| 1330 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1331 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1332 | return Failure; |
| 1333 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1334 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1335 | while (true) { |
| 1336 | unsigned Code = Cursor.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1337 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1338 | // We expect all abbrevs to be at the start of the block. |
| 1339 | if (Code != llvm::bitc::DEFINE_ABBREV) |
| 1340 | return false; |
| 1341 | Cursor.ReadAbbrevRecord(); |
| 1342 | } |
| 1343 | } |
| 1344 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1345 | void ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1346 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1347 | llvm::BitstreamCursor &Stream = F.Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1348 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1349 | // Keep track of where we are in the stream, then jump back there |
| 1350 | // after reading this macro. |
| 1351 | SavedStreamPosition SavedPosition(Stream); |
| 1352 | |
| 1353 | Stream.JumpToBit(Offset); |
| 1354 | RecordData Record; |
| 1355 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1356 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1357 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1358 | while (true) { |
| 1359 | unsigned Code = Stream.ReadCode(); |
| 1360 | switch (Code) { |
| 1361 | case llvm::bitc::END_BLOCK: |
| 1362 | return; |
| 1363 | |
| 1364 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1365 | // No known subblocks, always skip them. |
| 1366 | Stream.ReadSubBlockID(); |
| 1367 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1368 | Error("malformed block record in AST file"); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1369 | return; |
| 1370 | } |
| 1371 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1372 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1373 | case llvm::bitc::DEFINE_ABBREV: |
| 1374 | Stream.ReadAbbrevRecord(); |
| 1375 | continue; |
| 1376 | default: break; |
| 1377 | } |
| 1378 | |
| 1379 | // Read a record. |
| 1380 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1381 | PreprocessorRecordTypes RecType = |
| 1382 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1383 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1384 | case PP_MACRO_OBJECT_LIKE: |
| 1385 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1386 | // If we already have a macro, that means that we've hit the end |
| 1387 | // of the definition of the macro we were looking for. We're |
| 1388 | // done. |
| 1389 | if (Macro) |
| 1390 | return; |
| 1391 | |
| 1392 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1393 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1394 | Error("macro must have a name in AST file"); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1395 | return; |
| 1396 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1397 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1398 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1399 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1400 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1401 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1402 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1403 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1404 | unsigned NextIndex = 3; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1405 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1406 | // Decode function-like macro info. |
| 1407 | bool isC99VarArgs = Record[3]; |
| 1408 | bool isGNUVarArgs = Record[4]; |
| 1409 | MacroArgs.clear(); |
| 1410 | unsigned NumArgs = Record[5]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1411 | NextIndex = 6 + NumArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1412 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1413 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1414 | |
| 1415 | // Install function-like macro info. |
| 1416 | MI->setIsFunctionLike(); |
| 1417 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1418 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1419 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1420 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1424 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1425 | |
| 1426 | // Remember that we saw this macro last so that we add the tokens that |
| 1427 | // form its body to it. |
| 1428 | Macro = MI; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1429 | |
| 1430 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1431 | // We have a macro definition. Load it now. |
| 1432 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1433 | getMacroDefinition(Record[NextIndex])); |
| 1434 | } |
| 1435 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1436 | ++NumMacrosRead; |
| 1437 | break; |
| 1438 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1439 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1440 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1441 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1442 | // erroneous, just pretend we didn't see this. |
| 1443 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1444 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1445 | Token Tok; |
| 1446 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1447 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1448 | Tok.setLength(Record[1]); |
| 1449 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1450 | Tok.setIdentifierInfo(II); |
| 1451 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1452 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1453 | Macro->AddTokenToBody(Tok); |
| 1454 | break; |
| 1455 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1456 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1457 | case PP_MACRO_INSTANTIATION: { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1458 | // If we already have a macro, that means that we've hit the end |
| 1459 | // of the definition of the macro we were looking for. We're |
| 1460 | // done. |
| 1461 | if (Macro) |
| 1462 | return; |
| 1463 | |
| 1464 | if (!PP->getPreprocessingRecord()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1465 | Error("missing preprocessing record in AST file"); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1466 | return; |
| 1467 | } |
| 1468 | |
| 1469 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1470 | if (PPRec.getPreprocessedEntity(Record[0])) |
| 1471 | return; |
| 1472 | |
| 1473 | MacroInstantiation *MI |
| 1474 | = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1475 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1476 | ReadSourceLocation(F, Record[2])), |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1477 | getMacroDefinition(Record[4])); |
| 1478 | PPRec.SetPreallocatedEntity(Record[0], MI); |
| 1479 | return; |
| 1480 | } |
| 1481 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1482 | case PP_MACRO_DEFINITION: { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1483 | // If we already have a macro, that means that we've hit the end |
| 1484 | // of the definition of the macro we were looking for. We're |
| 1485 | // done. |
| 1486 | if (Macro) |
| 1487 | return; |
| 1488 | |
| 1489 | if (!PP->getPreprocessingRecord()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1490 | Error("missing preprocessing record in AST file"); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1491 | return; |
| 1492 | } |
| 1493 | |
| 1494 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1495 | if (PPRec.getPreprocessedEntity(Record[0])) |
| 1496 | return; |
| 1497 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1498 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1499 | Error("out-of-bounds macro definition record"); |
| 1500 | return; |
| 1501 | } |
| 1502 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1503 | // Decode the identifier info and then check again; if the macro is |
| 1504 | // still defined and associated with the identifier, |
| 1505 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1506 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1507 | MacroDefinition *MD |
| 1508 | = new (PPRec) MacroDefinition(II, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1509 | ReadSourceLocation(F, Record[5]), |
Douglas Gregor | b1a7d9a | 2010-10-01 20:33:34 +0000 | [diff] [blame] | 1510 | SourceRange( |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1511 | ReadSourceLocation(F, Record[2]), |
| 1512 | ReadSourceLocation(F, Record[3]))); |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1513 | |
| 1514 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1515 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
| 1516 | |
| 1517 | if (DeserializationListener) |
| 1518 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1519 | } |
| 1520 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1521 | return; |
| 1522 | } |
Sebastian Redl | b57a624 | 2010-09-27 22:18:47 +0000 | [diff] [blame] | 1523 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1524 | } |
| 1525 | } |
| 1526 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1527 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1528 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1529 | PerFileData &F = *Chain[N - I - 1]; |
| 1530 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1531 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1532 | // If there was no preprocessor block, skip this file. |
| 1533 | if (!MacroCursor.getBitStreamReader()) |
| 1534 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1535 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1536 | llvm::BitstreamCursor Cursor = MacroCursor; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1537 | if (Cursor.EnterSubBlock(PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1538 | Error("malformed preprocessor block record in AST file"); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1539 | return; |
| 1540 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1541 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1542 | RecordData Record; |
| 1543 | while (true) { |
Sebastian Redl | edadecc | 2010-09-28 02:55:49 +0000 | [diff] [blame] | 1544 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1545 | unsigned Code = Cursor.ReadCode(); |
| 1546 | if (Code == llvm::bitc::END_BLOCK) { |
| 1547 | if (Cursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1548 | Error("error at end of preprocessor block in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1549 | return; |
| 1550 | } |
| 1551 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1552 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1553 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1554 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1555 | // No known subblocks, always skip them. |
| 1556 | Cursor.ReadSubBlockID(); |
| 1557 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1558 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1559 | return; |
| 1560 | } |
| 1561 | continue; |
| 1562 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1563 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1564 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1565 | Cursor.ReadAbbrevRecord(); |
| 1566 | continue; |
| 1567 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1568 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1569 | // Read a record. |
| 1570 | const char *BlobStart; |
| 1571 | unsigned BlobLen; |
| 1572 | Record.clear(); |
| 1573 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1574 | default: // Default behavior: ignore. |
| 1575 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1576 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1577 | case PP_MACRO_OBJECT_LIKE: |
| 1578 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1579 | DecodeIdentifierInfo(Record[0]); |
| 1580 | break; |
| 1581 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1582 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1583 | // Ignore tokens. |
| 1584 | break; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1585 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1586 | case PP_MACRO_INSTANTIATION: |
| 1587 | case PP_MACRO_DEFINITION: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1588 | // Read the macro record. |
Sebastian Redl | edadecc | 2010-09-28 02:55:49 +0000 | [diff] [blame] | 1589 | // FIXME: That's a stupid way to do this. We should reuse this cursor. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1590 | ReadMacroRecord(F, Offset); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1591 | break; |
| 1592 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1593 | } |
| 1594 | } |
| 1595 | } |
| 1596 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1597 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1598 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1599 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1600 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1601 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1602 | unsigned Index = ID - 1; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1603 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1604 | PerFileData &F = *Chain[N - I - 1]; |
| 1605 | if (Index < F.LocalNumMacroDefinitions) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1606 | ReadMacroRecord(F, F.MacroDefinitionOffsets[Index]); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1607 | break; |
| 1608 | } |
| 1609 | Index -= F.LocalNumMacroDefinitions; |
| 1610 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1611 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1614 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1617 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1618 | /// not an absolute path, add the system root to the beginning of the file |
| 1619 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1620 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1621 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1622 | if (!RelocatablePCH) |
| 1623 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1624 | |
Daniel Dunbar | d5b2197 | 2009-11-18 19:50:41 +0000 | [diff] [blame] | 1625 | if (Filename.empty() || llvm::sys::Path(Filename).isAbsolute()) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1626 | return; |
| 1627 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1628 | if (isysroot == 0) { |
| 1629 | // If no system root was given, default to '/' |
| 1630 | Filename.insert(Filename.begin(), '/'); |
| 1631 | return; |
| 1632 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1633 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1634 | unsigned Length = strlen(isysroot); |
| 1635 | if (isysroot[Length - 1] != '/') |
| 1636 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1637 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1638 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1639 | } |
| 1640 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1641 | ASTReader::ASTReadResult |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1642 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1643 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1644 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1645 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1646 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1647 | return Failure; |
| 1648 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1649 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1650 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1651 | RecordData Record; |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1652 | bool First = true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1653 | while (!Stream.AtEndOfStream()) { |
| 1654 | unsigned Code = Stream.ReadCode(); |
| 1655 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1656 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1657 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1658 | return Failure; |
| 1659 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1660 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1661 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1665 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1666 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1667 | // We lazily load the decls block, but we want to set up the |
| 1668 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1669 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1670 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1671 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1672 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1673 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1674 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1675 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1676 | return Failure; |
| 1677 | } |
| 1678 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1679 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1680 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1681 | F.MacroCursor = Stream; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1682 | if (PP) |
| 1683 | PP->setExternalSource(this); |
| 1684 | |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1685 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1686 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1687 | return Failure; |
| 1688 | } |
| 1689 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1690 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1691 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1692 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1693 | case Success: |
| 1694 | break; |
| 1695 | |
| 1696 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1697 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1698 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1699 | |
| 1700 | case IgnorePCH: |
| 1701 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1702 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1703 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1704 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1705 | First = false; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1706 | continue; |
| 1707 | } |
| 1708 | |
| 1709 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1710 | Stream.ReadAbbrevRecord(); |
| 1711 | continue; |
| 1712 | } |
| 1713 | |
| 1714 | // Read and process a record. |
| 1715 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1716 | const char *BlobStart = 0; |
| 1717 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1718 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1719 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1720 | default: // Default behavior: ignore. |
| 1721 | break; |
| 1722 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1723 | case METADATA: { |
| 1724 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1725 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1726 | : diag::warn_pch_version_too_new); |
| 1727 | return IgnorePCH; |
| 1728 | } |
| 1729 | |
| 1730 | RelocatablePCH = Record[4]; |
| 1731 | if (Listener) { |
| 1732 | std::string TargetTriple(BlobStart, BlobLen); |
| 1733 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1734 | return IgnorePCH; |
| 1735 | } |
| 1736 | break; |
| 1737 | } |
| 1738 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1739 | case CHAINED_METADATA: { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1740 | if (!First) { |
| 1741 | Error("CHAINED_METADATA is not first record in block"); |
| 1742 | return Failure; |
| 1743 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1744 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1745 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1746 | : diag::warn_pch_version_too_new); |
| 1747 | return IgnorePCH; |
| 1748 | } |
| 1749 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 1750 | // Load the chained file, which is always a PCH file. |
| 1751 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1752 | case Failure: return Failure; |
| 1753 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1754 | case IgnorePCH: return IgnorePCH; |
| 1755 | case Success: break; |
| 1756 | } |
| 1757 | break; |
| 1758 | } |
| 1759 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1760 | case TYPE_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1761 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1762 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1763 | return Failure; |
| 1764 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1765 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1766 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1767 | break; |
| 1768 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1769 | case DECL_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1770 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1771 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1772 | return Failure; |
| 1773 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1774 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 1775 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1776 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1777 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1778 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1779 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 1780 | /* No visible information */ 0, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame^] | 1781 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 1782 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1783 | }; |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 1784 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 1785 | .push_back(Info); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1786 | break; |
| 1787 | } |
| 1788 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1789 | case UPDATE_VISIBLE: { |
| 1790 | serialization::DeclID ID = Record[0]; |
| 1791 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 1792 | (const unsigned char *)BlobStart + Record[1], |
| 1793 | (const unsigned char *)BlobStart, |
| 1794 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 1795 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1796 | DeclContextInfo Info = { |
| 1797 | Table, /* No lexical inforamtion */ 0, 0 |
| 1798 | }; |
| 1799 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 1800 | } else |
| 1801 | PendingVisibleUpdates[ID].push_back(Table); |
| 1802 | break; |
| 1803 | } |
| 1804 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1805 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1806 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 1807 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1808 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1809 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 1810 | Latest > FirstLatestDeclIDs[First]) && |
| 1811 | "The new latest is supposed to come after the previous latest"); |
| 1812 | FirstLatestDeclIDs[First] = Latest; |
| 1813 | } |
| 1814 | break; |
| 1815 | } |
| 1816 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1817 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1818 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1819 | return IgnorePCH; |
| 1820 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1821 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1822 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1823 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1824 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1825 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1826 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1827 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 1828 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1829 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1830 | if (PP) |
| 1831 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1832 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1833 | break; |
| 1834 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1835 | case IDENTIFIER_OFFSET: |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1836 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1837 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1838 | return Failure; |
| 1839 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1840 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1841 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1842 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1843 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1844 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1845 | // Optimization for the first block. |
| 1846 | if (ExternalDefinitions.empty()) |
| 1847 | ExternalDefinitions.swap(Record); |
| 1848 | else |
| 1849 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 1850 | Record.begin(), Record.end()); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1851 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1852 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1853 | case SPECIAL_TYPES: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1854 | // Optimization for the first block |
| 1855 | if (SpecialTypes.empty()) |
| 1856 | SpecialTypes.swap(Record); |
| 1857 | else |
| 1858 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1859 | break; |
| 1860 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1861 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1862 | TotalNumStatements += Record[0]; |
| 1863 | TotalNumMacros += Record[1]; |
| 1864 | TotalLexicalDeclContexts += Record[2]; |
| 1865 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1866 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1867 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1868 | case TENTATIVE_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1869 | // Optimization for the first block. |
| 1870 | if (TentativeDefinitions.empty()) |
| 1871 | TentativeDefinitions.swap(Record); |
| 1872 | else |
| 1873 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 1874 | Record.begin(), Record.end()); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 1875 | break; |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1876 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1877 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1878 | // Optimization for the first block. |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 1879 | if (UnusedFileScopedDecls.empty()) |
| 1880 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1881 | else |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 1882 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 1883 | Record.begin(), Record.end()); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 1884 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1885 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1886 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 1887 | // Later blocks overwrite earlier ones. |
| 1888 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 1889 | break; |
| 1890 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1891 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1892 | // Optimization for the first block. |
| 1893 | if (LocallyScopedExternalDecls.empty()) |
| 1894 | LocallyScopedExternalDecls.swap(Record); |
| 1895 | else |
| 1896 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 1897 | Record.begin(), Record.end()); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1898 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1899 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1900 | case SELECTOR_OFFSETS: |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 1901 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1902 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1903 | break; |
| 1904 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1905 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1906 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1907 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1908 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1909 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1910 | F.SelectorLookupTableData + Record[0], |
| 1911 | F.SelectorLookupTableData, |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1912 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 1913 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1914 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1915 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 1916 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1917 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 1918 | break; |
| 1919 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1920 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1921 | if (!Record.empty() && Listener) |
| 1922 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1923 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1924 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1925 | case SOURCE_LOCATION_OFFSETS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1926 | F.SLocOffsets = (const uint32_t *)BlobStart; |
| 1927 | F.LocalNumSLocEntries = Record[0]; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 1928 | F.LocalSLocSize = Record[1]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1929 | break; |
| 1930 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1931 | case SOURCE_LOCATION_PRELOADS: |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 1932 | if (PreloadSLocEntries.empty()) |
| 1933 | PreloadSLocEntries.swap(Record); |
| 1934 | else |
| 1935 | PreloadSLocEntries.insert(PreloadSLocEntries.end(), |
| 1936 | Record.begin(), Record.end()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1937 | break; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1938 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1939 | case STAT_CACHE: { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1940 | ASTStatCache *MyStatCache = |
| 1941 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 1942 | (const unsigned char *)BlobStart, |
| 1943 | NumStatHits, NumStatMisses); |
| 1944 | FileMgr.addStatCache(MyStatCache); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1945 | F.StatCache = MyStatCache; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1946 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 1947 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1948 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1949 | case EXT_VECTOR_DECLS: |
Sebastian Redl | a9f2368 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 1950 | // Optimization for the first block. |
| 1951 | if (ExtVectorDecls.empty()) |
| 1952 | ExtVectorDecls.swap(Record); |
| 1953 | else |
| 1954 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 1955 | Record.begin(), Record.end()); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 1956 | break; |
| 1957 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1958 | case VTABLE_USES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 1959 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 1960 | VTableUses.swap(Record); |
| 1961 | break; |
| 1962 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1963 | case DYNAMIC_CLASSES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 1964 | // Optimization for the first block. |
| 1965 | if (DynamicClasses.empty()) |
| 1966 | DynamicClasses.swap(Record); |
| 1967 | else |
| 1968 | DynamicClasses.insert(DynamicClasses.end(), |
| 1969 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 1970 | break; |
| 1971 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1972 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1973 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 1974 | break; |
| 1975 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1976 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 1977 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 1978 | SemaDeclRefs.swap(Record); |
| 1979 | break; |
| 1980 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1981 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1982 | // The primary AST will be the last to get here, so it will be the one |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1983 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 1984 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 1985 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1986 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1987 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1988 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1989 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 1990 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1991 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 1992 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 1993 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 1994 | return IgnorePCH; |
| 1995 | } |
| 1996 | break; |
| 1997 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 1998 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1999 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2000 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2001 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2002 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2003 | break; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2004 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2005 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2006 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2007 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2008 | return Failure; |
| 2009 | } |
| 2010 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2011 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2012 | std::make_pair(&F, Record[I+1]); |
| 2013 | break; |
| 2014 | } |
Sebastian Redl | 6e50e00 | 2010-08-24 22:50:19 +0000 | [diff] [blame] | 2015 | |
| 2016 | case ADDITIONAL_TEMPLATE_SPECIALIZATIONS: { |
| 2017 | AdditionalTemplateSpecializations &ATS = |
| 2018 | AdditionalTemplateSpecializationsPending[Record[0]]; |
| 2019 | ATS.insert(ATS.end(), Record.begin()+1, Record.end()); |
| 2020 | break; |
| 2021 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2022 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2023 | First = false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2024 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2025 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2026 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2029 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2030 | ASTFileType Type) { |
| 2031 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2032 | case Failure: return Failure; |
| 2033 | case IgnorePCH: return IgnorePCH; |
| 2034 | case Success: break; |
| 2035 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2036 | |
| 2037 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2038 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2039 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2040 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2041 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2042 | TotalNumSelectors = 0; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2043 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2044 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2045 | NextSLocOffset += Chain[I]->LocalSLocSize; |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2046 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2047 | TotalNumTypes += Chain[I]->LocalNumTypes; |
| 2048 | TotalNumDecls += Chain[I]->LocalNumDecls; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2049 | TotalNumPreallocatedPreprocessingEntities += |
| 2050 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2051 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2052 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2053 | } |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2054 | SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset); |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2055 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2056 | TypesLoaded.resize(TotalNumTypes); |
| 2057 | DeclsLoaded.resize(TotalNumDecls); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2058 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2059 | if (PP) { |
| 2060 | if (TotalNumIdentifiers > 0) |
| 2061 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2062 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2063 | if (!PP->getPreprocessingRecord()) |
| 2064 | PP->createPreprocessingRecord(); |
| 2065 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2066 | TotalNumPreallocatedPreprocessingEntities); |
| 2067 | } |
| 2068 | } |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2069 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2070 | // Preload SLocEntries. |
| 2071 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2072 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2073 | if (Result != Success) |
| 2074 | return Result; |
| 2075 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2076 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2077 | // Check the predefines buffers. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2078 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2079 | return IgnorePCH; |
| 2080 | |
| 2081 | if (PP) { |
| 2082 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2083 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2084 | // loaded into the IdentifierTable before we intercepted the |
| 2085 | // creation of identifiers. Iterate through the list of known |
| 2086 | // identifiers and determine whether we have to establish |
| 2087 | // preprocessor definitions or top-level identifier declaration |
| 2088 | // chains for those identifiers. |
| 2089 | // |
| 2090 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2091 | // since de-serializing declarations or macro definitions can add |
| 2092 | // new entries into the identifier table, invalidating the |
| 2093 | // iterators. |
| 2094 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2095 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2096 | IdEnd = PP->getIdentifierTable().end(); |
| 2097 | Id != IdEnd; ++Id) |
| 2098 | Identifiers.push_back(Id->second); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2099 | // We need to search the tables in all files. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2100 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2101 | ASTIdentifierLookupTable *IdTable |
| 2102 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2103 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2104 | // ones. |
| 2105 | if (!IdTable) |
| 2106 | continue; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2107 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2108 | IdentifierInfo *II = Identifiers[I]; |
| 2109 | // Look in the on-disk hash tables for an entry for this identifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2110 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2111 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2112 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2113 | if (Pos == IdTable->end()) |
| 2114 | continue; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2115 | |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2116 | // Dereferencing the iterator has the effect of populating the |
| 2117 | // IdentifierInfo node with the various declarations it needs. |
| 2118 | (void)*Pos; |
| 2119 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2120 | } |
| 2121 | } |
| 2122 | |
| 2123 | if (Context) |
| 2124 | InitializeContext(*Context); |
| 2125 | |
| 2126 | return Success; |
| 2127 | } |
| 2128 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2129 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2130 | ASTFileType Type) { |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2131 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2132 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2133 | PerFileData &F = *Chain.back(); |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2134 | if (Prev) |
| 2135 | Prev->NextInSource = &F; |
| 2136 | else |
| 2137 | FirstInSource = &F; |
| 2138 | F.Loaders.push_back(Prev); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2139 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2140 | // Set the AST file name. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2141 | F.FileName = FileName; |
| 2142 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2143 | // Open the AST file. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2144 | // |
| 2145 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2146 | std::string ErrStr; |
| 2147 | F.Buffer.reset(llvm::MemoryBuffer::getFileOrSTDIN(FileName, &ErrStr)); |
| 2148 | if (!F.Buffer) { |
| 2149 | Error(ErrStr.c_str()); |
| 2150 | return IgnorePCH; |
| 2151 | } |
| 2152 | |
| 2153 | // Initialize the stream |
| 2154 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2155 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2156 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2157 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2158 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2159 | |
| 2160 | // Sniff for the signature. |
| 2161 | if (Stream.Read(8) != 'C' || |
| 2162 | Stream.Read(8) != 'P' || |
| 2163 | Stream.Read(8) != 'C' || |
| 2164 | Stream.Read(8) != 'H') { |
| 2165 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2166 | return Failure; |
| 2167 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2168 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2169 | while (!Stream.AtEndOfStream()) { |
| 2170 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2171 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2172 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2173 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2174 | return Failure; |
| 2175 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2176 | |
| 2177 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2178 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2179 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2180 | switch (BlockID) { |
| 2181 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2182 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2183 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2184 | return Failure; |
| 2185 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2186 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2187 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2188 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2189 | case Success: |
| 2190 | break; |
| 2191 | |
| 2192 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2193 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2194 | |
| 2195 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2196 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2197 | // AST block, skipping subblocks, to see if there are other |
| 2198 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2199 | |
| 2200 | // Clear out any preallocated source location entries, so that |
| 2201 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2202 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2203 | |
| 2204 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2205 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2206 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2207 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2208 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2209 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2210 | break; |
| 2211 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2212 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2213 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2214 | return Failure; |
| 2215 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2216 | break; |
| 2217 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2218 | } |
| 2219 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2220 | return Success; |
| 2221 | } |
| 2222 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2223 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2224 | PP = &pp; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2225 | |
| 2226 | unsigned TotalNum = 0; |
| 2227 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2228 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2229 | if (TotalNum) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2230 | if (!PP->getPreprocessingRecord()) |
| 2231 | PP->createPreprocessingRecord(); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2232 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2233 | } |
| 2234 | } |
| 2235 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2236 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2237 | Context = &Ctx; |
| 2238 | assert(Context && "Passed null context!"); |
| 2239 | |
| 2240 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2241 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2242 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2243 | PP->setExternalSource(this); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2244 | |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2245 | // If we have an update block for the TU waiting, we have to add it before |
| 2246 | // deserializing the decl. |
| 2247 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2248 | if (DCU != DeclContextOffsets.end()) { |
| 2249 | // Insertion could invalidate map, so grab vector. |
| 2250 | DeclContextInfos T; |
| 2251 | T.swap(DCU->second); |
| 2252 | DeclContextOffsets.erase(DCU); |
| 2253 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2254 | } |
| 2255 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2256 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2257 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2258 | |
| 2259 | // Load the special types. |
| 2260 | Context->setBuiltinVaListType( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2261 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2262 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2263 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2264 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2265 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2266 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2267 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2268 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2269 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2270 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2271 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2272 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2273 | if (unsigned FastEnum |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2274 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2275 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2276 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2277 | QualType FileType = GetType(File); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2278 | if (FileType.isNull()) { |
| 2279 | Error("FILE type is NULL"); |
| 2280 | return; |
| 2281 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2282 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2283 | Context->setFILEDecl(Typedef->getDecl()); |
| 2284 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2285 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2286 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2287 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2288 | return; |
| 2289 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2290 | Context->setFILEDecl(Tag->getDecl()); |
| 2291 | } |
| 2292 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2293 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2294 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2295 | if (Jmp_bufType.isNull()) { |
| 2296 | Error("jmp_bug type is NULL"); |
| 2297 | return; |
| 2298 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2299 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2300 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2301 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2302 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2303 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2304 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2305 | return; |
| 2306 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2307 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2308 | } |
| 2309 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2310 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2311 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2312 | if (Sigjmp_bufType.isNull()) { |
| 2313 | Error("sigjmp_buf type is NULL"); |
| 2314 | return; |
| 2315 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2316 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2317 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2318 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2319 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2320 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2321 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2322 | } |
| 2323 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2324 | if (unsigned ObjCIdRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2325 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2326 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2327 | if (unsigned ObjCClassRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2328 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2329 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2330 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2331 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2332 | if (unsigned String |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2333 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2334 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2335 | if (unsigned ObjCSelRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2336 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2337 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2338 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2339 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2340 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2341 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2342 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2343 | } |
| 2344 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2345 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2346 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2347 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2348 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2349 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2350 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2351 | std::string ErrStr; |
| 2352 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2353 | Buffer.reset(llvm::MemoryBuffer::getFile(ASTFileName.c_str(), &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2354 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2355 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2356 | return std::string(); |
| 2357 | } |
| 2358 | |
| 2359 | // Initialize the stream |
| 2360 | llvm::BitstreamReader StreamFile; |
| 2361 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2362 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2363 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2364 | Stream.init(StreamFile); |
| 2365 | |
| 2366 | // Sniff for the signature. |
| 2367 | if (Stream.Read(8) != 'C' || |
| 2368 | Stream.Read(8) != 'P' || |
| 2369 | Stream.Read(8) != 'C' || |
| 2370 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2371 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2372 | return std::string(); |
| 2373 | } |
| 2374 | |
| 2375 | RecordData Record; |
| 2376 | while (!Stream.AtEndOfStream()) { |
| 2377 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2378 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2379 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2380 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2381 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2382 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2383 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2384 | case AST_BLOCK_ID: |
| 2385 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2386 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2387 | return std::string(); |
| 2388 | } |
| 2389 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2390 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2391 | default: |
| 2392 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2393 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2394 | return std::string(); |
| 2395 | } |
| 2396 | break; |
| 2397 | } |
| 2398 | continue; |
| 2399 | } |
| 2400 | |
| 2401 | if (Code == llvm::bitc::END_BLOCK) { |
| 2402 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2403 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2404 | return std::string(); |
| 2405 | } |
| 2406 | continue; |
| 2407 | } |
| 2408 | |
| 2409 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2410 | Stream.ReadAbbrevRecord(); |
| 2411 | continue; |
| 2412 | } |
| 2413 | |
| 2414 | Record.clear(); |
| 2415 | const char *BlobStart = 0; |
| 2416 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2417 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2418 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2419 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2420 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2421 | |
| 2422 | return std::string(); |
| 2423 | } |
| 2424 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2425 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2426 | /// structure. |
| 2427 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2428 | /// This routine parses the language options from the AST file and then gives |
| 2429 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2430 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2431 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2432 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2433 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2434 | if (Listener) { |
| 2435 | LangOptions LangOpts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2436 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2437 | #define PARSE_LANGOPT(Option) \ |
| 2438 | LangOpts.Option = Record[Idx]; \ |
| 2439 | ++Idx |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2440 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2441 | unsigned Idx = 0; |
| 2442 | PARSE_LANGOPT(Trigraphs); |
| 2443 | PARSE_LANGOPT(BCPLComment); |
| 2444 | PARSE_LANGOPT(DollarIdents); |
| 2445 | PARSE_LANGOPT(AsmPreprocessor); |
| 2446 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2447 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2448 | PARSE_LANGOPT(ImplicitInt); |
| 2449 | PARSE_LANGOPT(Digraphs); |
| 2450 | PARSE_LANGOPT(HexFloats); |
| 2451 | PARSE_LANGOPT(C99); |
| 2452 | PARSE_LANGOPT(Microsoft); |
| 2453 | PARSE_LANGOPT(CPlusPlus); |
| 2454 | PARSE_LANGOPT(CPlusPlus0x); |
| 2455 | PARSE_LANGOPT(CXXOperatorNames); |
| 2456 | PARSE_LANGOPT(ObjC1); |
| 2457 | PARSE_LANGOPT(ObjC2); |
| 2458 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 2459 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 2460 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2461 | PARSE_LANGOPT(PascalStrings); |
| 2462 | PARSE_LANGOPT(WritableStrings); |
| 2463 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2464 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2465 | PARSE_LANGOPT(Exceptions); |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 2466 | PARSE_LANGOPT(SjLjExceptions); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2467 | PARSE_LANGOPT(NeXTRuntime); |
| 2468 | PARSE_LANGOPT(Freestanding); |
| 2469 | PARSE_LANGOPT(NoBuiltin); |
| 2470 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 2471 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2472 | PARSE_LANGOPT(Blocks); |
| 2473 | PARSE_LANGOPT(EmitAllDecls); |
| 2474 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2475 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 2476 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2477 | PARSE_LANGOPT(HeinousExtensions); |
| 2478 | PARSE_LANGOPT(Optimize); |
| 2479 | PARSE_LANGOPT(OptimizeSize); |
| 2480 | PARSE_LANGOPT(Static); |
| 2481 | PARSE_LANGOPT(PICLevel); |
| 2482 | PARSE_LANGOPT(GNUInline); |
| 2483 | PARSE_LANGOPT(NoInline); |
| 2484 | PARSE_LANGOPT(AccessControl); |
| 2485 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2486 | PARSE_LANGOPT(ShortWChar); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2487 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
| 2488 | LangOpts.setVisibilityMode((LangOptions::VisibilityMode)Record[Idx++]); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 2489 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2490 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2491 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2492 | PARSE_LANGOPT(OpenCL); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2493 | PARSE_LANGOPT(CatchUndefined); |
| 2494 | // FIXME: Missing ElideConstructors?! |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2495 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2496 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2497 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2498 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2499 | |
| 2500 | return false; |
| 2501 | } |
| 2502 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2503 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2504 | ReadDefinedMacros(); |
| 2505 | } |
| 2506 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2507 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2508 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2509 | PerFileData *F = 0; |
| 2510 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2511 | F = Chain[N - I - 1]; |
| 2512 | if (Index < F->LocalNumTypes) |
| 2513 | break; |
| 2514 | Index -= F->LocalNumTypes; |
| 2515 | } |
| 2516 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2517 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2521 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2522 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 2523 | /// routine actually reads the record corresponding to the type at the given |
| 2524 | /// location. It is a helper routine for GetType, which deals with reading type |
| 2525 | /// IDs. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2526 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2527 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2528 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2529 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2530 | // Keep track of where we are in the stream, then jump back there |
| 2531 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2532 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2533 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 2534 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 2535 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2536 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 2537 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2538 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2539 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2540 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2541 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2542 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 2543 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2544 | if (Record.size() != 2) { |
| 2545 | Error("Incorrect encoding of extended qualifier type"); |
| 2546 | return QualType(); |
| 2547 | } |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2548 | QualType Base = GetType(Record[0]); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2549 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 2550 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2551 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2552 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2553 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2554 | if (Record.size() != 1) { |
| 2555 | Error("Incorrect encoding of complex type"); |
| 2556 | return QualType(); |
| 2557 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2558 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2559 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2560 | } |
| 2561 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2562 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2563 | if (Record.size() != 1) { |
| 2564 | Error("Incorrect encoding of pointer type"); |
| 2565 | return QualType(); |
| 2566 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2567 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2568 | return Context->getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2569 | } |
| 2570 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2571 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2572 | if (Record.size() != 1) { |
| 2573 | Error("Incorrect encoding of block pointer type"); |
| 2574 | return QualType(); |
| 2575 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2576 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2577 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2578 | } |
| 2579 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2580 | case TYPE_LVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2581 | if (Record.size() != 1) { |
| 2582 | Error("Incorrect encoding of lvalue reference type"); |
| 2583 | return QualType(); |
| 2584 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2585 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2586 | return Context->getLValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2589 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2590 | if (Record.size() != 1) { |
| 2591 | Error("Incorrect encoding of rvalue reference type"); |
| 2592 | return QualType(); |
| 2593 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2594 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2595 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2596 | } |
| 2597 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2598 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 2599 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2600 | Error("Incorrect encoding of member pointer type"); |
| 2601 | return QualType(); |
| 2602 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2603 | QualType PointeeType = GetType(Record[0]); |
| 2604 | QualType ClassType = GetType(Record[1]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2605 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2606 | } |
| 2607 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2608 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2609 | QualType ElementType = GetType(Record[0]); |
| 2610 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2611 | unsigned IndexTypeQuals = Record[2]; |
| 2612 | unsigned Idx = 3; |
| 2613 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 2614 | return Context->getConstantArrayType(ElementType, Size, |
| 2615 | ASM, IndexTypeQuals); |
| 2616 | } |
| 2617 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2618 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2619 | QualType ElementType = GetType(Record[0]); |
| 2620 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2621 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2622 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2625 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2626 | QualType ElementType = GetType(Record[0]); |
| 2627 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2628 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2629 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 2630 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 2631 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 2632 | ASM, IndexTypeQuals, |
| 2633 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2634 | } |
| 2635 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2636 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2637 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2638 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2639 | return QualType(); |
| 2640 | } |
| 2641 | |
| 2642 | QualType ElementType = GetType(Record[0]); |
| 2643 | unsigned NumElements = Record[1]; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2644 | unsigned AltiVecSpec = Record[2]; |
| 2645 | return Context->getVectorType(ElementType, NumElements, |
| 2646 | (VectorType::AltiVecSpecific)AltiVecSpec); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2647 | } |
| 2648 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2649 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2650 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2651 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2652 | return QualType(); |
| 2653 | } |
| 2654 | |
| 2655 | QualType ElementType = GetType(Record[0]); |
| 2656 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2657 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2658 | } |
| 2659 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2660 | case TYPE_FUNCTION_NO_PROTO: { |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2661 | if (Record.size() != 4) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 2662 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2663 | return QualType(); |
| 2664 | } |
| 2665 | QualType ResultType = GetType(Record[0]); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2666 | FunctionType::ExtInfo Info(Record[1], Record[2], (CallingConv)Record[3]); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 2667 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2668 | } |
| 2669 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2670 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2671 | QualType ResultType = GetType(Record[0]); |
Douglas Gregor | 9123666 | 2009-12-22 18:11:50 +0000 | [diff] [blame] | 2672 | bool NoReturn = Record[1]; |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2673 | unsigned RegParm = Record[2]; |
| 2674 | CallingConv CallConv = (CallingConv)Record[3]; |
| 2675 | unsigned Idx = 4; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2676 | unsigned NumParams = Record[Idx++]; |
| 2677 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 2678 | for (unsigned I = 0; I != NumParams; ++I) |
| 2679 | ParamTypes.push_back(GetType(Record[Idx++])); |
| 2680 | bool isVariadic = Record[Idx++]; |
| 2681 | unsigned Quals = Record[Idx++]; |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 2682 | bool hasExceptionSpec = Record[Idx++]; |
| 2683 | bool hasAnyExceptionSpec = Record[Idx++]; |
| 2684 | unsigned NumExceptions = Record[Idx++]; |
| 2685 | llvm::SmallVector<QualType, 2> Exceptions; |
| 2686 | for (unsigned I = 0; I != NumExceptions; ++I) |
| 2687 | Exceptions.push_back(GetType(Record[Idx++])); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 2688 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 2689 | isVariadic, Quals, hasExceptionSpec, |
| 2690 | hasAnyExceptionSpec, NumExceptions, |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 2691 | Exceptions.data(), |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2692 | FunctionType::ExtInfo(NoReturn, RegParm, |
| 2693 | CallConv)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2694 | } |
| 2695 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2696 | case TYPE_UNRESOLVED_USING: |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2697 | return Context->getTypeDeclType( |
| 2698 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 2699 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2700 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2701 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2702 | Error("incorrect encoding of typedef type"); |
| 2703 | return QualType(); |
| 2704 | } |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2705 | TypedefDecl *Decl = cast<TypedefDecl>(GetDecl(Record[0])); |
| 2706 | QualType Canonical = GetType(Record[1]); |
| 2707 | return Context->getTypedefType(Decl, Canonical); |
| 2708 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2709 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2710 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2711 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2712 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2713 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2714 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2715 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2716 | return QualType(); |
| 2717 | } |
| 2718 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2719 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2720 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2721 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2722 | case TYPE_DECLTYPE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2723 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 2724 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2725 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2726 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2727 | Error("incorrect encoding of record type"); |
| 2728 | return QualType(); |
| 2729 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2730 | bool IsDependent = Record[0]; |
| 2731 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
| 2732 | T->Dependent = IsDependent; |
| 2733 | return T; |
| 2734 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2735 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2736 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2737 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2738 | Error("incorrect encoding of enum type"); |
| 2739 | return QualType(); |
| 2740 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2741 | bool IsDependent = Record[0]; |
| 2742 | QualType T = Context->getEnumType(cast<EnumDecl>(GetDecl(Record[1]))); |
| 2743 | T->Dependent = IsDependent; |
| 2744 | return T; |
| 2745 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2746 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2747 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 2748 | unsigned Idx = 0; |
| 2749 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 2750 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 2751 | QualType NamedType = GetType(Record[Idx++]); |
| 2752 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2755 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2756 | unsigned Idx = 0; |
| 2757 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2758 | return Context->getObjCInterfaceType(ItfD); |
| 2759 | } |
| 2760 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2761 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2762 | unsigned Idx = 0; |
| 2763 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2764 | unsigned NumProtos = Record[Idx++]; |
| 2765 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 2766 | for (unsigned I = 0; I != NumProtos; ++I) |
| 2767 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2768 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2769 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2770 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2771 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 2772 | unsigned Idx = 0; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2773 | QualType Pointee = GetType(Record[Idx++]); |
| 2774 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 2775 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2776 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2777 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2778 | unsigned Idx = 0; |
| 2779 | QualType Parm = GetType(Record[Idx++]); |
| 2780 | QualType Replacement = GetType(Record[Idx++]); |
| 2781 | return |
| 2782 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 2783 | Replacement); |
| 2784 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2785 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2786 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2787 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 2788 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 2789 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2790 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 2791 | return |
| 2792 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2793 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 2794 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2795 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2796 | unsigned Idx = 0; |
| 2797 | unsigned Depth = Record[Idx++]; |
| 2798 | unsigned Index = Record[Idx++]; |
| 2799 | bool Pack = Record[Idx++]; |
| 2800 | IdentifierInfo *Name = GetIdentifierInfo(Record, Idx); |
| 2801 | return Context->getTemplateTypeParmType(Depth, Index, Pack, Name); |
| 2802 | } |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 2803 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2804 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 2805 | unsigned Idx = 0; |
| 2806 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 2807 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 2808 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 2809 | QualType Canon = GetType(Record[Idx++]); |
| 2810 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 2811 | } |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 2812 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2813 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 2814 | unsigned Idx = 0; |
| 2815 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 2816 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 2817 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
| 2818 | unsigned NumArgs = Record[Idx++]; |
| 2819 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 2820 | Args.reserve(NumArgs); |
| 2821 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2822 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 2823 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 2824 | Args.size(), Args.data()); |
| 2825 | } |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 2826 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2827 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 2828 | unsigned Idx = 0; |
| 2829 | |
| 2830 | // ArrayType |
| 2831 | QualType ElementType = GetType(Record[Idx++]); |
| 2832 | ArrayType::ArraySizeModifier ASM |
| 2833 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 2834 | unsigned IndexTypeQuals = Record[Idx++]; |
| 2835 | |
| 2836 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2837 | Expr *NumElts = ReadExpr(*Loc.F); |
| 2838 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 2839 | |
| 2840 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 2841 | IndexTypeQuals, Brackets); |
| 2842 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 2843 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2844 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2845 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2846 | bool IsDependent = Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2847 | TemplateName Name = ReadTemplateName(Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2848 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2849 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2850 | QualType Canon = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2851 | QualType T; |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2852 | if (Canon.isNull()) |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2853 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 2854 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2855 | else |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2856 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
| 2857 | Args.size(), Canon); |
| 2858 | T->Dependent = IsDependent; |
| 2859 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2860 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2861 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2862 | // Suppress a GCC warning |
| 2863 | return QualType(); |
| 2864 | } |
| 2865 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2866 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2867 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2868 | ASTReader::PerFileData &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 2869 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2870 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2871 | unsigned &Idx; |
| 2872 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2873 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 2874 | unsigned &I) { |
| 2875 | return Reader.ReadSourceLocation(F, R, I); |
| 2876 | } |
| 2877 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2878 | public: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2879 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2880 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2881 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 2882 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2883 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2884 | // We want compile-time assurance that we've enumerated all of |
| 2885 | // these, so unfortunately we have to declare them first, then |
| 2886 | // define them out-of-line. |
| 2887 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2888 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2889 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2890 | #include "clang/AST/TypeLocNodes.def" |
| 2891 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2892 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 2893 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2894 | }; |
| 2895 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2896 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2897 | // nothing to do |
| 2898 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2899 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2900 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2901 | if (TL.needsExtraLocalData()) { |
| 2902 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 2903 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 2904 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 2905 | TL.setModeAttr(Record[Idx++]); |
| 2906 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2907 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2908 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2909 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2910 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2911 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2912 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2913 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2914 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2915 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2916 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2917 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2918 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2919 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2920 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2921 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2922 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2923 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2924 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2925 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2926 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2927 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 2928 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2929 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2930 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2931 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2932 | TL.setSizeExpr(0); |
| 2933 | } |
| 2934 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 2935 | VisitArrayTypeLoc(TL); |
| 2936 | } |
| 2937 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 2938 | VisitArrayTypeLoc(TL); |
| 2939 | } |
| 2940 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 2941 | VisitArrayTypeLoc(TL); |
| 2942 | } |
| 2943 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 2944 | DependentSizedArrayTypeLoc TL) { |
| 2945 | VisitArrayTypeLoc(TL); |
| 2946 | } |
| 2947 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 2948 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2949 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2950 | } |
| 2951 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2952 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2953 | } |
| 2954 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2955 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2956 | } |
| 2957 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2958 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 2959 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 2960 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2961 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | 86acc2a | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 2962 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2963 | } |
| 2964 | } |
| 2965 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 2966 | VisitFunctionTypeLoc(TL); |
| 2967 | } |
| 2968 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 2969 | VisitFunctionTypeLoc(TL); |
| 2970 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2971 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2972 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2973 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2974 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2975 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2976 | } |
| 2977 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2978 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 2979 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 2980 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2981 | } |
| 2982 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2983 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 2984 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 2985 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 2986 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2987 | } |
| 2988 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2989 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2990 | } |
| 2991 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2992 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2993 | } |
| 2994 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2995 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2996 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2997 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2998 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2999 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3000 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3001 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3002 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3003 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3004 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3005 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3006 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3007 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3008 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3009 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3010 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3011 | Reader.GetTemplateArgumentLocInfo(F, |
| 3012 | TL.getTypePtr()->getArg(i).getKind(), |
| 3013 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3014 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3015 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3016 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3017 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3018 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3019 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3020 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3021 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3022 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3023 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3024 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3025 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3026 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3027 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3028 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3029 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3030 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3031 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3032 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3033 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3034 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3035 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3036 | Reader.GetTemplateArgumentLocInfo(F, |
| 3037 | TL.getTypePtr()->getArg(I).getKind(), |
| 3038 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3039 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3040 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3041 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3042 | } |
| 3043 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3044 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3045 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3046 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3047 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3048 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3049 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3050 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3051 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3052 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3053 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3054 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3055 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3056 | unsigned &Idx) { |
| 3057 | QualType InfoTy = GetType(Record[Idx++]); |
| 3058 | if (InfoTy.isNull()) |
| 3059 | return 0; |
| 3060 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3061 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3062 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3063 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3064 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3065 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3066 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3067 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3068 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3069 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3070 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3071 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3072 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3073 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3074 | switch ((PredefinedTypeIDs)Index) { |
| 3075 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3076 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3077 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3078 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3079 | case PREDEF_TYPE_CHAR_U_ID: |
| 3080 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3081 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3082 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3083 | break; |
| 3084 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3085 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3086 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3087 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3088 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3089 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3090 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3091 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3092 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3093 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3094 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3095 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3096 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3097 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3098 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3099 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3100 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3101 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
| 3102 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
| 3103 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3104 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3105 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3106 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3107 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3108 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3112 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3113 | } |
| 3114 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3115 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3116 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3117 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3118 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3119 | if (TypesLoaded[Index].isNull()) |
| 3120 | return QualType(); |
| 3121 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3122 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3123 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3124 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3125 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3126 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3127 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3128 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3129 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3130 | } |
| 3131 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3132 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3133 | return MakeTypeID(T, |
| 3134 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3135 | } |
| 3136 | |
| 3137 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3138 | if (T.isNull()) |
| 3139 | return TypeIdx(); |
| 3140 | assert(!T.getLocalFastQualifiers()); |
| 3141 | |
| 3142 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3143 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3144 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3145 | // If the type didn't come from the AST file use a specially marked index |
| 3146 | // so that any hash/key comparison fail since no such index is stored |
| 3147 | // in a AST file. |
| 3148 | if (I == TypeIdxs.end()) |
| 3149 | return TypeIdx(-1); |
| 3150 | return I->second; |
| 3151 | } |
| 3152 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3153 | TemplateArgumentLocInfo |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3154 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3155 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3156 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3157 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3158 | switch (Kind) { |
| 3159 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3160 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3161 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3162 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3163 | case TemplateArgument::Template: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3164 | SourceRange QualifierRange = ReadSourceRange(F, Record, Index); |
| 3165 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3166 | return TemplateArgumentLocInfo(QualifierRange, TemplateNameLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3167 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3168 | case TemplateArgument::Null: |
| 3169 | case TemplateArgument::Integral: |
| 3170 | case TemplateArgument::Declaration: |
| 3171 | case TemplateArgument::Pack: |
| 3172 | return TemplateArgumentLocInfo(); |
| 3173 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3174 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3175 | return TemplateArgumentLocInfo(); |
| 3176 | } |
| 3177 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3178 | TemplateArgumentLoc |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3179 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3180 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3181 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3182 | |
| 3183 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3184 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3185 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3186 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3187 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3188 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3189 | } |
| 3190 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3191 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3192 | return GetDecl(ID); |
| 3193 | } |
| 3194 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3195 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3196 | if (!DeclsLoaded[0]) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 3197 | ReadDeclRecord(0, 1); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3198 | if (DeserializationListener) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3199 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3200 | } |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 3201 | |
| 3202 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 3203 | } |
| 3204 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3205 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3206 | if (ID == 0) |
| 3207 | return 0; |
| 3208 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3209 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3210 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3211 | return 0; |
| 3212 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3213 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3214 | unsigned Index = ID - 1; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3215 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3216 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3217 | if (DeserializationListener) |
| 3218 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3219 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3220 | |
| 3221 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3222 | } |
| 3223 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3224 | /// \brief Resolve the offset of a statement into a statement. |
| 3225 | /// |
| 3226 | /// This operation will read a new statement from the external |
| 3227 | /// source each time it is called, and is meant to be used via a |
| 3228 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3229 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3230 | // Offset here is a global offset across the entire chain. |
| 3231 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3232 | PerFileData &F = *Chain[N - I - 1]; |
| 3233 | if (Offset < F.SizeInBits) { |
| 3234 | // Since we know that this statement is part of a decl, make sure to use |
| 3235 | // the decl cursor to read it. |
| 3236 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3237 | return ReadStmtFromStream(F); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3238 | } |
| 3239 | Offset -= F.SizeInBits; |
| 3240 | } |
| 3241 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 3242 | } |
| 3243 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3244 | bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame^] | 3245 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3246 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3247 | assert(DC->hasExternalLexicalStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3248 | "DeclContext has no lexical decls in storage"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3249 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3250 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 3251 | // at least. |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3252 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 3253 | // so make a copy of the vector. |
| 3254 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3255 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3256 | I != E; ++I) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3257 | // IDs can be 0 if this context doesn't contain declarations. |
| 3258 | if (!I->LexicalDecls) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3259 | continue; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3260 | |
| 3261 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame^] | 3262 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 3263 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 3264 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 3265 | continue; |
| 3266 | |
| 3267 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3268 | assert(D && "Null decl in lexical decls"); |
| 3269 | Decls.push_back(D); |
| 3270 | } |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3271 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3272 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3273 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3274 | return false; |
| 3275 | } |
| 3276 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3277 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3278 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3279 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3280 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3281 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3282 | if (!Name) |
| 3283 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 3284 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3285 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3286 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 8b12273 | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 3287 | // There might be visible decls in multiple parts of the chain, for the TU |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3288 | // and namespaces. For any given name, the last available results replace |
| 3289 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3290 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3291 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3292 | I != E; ++I) { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3293 | if (!I->NameLookupTableData) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3294 | continue; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3295 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3296 | ASTDeclContextNameLookupTable *LookupTable = |
| 3297 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3298 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 3299 | if (Pos == LookupTable->end()) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3300 | continue; |
| 3301 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3302 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 3303 | for (; Data.first != Data.second; ++Data.first) |
| 3304 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3305 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3306 | } |
| 3307 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3308 | ++NumVisibleDeclContextsRead; |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3309 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3310 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3311 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3312 | } |
| 3313 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 3314 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 3315 | assert(DC->hasExternalVisibleStorage() && |
| 3316 | "DeclContext has no visible decls in storage"); |
| 3317 | |
| 3318 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 3319 | // There might be visible decls in multiple parts of the chain, for the TU |
| 3320 | // and namespaces. |
| 3321 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 3322 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3323 | I != E; ++I) { |
| 3324 | if (!I->NameLookupTableData) |
| 3325 | continue; |
| 3326 | |
| 3327 | ASTDeclContextNameLookupTable *LookupTable = |
| 3328 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3329 | for (ASTDeclContextNameLookupTable::item_iterator |
| 3330 | ItemI = LookupTable->item_begin(), |
| 3331 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 3332 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 3333 | = *ItemI; |
| 3334 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 3335 | Decls.clear(); |
| 3336 | for (; Data.first != Data.second; ++Data.first) |
| 3337 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 3338 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 3339 | } |
| 3340 | } |
| 3341 | } |
| 3342 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3343 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3344 | assert(Consumer); |
| 3345 | while (!InterestingDecls.empty()) { |
| 3346 | DeclGroupRef DG(InterestingDecls.front()); |
| 3347 | InterestingDecls.pop_front(); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3348 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3349 | } |
| 3350 | } |
| 3351 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3352 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 3353 | this->Consumer = Consumer; |
| 3354 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3355 | if (!Consumer) |
| 3356 | return; |
| 3357 | |
| 3358 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3359 | // Force deserialization of this decl, which will cause it to be queued for |
| 3360 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 3361 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3362 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 3363 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3364 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3365 | } |
| 3366 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3367 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3368 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3369 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3370 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3371 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3372 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3373 | unsigned NumDeclsLoaded |
| 3374 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 3375 | (Decl *)0); |
| 3376 | unsigned NumIdentifiersLoaded |
| 3377 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 3378 | IdentifiersLoaded.end(), |
| 3379 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3380 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3381 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 3382 | SelectorsLoaded.end(), |
| 3383 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 3384 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3385 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 3386 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 3387 | if (TotalNumSLocEntries) |
| 3388 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 3389 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 3390 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3391 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3392 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3393 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 3394 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 3395 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3396 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3397 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 3398 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3399 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3400 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3401 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 3402 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3403 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3404 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3405 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 3406 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3407 | if (TotalNumStatements) |
| 3408 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 3409 | NumStatementsRead, TotalNumStatements, |
| 3410 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 3411 | if (TotalNumMacros) |
| 3412 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 3413 | NumMacrosRead, TotalNumMacros, |
| 3414 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 3415 | if (TotalLexicalDeclContexts) |
| 3416 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 3417 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 3418 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 3419 | * 100)); |
| 3420 | if (TotalVisibleDeclContexts) |
| 3421 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 3422 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 3423 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 3424 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3425 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3426 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3427 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 3428 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3429 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3430 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3431 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3432 | std::fprintf(stderr, "\n"); |
| 3433 | } |
| 3434 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3435 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3436 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3437 | S.ExternalSource = this; |
| 3438 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 3439 | // Makes sure any declarations that were deserialized "too early" |
| 3440 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3441 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 3442 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 3443 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3444 | |
| 3445 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3446 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 3447 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3448 | |
| 3449 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 3450 | // them to Sema's list of tentative definitions. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3451 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 3452 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 3453 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3454 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 3455 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3456 | // If there were any unused file scoped decls, deserialize them and add to |
| 3457 | // Sema's list of unused file scoped decls. |
| 3458 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 3459 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 3460 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 3461 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3462 | |
| 3463 | // If there were any locally-scoped external declarations, |
| 3464 | // deserialize them and add them to Sema's table of locally-scoped |
| 3465 | // external declarations. |
| 3466 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 3467 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 3468 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 3469 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3470 | |
| 3471 | // If there were any ext_vector type declarations, deserialize them |
| 3472 | // and add them to Sema's vector of such declarations. |
| 3473 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 3474 | SemaObj->ExtVectorDecls.push_back( |
| 3475 | cast<TypedefDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3476 | |
| 3477 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 3478 | // Can we cut them down before writing them ? |
| 3479 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3480 | // If there were any dynamic classes declarations, deserialize them |
| 3481 | // and add them to Sema's vector of such declarations. |
| 3482 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 3483 | SemaObj->DynamicClasses.push_back( |
| 3484 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3485 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3486 | // Load the offsets of the declarations that Sema references. |
| 3487 | // They will be lazily deserialized when needed. |
| 3488 | if (!SemaDeclRefs.empty()) { |
| 3489 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 3490 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 3491 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 3492 | } |
| 3493 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3494 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 3495 | |
| 3496 | // If there are @selector references added them to its pool. This is for |
| 3497 | // implementation of -Wselector. |
| 3498 | if (!F->ReferencedSelectorsData.empty()) { |
| 3499 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 3500 | unsigned I = 0; |
| 3501 | while (I < DataSize) { |
| 3502 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 3503 | SourceLocation SelLoc = ReadSourceLocation( |
| 3504 | *F, F->ReferencedSelectorsData, I); |
| 3505 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 3506 | } |
| 3507 | } |
| 3508 | |
| 3509 | // If there were any pending implicit instantiations, deserialize them |
| 3510 | // and add them to Sema's queue of such instantiations. |
| 3511 | assert(F->PendingInstantiations.size() % 2 == 0 && |
| 3512 | "Expected pairs of entries"); |
| 3513 | for (unsigned Idx = 0, N = F->PendingInstantiations.size(); Idx < N;) { |
| 3514 | ValueDecl *D=cast<ValueDecl>(GetDecl(F->PendingInstantiations[Idx++])); |
| 3515 | SourceLocation Loc = ReadSourceLocation(*F, F->PendingInstantiations,Idx); |
| 3516 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 3517 | } |
| 3518 | } |
| 3519 | |
| 3520 | // The two special data sets below always come from the most recent PCH, |
| 3521 | // which is at the front of the chain. |
| 3522 | PerFileData &F = *Chain.front(); |
| 3523 | |
| 3524 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 3525 | // Sema's list of weak undeclared identifiers. |
| 3526 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 3527 | unsigned Idx = 0; |
| 3528 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 3529 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 3530 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 3531 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 3532 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 3533 | Sema::WeakInfo WI(AliasId, Loc); |
| 3534 | WI.setUsed(Used); |
| 3535 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 3536 | } |
| 3537 | } |
| 3538 | |
| 3539 | // If there were any VTable uses, deserialize the information and add it |
| 3540 | // to Sema's vector and map of VTable uses. |
| 3541 | if (!VTableUses.empty()) { |
| 3542 | unsigned Idx = 0; |
| 3543 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 3544 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 3545 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 3546 | bool DefinitionRequired = VTableUses[Idx++]; |
| 3547 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 3548 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3549 | } |
| 3550 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3551 | } |
| 3552 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3553 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3554 | // Try to find this name within our on-disk hash tables. We start with the |
| 3555 | // most recent one, since that one contains the most up-to-date info. |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3556 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3557 | ASTIdentifierLookupTable *IdTable |
| 3558 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3559 | if (!IdTable) |
| 3560 | continue; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3561 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3562 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3563 | if (Pos == IdTable->end()) |
| 3564 | continue; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3565 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3566 | // Dereferencing the iterator has the effect of building the |
| 3567 | // IdentifierInfo node and populating it with the various |
| 3568 | // declarations it needs. |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3569 | return *Pos; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3570 | } |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3571 | return 0; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3572 | } |
| 3573 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3574 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3575 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3576 | // Find this selector in a hash table. We want to find the most recent entry. |
| 3577 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3578 | PerFileData &F = *Chain[I]; |
| 3579 | if (!F.SelectorLookupTable) |
| 3580 | continue; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3581 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3582 | ASTSelectorLookupTable *PoolTable |
| 3583 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 3584 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3585 | if (Pos != PoolTable->end()) { |
| 3586 | ++NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3587 | // FIXME: Not quite happy with the statistics here. We probably should |
| 3588 | // disable this tracking when called via LoadSelector. |
| 3589 | // Also, should entries without methods count as misses? |
| 3590 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3591 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3592 | if (DeserializationListener) |
| 3593 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 3594 | return std::make_pair(Data.Instance, Data.Factory); |
| 3595 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3596 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3597 | |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3598 | ++NumMethodPoolMisses; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3599 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3600 | } |
| 3601 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3602 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3603 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 3604 | ReadMethodPool(Sel); |
| 3605 | } |
| 3606 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3607 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3608 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3609 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3610 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3611 | if (DeserializationListener) |
| 3612 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3613 | } |
| 3614 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3615 | /// \brief Set the globally-visible declarations associated with the given |
| 3616 | /// identifier. |
| 3617 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3618 | /// If the AST reader is currently in a state where the given declaration IDs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3619 | /// cannot safely be resolved, they are queued until it is safe to resolve |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3620 | /// them. |
| 3621 | /// |
| 3622 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 3623 | /// declarations. |
| 3624 | /// |
| 3625 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 3626 | /// visible at global scope. |
| 3627 | /// |
| 3628 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 3629 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 3630 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3631 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3632 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3633 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 3634 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3635 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3636 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 3637 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 3638 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 3639 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3640 | return; |
| 3641 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3642 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3643 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 3644 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 3645 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 3646 | if (SemaObj->TUScope) { |
| 3647 | // Introduce this declaration into the translation-unit scope |
| 3648 | // and add it to the declaration chain for this identifier, so |
| 3649 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 3650 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 3651 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3652 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3653 | } else { |
| 3654 | // Queue this declaration so that it will be added to the |
| 3655 | // translation unit scope and identifier's declaration chain |
| 3656 | // once a Sema object is known. |
| 3657 | PreloadedDecls.push_back(D); |
| 3658 | } |
| 3659 | } |
| 3660 | } |
| 3661 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3662 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3663 | if (ID == 0) |
| 3664 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3665 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3666 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3667 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3668 | return 0; |
| 3669 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3670 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3671 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3672 | ID -= 1; |
| 3673 | if (!IdentifiersLoaded[ID]) { |
| 3674 | unsigned Index = ID; |
| 3675 | const char *Str = 0; |
| 3676 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3677 | PerFileData *F = Chain[N - I - 1]; |
| 3678 | if (Index < F->LocalNumIdentifiers) { |
| 3679 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 3680 | Str = F->IdentifierTableData + Offset; |
| 3681 | break; |
| 3682 | } |
| 3683 | Index -= F->LocalNumIdentifiers; |
| 3684 | } |
| 3685 | assert(Str && "Broken Chain"); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 3686 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3687 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 3688 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 3689 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 3690 | // unsigned integers. This is important to avoid integer overflow when |
| 3691 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 3692 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3693 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 3694 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3695 | IdentifiersLoaded[ID] |
Kovarththanan Rajaratnam | 811f426 | 2010-03-12 10:32:27 +0000 | [diff] [blame] | 3696 | = &PP->getIdentifierTable().get(Str, StrLen); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3697 | if (DeserializationListener) |
| 3698 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3699 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3700 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3701 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3702 | } |
| 3703 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3704 | void ASTReader::ReadSLocEntry(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 3705 | ReadSLocEntryRecord(ID); |
| 3706 | } |
| 3707 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3708 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3709 | if (ID == 0) |
| 3710 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3711 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3712 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3713 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3714 | return Selector(); |
| 3715 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3716 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3717 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3718 | // Load this selector from the selector table. |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3719 | unsigned Idx = ID - 1; |
| 3720 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3721 | PerFileData &F = *Chain[N - I - 1]; |
| 3722 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3723 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3724 | SelectorsLoaded[ID - 1] = |
| 3725 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 3726 | if (DeserializationListener) |
| 3727 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 3728 | break; |
| 3729 | } |
| 3730 | Idx -= F.LocalNumSelectors; |
| 3731 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3732 | } |
| 3733 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3734 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3735 | } |
| 3736 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3737 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 3738 | return DecodeSelector(ID); |
| 3739 | } |
| 3740 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3741 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3742 | // ID 0 (the null selector) is considered an external selector. |
| 3743 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 3744 | } |
| 3745 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3746 | DeclarationName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3747 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3748 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 3749 | switch (Kind) { |
| 3750 | case DeclarationName::Identifier: |
| 3751 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 3752 | |
| 3753 | case DeclarationName::ObjCZeroArgSelector: |
| 3754 | case DeclarationName::ObjCOneArgSelector: |
| 3755 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 3756 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3757 | |
| 3758 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3759 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 3760 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3761 | |
| 3762 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3763 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 3764 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3765 | |
| 3766 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3767 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 3768 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3769 | |
| 3770 | case DeclarationName::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3771 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3772 | (OverloadedOperatorKind)Record[Idx++]); |
| 3773 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3774 | case DeclarationName::CXXLiteralOperatorName: |
| 3775 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 3776 | GetIdentifierInfo(Record, Idx)); |
| 3777 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3778 | case DeclarationName::CXXUsingDirective: |
| 3779 | return DeclarationName::getUsingDirectiveName(); |
| 3780 | } |
| 3781 | |
| 3782 | // Required to silence GCC warning |
| 3783 | return DeclarationName(); |
| 3784 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3785 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3786 | TemplateName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3787 | ASTReader::ReadTemplateName(const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3788 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
| 3789 | switch (Kind) { |
| 3790 | case TemplateName::Template: |
| 3791 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 3792 | |
| 3793 | case TemplateName::OverloadedTemplate: { |
| 3794 | unsigned size = Record[Idx++]; |
| 3795 | UnresolvedSet<8> Decls; |
| 3796 | while (size--) |
| 3797 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 3798 | |
| 3799 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 3800 | } |
| 3801 | |
| 3802 | case TemplateName::QualifiedTemplate: { |
| 3803 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3804 | bool hasTemplKeyword = Record[Idx++]; |
| 3805 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 3806 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 3807 | } |
| 3808 | |
| 3809 | case TemplateName::DependentTemplate: { |
| 3810 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3811 | if (Record[Idx++]) // isIdentifier |
| 3812 | return Context->getDependentTemplateName(NNS, |
| 3813 | GetIdentifierInfo(Record, Idx)); |
| 3814 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3815 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3816 | } |
| 3817 | } |
| 3818 | |
| 3819 | assert(0 && "Unhandled template name kind!"); |
| 3820 | return TemplateName(); |
| 3821 | } |
| 3822 | |
| 3823 | TemplateArgument |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3824 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3825 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3826 | switch ((TemplateArgument::ArgKind)Record[Idx++]) { |
| 3827 | case TemplateArgument::Null: |
| 3828 | return TemplateArgument(); |
| 3829 | case TemplateArgument::Type: |
| 3830 | return TemplateArgument(GetType(Record[Idx++])); |
| 3831 | case TemplateArgument::Declaration: |
| 3832 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 3833 | case TemplateArgument::Integral: { |
| 3834 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 3835 | QualType T = GetType(Record[Idx++]); |
| 3836 | return TemplateArgument(Value, T); |
| 3837 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3838 | case TemplateArgument::Template: |
| 3839 | return TemplateArgument(ReadTemplateName(Record, Idx)); |
| 3840 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3841 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3842 | case TemplateArgument::Pack: { |
| 3843 | unsigned NumArgs = Record[Idx++]; |
| 3844 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 3845 | Args.reserve(NumArgs); |
| 3846 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3847 | Args.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3848 | TemplateArgument TemplArg; |
| 3849 | TemplArg.setArgumentPack(Args.data(), Args.size(), /*CopyArgs=*/true); |
| 3850 | return TemplArg; |
| 3851 | } |
| 3852 | } |
| 3853 | |
| 3854 | assert(0 && "Unhandled template argument kind!"); |
| 3855 | return TemplateArgument(); |
| 3856 | } |
| 3857 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3858 | TemplateParameterList * |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3859 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 3860 | const RecordData &Record, unsigned &Idx) { |
| 3861 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 3862 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 3863 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3864 | |
| 3865 | unsigned NumParams = Record[Idx++]; |
| 3866 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 3867 | Params.reserve(NumParams); |
| 3868 | while (NumParams--) |
| 3869 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 3870 | |
| 3871 | TemplateParameterList* TemplateParams = |
| 3872 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 3873 | Params.data(), Params.size(), RAngleLoc); |
| 3874 | return TemplateParams; |
| 3875 | } |
| 3876 | |
| 3877 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3878 | ASTReader:: |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3879 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3880 | PerFileData &F, const RecordData &Record, |
| 3881 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3882 | unsigned NumTemplateArgs = Record[Idx++]; |
| 3883 | TemplArgs.reserve(NumTemplateArgs); |
| 3884 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3885 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3886 | } |
| 3887 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 3888 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3889 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 3890 | const RecordData &Record, unsigned &Idx) { |
| 3891 | unsigned NumDecls = Record[Idx++]; |
| 3892 | while (NumDecls--) { |
| 3893 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 3894 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 3895 | Set.addDecl(D, AS); |
| 3896 | } |
| 3897 | } |
| 3898 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3899 | CXXBaseSpecifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3900 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 3901 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3902 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 3903 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 3904 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3905 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 3906 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 3907 | return CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, TInfo); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3908 | } |
| 3909 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3910 | std::pair<CXXBaseOrMemberInitializer **, unsigned> |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3911 | ASTReader::ReadCXXBaseOrMemberInitializers(PerFileData &F, |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3912 | const RecordData &Record, |
| 3913 | unsigned &Idx) { |
| 3914 | CXXBaseOrMemberInitializer **BaseOrMemberInitializers = 0; |
| 3915 | unsigned NumInitializers = Record[Idx++]; |
| 3916 | if (NumInitializers) { |
| 3917 | ASTContext &C = *getContext(); |
| 3918 | |
| 3919 | BaseOrMemberInitializers |
| 3920 | = new (C) CXXBaseOrMemberInitializer*[NumInitializers]; |
| 3921 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 3922 | TypeSourceInfo *BaseClassInfo = 0; |
| 3923 | bool IsBaseVirtual = false; |
| 3924 | FieldDecl *Member = 0; |
| 3925 | |
| 3926 | bool IsBaseInitializer = Record[Idx++]; |
| 3927 | if (IsBaseInitializer) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3928 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3929 | IsBaseVirtual = Record[Idx++]; |
| 3930 | } else { |
| 3931 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
| 3932 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3933 | SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx); |
| 3934 | Expr *Init = ReadExpr(F); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3935 | FieldDecl *AnonUnionMember |
| 3936 | = cast_or_null<FieldDecl>(GetDecl(Record[Idx++])); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3937 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 3938 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3939 | bool IsWritten = Record[Idx++]; |
| 3940 | unsigned SourceOrderOrNumArrayIndices; |
| 3941 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 3942 | if (IsWritten) { |
| 3943 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 3944 | } else { |
| 3945 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 3946 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 3947 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 3948 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 3949 | } |
| 3950 | |
| 3951 | CXXBaseOrMemberInitializer *BOMInit; |
| 3952 | if (IsBaseInitializer) { |
| 3953 | BOMInit = new (C) CXXBaseOrMemberInitializer(C, BaseClassInfo, |
| 3954 | IsBaseVirtual, LParenLoc, |
| 3955 | Init, RParenLoc); |
| 3956 | } else if (IsWritten) { |
| 3957 | BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc, |
| 3958 | LParenLoc, Init, RParenLoc); |
| 3959 | } else { |
| 3960 | BOMInit = CXXBaseOrMemberInitializer::Create(C, Member, MemberLoc, |
| 3961 | LParenLoc, Init, RParenLoc, |
| 3962 | Indices.data(), |
| 3963 | Indices.size()); |
| 3964 | } |
| 3965 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 3966 | if (IsWritten) |
| 3967 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3968 | BOMInit->setAnonUnionMember(AnonUnionMember); |
| 3969 | BaseOrMemberInitializers[i] = BOMInit; |
| 3970 | } |
| 3971 | } |
| 3972 | |
| 3973 | return std::make_pair(BaseOrMemberInitializers, NumInitializers); |
| 3974 | } |
| 3975 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3976 | NestedNameSpecifier * |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3977 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3978 | unsigned N = Record[Idx++]; |
| 3979 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 3980 | for (unsigned I = 0; I != N; ++I) { |
| 3981 | NestedNameSpecifier::SpecifierKind Kind |
| 3982 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 3983 | switch (Kind) { |
| 3984 | case NestedNameSpecifier::Identifier: { |
| 3985 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 3986 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 3987 | break; |
| 3988 | } |
| 3989 | |
| 3990 | case NestedNameSpecifier::Namespace: { |
| 3991 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 3992 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 3993 | break; |
| 3994 | } |
| 3995 | |
| 3996 | case NestedNameSpecifier::TypeSpec: |
| 3997 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 3998 | Type *T = GetType(Record[Idx++]).getTypePtr(); |
| 3999 | bool Template = Record[Idx++]; |
| 4000 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 4001 | break; |
| 4002 | } |
| 4003 | |
| 4004 | case NestedNameSpecifier::Global: { |
| 4005 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4006 | // No associated value, and there can't be a prefix. |
| 4007 | break; |
| 4008 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4009 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 4010 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4011 | } |
| 4012 | return NNS; |
| 4013 | } |
| 4014 | |
| 4015 | SourceRange |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4016 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 4017 | unsigned &Idx) { |
| 4018 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 4019 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 4020 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4021 | } |
| 4022 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4023 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4024 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4025 | unsigned BitWidth = Record[Idx++]; |
| 4026 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 4027 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 4028 | Idx += NumWords; |
| 4029 | return Result; |
| 4030 | } |
| 4031 | |
| 4032 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4033 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4034 | bool isUnsigned = Record[Idx++]; |
| 4035 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 4036 | } |
| 4037 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4038 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4039 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4040 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 4041 | } |
| 4042 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4043 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4044 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4045 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 4046 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4047 | Idx += Len; |
| 4048 | return Result; |
| 4049 | } |
| 4050 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4051 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4052 | unsigned &Idx) { |
| 4053 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 4054 | return CXXTemporary::Create(*Context, Decl); |
| 4055 | } |
| 4056 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4057 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 4058 | return Diag(SourceLocation(), DiagID); |
| 4059 | } |
| 4060 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4061 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4062 | return Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4063 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4064 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4065 | /// \brief Retrieve the identifier table associated with the |
| 4066 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4067 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4068 | assert(PP && "Forgot to set Preprocessor ?"); |
| 4069 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4070 | } |
| 4071 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4072 | /// \brief Record that the given ID maps to the given switch-case |
| 4073 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4074 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4075 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 4076 | SwitchCaseStmts[ID] = SC; |
| 4077 | } |
| 4078 | |
| 4079 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4080 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4081 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 4082 | return SwitchCaseStmts[ID]; |
| 4083 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4084 | |
| 4085 | /// \brief Record that the given label statement has been |
| 4086 | /// deserialized and has the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4087 | void ASTReader::RecordLabelStmt(LabelStmt *S, unsigned ID) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4088 | assert(LabelStmts.find(ID) == LabelStmts.end() && |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4089 | "Deserialized label twice"); |
| 4090 | LabelStmts[ID] = S; |
| 4091 | |
| 4092 | // If we've already seen any goto statements that point to this |
| 4093 | // label, resolve them now. |
| 4094 | typedef std::multimap<unsigned, GotoStmt *>::iterator GotoIter; |
| 4095 | std::pair<GotoIter, GotoIter> Gotos = UnresolvedGotoStmts.equal_range(ID); |
| 4096 | for (GotoIter Goto = Gotos.first; Goto != Gotos.second; ++Goto) |
| 4097 | Goto->second->setLabel(S); |
| 4098 | UnresolvedGotoStmts.erase(Gotos.first, Gotos.second); |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4099 | |
| 4100 | // If we've already seen any address-label statements that point to |
| 4101 | // this label, resolve them now. |
| 4102 | typedef std::multimap<unsigned, AddrLabelExpr *>::iterator AddrLabelIter; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4103 | std::pair<AddrLabelIter, AddrLabelIter> AddrLabels |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4104 | = UnresolvedAddrLabelExprs.equal_range(ID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4105 | for (AddrLabelIter AddrLabel = AddrLabels.first; |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4106 | AddrLabel != AddrLabels.second; ++AddrLabel) |
| 4107 | AddrLabel->second->setLabel(S); |
| 4108 | UnresolvedAddrLabelExprs.erase(AddrLabels.first, AddrLabels.second); |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4109 | } |
| 4110 | |
| 4111 | /// \brief Set the label of the given statement to the label |
| 4112 | /// identified by ID. |
| 4113 | /// |
| 4114 | /// Depending on the order in which the label and other statements |
| 4115 | /// referencing that label occur, this operation may complete |
| 4116 | /// immediately (updating the statement) or it may queue the |
| 4117 | /// statement to be back-patched later. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4118 | void ASTReader::SetLabelOf(GotoStmt *S, unsigned ID) { |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4119 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 4120 | if (Label != LabelStmts.end()) { |
| 4121 | // We've already seen this label, so set the label of the goto and |
| 4122 | // we're done. |
| 4123 | S->setLabel(Label->second); |
| 4124 | } else { |
| 4125 | // We haven't seen this label yet, so add this goto to the set of |
| 4126 | // unresolved goto statements. |
| 4127 | UnresolvedGotoStmts.insert(std::make_pair(ID, S)); |
| 4128 | } |
| 4129 | } |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4130 | |
| 4131 | /// \brief Set the label of the given expression to the label |
| 4132 | /// identified by ID. |
| 4133 | /// |
| 4134 | /// Depending on the order in which the label and other statements |
| 4135 | /// referencing that label occur, this operation may complete |
| 4136 | /// immediately (updating the statement) or it may queue the |
| 4137 | /// statement to be back-patched later. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4138 | void ASTReader::SetLabelOf(AddrLabelExpr *S, unsigned ID) { |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4139 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 4140 | if (Label != LabelStmts.end()) { |
| 4141 | // We've already seen this label, so set the label of the |
| 4142 | // label-address expression and we're done. |
| 4143 | S->setLabel(Label->second); |
| 4144 | } else { |
| 4145 | // We haven't seen this label yet, so add this label-address |
| 4146 | // expression to the set of unresolved label-address expressions. |
| 4147 | UnresolvedAddrLabelExprs.insert(std::make_pair(ID, S)); |
| 4148 | } |
| 4149 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4150 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4151 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4152 | assert(NumCurrentElementsDeserializing && |
| 4153 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 4154 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4155 | // If any identifiers with corresponding top-level declarations have |
| 4156 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4157 | while (!PendingIdentifierInfos.empty()) { |
| 4158 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 4159 | PendingIdentifierInfos.front().DeclIDs, true); |
| 4160 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4161 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4162 | |
| 4163 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 4164 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4165 | if (Consumer) |
| 4166 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4167 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4168 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4169 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4170 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4171 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
| 4172 | const char *isysroot, bool DisableValidation) |
| 4173 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 4174 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 4175 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
| 4176 | Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), |
| 4177 | NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4178 | TotalNumSLocEntries(0), NextSLocOffset(0), NumStatementsRead(0), |
| 4179 | TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), |
| 4180 | NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4181 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4182 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4183 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
| 4184 | RelocatablePCH = false; |
| 4185 | } |
| 4186 | |
| 4187 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 4188 | Diagnostic &Diags, const char *isysroot, |
| 4189 | bool DisableValidation) |
| 4190 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
| 4191 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), |
| 4192 | isysroot(isysroot), DisableValidation(DisableValidation), NumStatHits(0), |
| 4193 | NumStatMisses(0), NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4194 | NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0), |
| 4195 | NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), |
| 4196 | NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
| 4197 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4198 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4199 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4200 | RelocatablePCH = false; |
| 4201 | } |
| 4202 | |
| 4203 | ASTReader::~ASTReader() { |
| 4204 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 4205 | delete Chain[e - i - 1]; |
| 4206 | // Delete all visible decl lookup tables |
| 4207 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 4208 | E = DeclContextOffsets.end(); |
| 4209 | I != E; ++I) { |
| 4210 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 4211 | J != F; ++J) { |
| 4212 | if (J->NameLookupTableData) |
| 4213 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 4214 | J->NameLookupTableData); |
| 4215 | } |
| 4216 | } |
| 4217 | for (DeclContextVisibleUpdatesPending::iterator |
| 4218 | I = PendingVisibleUpdates.begin(), |
| 4219 | E = PendingVisibleUpdates.end(); |
| 4220 | I != E; ++I) { |
| 4221 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 4222 | F = I->second.end(); |
| 4223 | J != F; ++J) |
| 4224 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 4225 | } |
| 4226 | } |
| 4227 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 4228 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
| 4229 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 4230 | LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), |
| 4231 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
| 4232 | MacroDefinitionOffsets(0), LocalNumSelectors(0), SelectorOffsets(0), |
| 4233 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
| 4234 | DeclOffsets(0), LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 4235 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4236 | {} |
| 4237 | |
| 4238 | ASTReader::PerFileData::~PerFileData() { |
| 4239 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
| 4240 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 4241 | } |
| 4242 | |