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