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