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