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