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" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 36 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 37 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 38 | #include "clang/Basic/Version.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 39 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 40 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 41 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 42 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 43 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 44 | #include "llvm/Support/Path.h" |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 45 | #include "llvm/Support/system_error.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 46 | #include <algorithm> |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 47 | #include <iterator> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 48 | #include <cstdio> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 49 | #include <sys/stat.h> |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 50 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 51 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 52 | using namespace clang::serialization; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 53 | |
| 54 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 55 | // PCH validator implementation |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 56 | //===----------------------------------------------------------------------===// |
| 57 | |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 58 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 59 | |
| 60 | bool |
| 61 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 62 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 63 | #define PARSE_LANGOPT_BENIGN(Option) |
| 64 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 65 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 66 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 67 | return true; \ |
| 68 | } |
| 69 | |
| 70 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 71 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 72 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 73 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 74 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 75 | PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 76 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 77 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 78 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 79 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
| 80 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 81 | PARSE_LANGOPT_BENIGN(MSCVersion); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 82 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 83 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 84 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 85 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 86 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 87 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 88 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 89 | PARSE_LANGOPT_IMPORTANT(AppleKext, diag::warn_pch_apple_kext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 90 | PARSE_LANGOPT_IMPORTANT(ObjCDefaultSynthProperties, |
| 91 | diag::warn_pch_objc_auto_properties); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 92 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 93 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 94 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 95 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 96 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 97 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 98 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 99 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 100 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 101 | PARSE_LANGOPT_IMPORTANT(MSBitfields, diag::warn_pch_ms_bitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 102 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 103 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 104 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 105 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 106 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 107 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 108 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 109 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 110 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 111 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 112 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 113 | diag::warn_pch_heinous_extensions); |
| 114 | // FIXME: Most of the options below are benign if the macro wasn't |
| 115 | // used. Unfortunately, this means that a PCH compiled without |
| 116 | // optimization can't be used with optimization turned on, even |
| 117 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 118 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 119 | // doesn't matter. We could consider making this some special kind |
| 120 | // of check. |
| 121 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 122 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 123 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 124 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 125 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 126 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
| 127 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 128 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 129 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 130 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 131 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 132 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 133 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 134 | return true; |
| 135 | } |
| 136 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 137 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 138 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 139 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 140 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 141 | PARSE_LANGOPT_IMPORTANT(CUDA, diag::warn_pch_cuda); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 142 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 143 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 144 | PARSE_LANGOPT_BENIGN(SpellChecking); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame^] | 145 | PARSE_LANGOPT_BENIGN(DefaultFPContract); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 146 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 147 | #undef PARSE_LANGOPT_BENIGN |
| 148 | |
| 149 | return false; |
| 150 | } |
| 151 | |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 152 | bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) { |
| 153 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 154 | return false; |
| 155 | |
| 156 | Reader.Diag(diag::warn_pch_target_triple) |
| 157 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 158 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 161 | namespace { |
| 162 | struct EmptyStringRef { |
| 163 | bool operator ()(llvm::StringRef r) const { return r.empty(); } |
| 164 | }; |
| 165 | struct EmptyBlock { |
| 166 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 167 | }; |
| 168 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 169 | |
| 170 | static bool EqualConcatenations(llvm::SmallVector<llvm::StringRef, 2> L, |
| 171 | PCHPredefinesBlocks R) { |
| 172 | // First, sum up the lengths. |
| 173 | unsigned LL = 0, RL = 0; |
| 174 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 175 | LL += L[I].size(); |
| 176 | } |
| 177 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 178 | RL += R[I].Data.size(); |
| 179 | } |
| 180 | if (LL != RL) |
| 181 | return false; |
| 182 | if (LL == 0 && RL == 0) |
| 183 | return true; |
| 184 | |
| 185 | // Kick out empty parts, they confuse the algorithm below. |
| 186 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 187 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 188 | |
| 189 | // Do it the hard way. At this point, both vectors must be non-empty. |
| 190 | llvm::StringRef LR = L[0], RR = R[0].Data; |
| 191 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 192 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 193 | for (;;) { |
| 194 | // Compare the current pieces. |
| 195 | if (LR.size() == RR.size()) { |
| 196 | // If they're the same length, it's pretty easy. |
| 197 | if (LR != RR) |
| 198 | return false; |
| 199 | // Both pieces are done, advance. |
| 200 | ++LI; |
| 201 | ++RI; |
| 202 | // If either string is done, they're both done, since they're the same |
| 203 | // length. |
| 204 | if (LI == LN) { |
| 205 | assert(RI == RN && "Strings not the same length after all?"); |
| 206 | return true; |
| 207 | } |
| 208 | LR = L[LI]; |
| 209 | RR = R[RI].Data; |
| 210 | } else if (LR.size() < RR.size()) { |
| 211 | // Right piece is longer. |
| 212 | if (!RR.startswith(LR)) |
| 213 | return false; |
| 214 | ++LI; |
| 215 | assert(LI != LN && "Strings not the same length after all?"); |
| 216 | RR = RR.substr(LR.size()); |
| 217 | LR = L[LI]; |
| 218 | } else { |
| 219 | // Left piece is longer. |
| 220 | if (!LR.startswith(RR)) |
| 221 | return false; |
| 222 | ++RI; |
| 223 | assert(RI != RN && "Strings not the same length after all?"); |
| 224 | LR = LR.substr(RR.size()); |
| 225 | RR = R[RI].Data; |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | static std::pair<FileID, llvm::StringRef::size_type> |
| 231 | FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) { |
| 232 | std::pair<FileID, llvm::StringRef::size_type> Res; |
| 233 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 234 | Res.second = Buffers[I].Data.find(MacroDef); |
| 235 | if (Res.second != llvm::StringRef::npos) { |
| 236 | Res.first = Buffers[I].BufferID; |
| 237 | break; |
| 238 | } |
| 239 | } |
| 240 | return Res; |
| 241 | } |
| 242 | |
| 243 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 244 | llvm::StringRef OriginalFileName, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 245 | std::string &SuggestedPredefines) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 246 | // We are in the context of an implicit include, so the predefines buffer will |
| 247 | // have a #include entry for the PCH file itself (as normalized by the |
| 248 | // preprocessor initialization). Find it and skip over it in the checking |
| 249 | // below. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 250 | llvm::SmallString<256> PCHInclude; |
| 251 | PCHInclude += "#include \""; |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 252 | PCHInclude += NormalizeDashIncludePath(OriginalFileName); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 253 | PCHInclude += "\"\n"; |
| 254 | std::pair<llvm::StringRef,llvm::StringRef> Split = |
| 255 | llvm::StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 256 | llvm::StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 257 | if (Left == PP.getPredefines()) { |
| 258 | Error("Missing PCH include entry!"); |
| 259 | return true; |
| 260 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 261 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 262 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 263 | // command line, we're done. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 264 | llvm::SmallVector<llvm::StringRef, 2> CommandLine; |
| 265 | CommandLine.push_back(Left); |
| 266 | CommandLine.push_back(Right); |
| 267 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 268 | return false; |
| 269 | |
| 270 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 271 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 272 | // The predefines buffers are different. Determine what the differences are, |
| 273 | // and whether they require us to reject the PCH file. |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 274 | llvm::SmallVector<llvm::StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 275 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 276 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 277 | |
| 278 | llvm::SmallVector<llvm::StringRef, 8> CmdLineLines; |
| 279 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 280 | |
| 281 | // Pick out implicit #includes after the PCH and don't consider them for |
| 282 | // validation; we will insert them into SuggestedPredefines so that the |
| 283 | // preprocessor includes them. |
| 284 | std::string IncludesAfterPCH; |
| 285 | llvm::SmallVector<llvm::StringRef, 8> AfterPCHLines; |
| 286 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 287 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 288 | if (AfterPCHLines[i].startswith("#include ")) { |
| 289 | IncludesAfterPCH += AfterPCHLines[i]; |
| 290 | IncludesAfterPCH += '\n'; |
| 291 | } else { |
| 292 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | // Make sure we add the includes last into SuggestedPredefines before we |
| 297 | // exit this function. |
| 298 | struct AddIncludesRAII { |
| 299 | std::string &SuggestedPredefines; |
| 300 | std::string &IncludesAfterPCH; |
| 301 | |
| 302 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 303 | std::string &IncludesAfterPCH) |
| 304 | : SuggestedPredefines(SuggestedPredefines), |
| 305 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 306 | ~AddIncludesRAII() { |
| 307 | SuggestedPredefines += IncludesAfterPCH; |
| 308 | } |
| 309 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 310 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 311 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 312 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 313 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 314 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 315 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 316 | // Determine which predefines that were used to build the PCH file are missing |
| 317 | // from the command line. |
| 318 | std::vector<llvm::StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 319 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 320 | CmdLineLines.begin(), CmdLineLines.end(), |
| 321 | std::back_inserter(MissingPredefines)); |
| 322 | |
| 323 | bool MissingDefines = false; |
| 324 | bool ConflictingDefines = false; |
| 325 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 326 | llvm::StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 327 | if (Missing.startswith("#include ")) { |
| 328 | // An -include was specified when generating the PCH; it is included in |
| 329 | // the PCH, just ignore it. |
| 330 | continue; |
| 331 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 332 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 333 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 334 | return true; |
| 335 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 336 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 337 | // This is a macro definition. Determine the name of the macro we're |
| 338 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 339 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 340 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 341 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 342 | assert(EndOfMacroName != std::string::npos && |
| 343 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 344 | llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 345 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 346 | // Determine whether this macro was given a different definition on the |
| 347 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 348 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 349 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 350 | llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 351 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 352 | MacroDefStart); |
| 353 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 354 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 355 | // Different macro; we're done. |
| 356 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 357 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 358 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 359 | |
| 360 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 361 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 362 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 363 | (*ConflictPos)[MacroDefLen] != '(') |
| 364 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 366 | // We found a conflicting macro definition. |
| 367 | break; |
| 368 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 369 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 370 | if (ConflictPos != CmdLineLines.end()) { |
| 371 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 372 | << MacroName; |
| 373 | |
| 374 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 375 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 376 | FindMacro(Buffers, Missing); |
| 377 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 378 | SourceLocation PCHMissingLoc = |
| 379 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 380 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 381 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 382 | |
| 383 | ConflictingDefines = true; |
| 384 | continue; |
| 385 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 386 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 387 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 388 | // 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] | 389 | if (ConflictingDefines) |
| 390 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 391 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 392 | if (!MissingDefines) { |
| 393 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 394 | MissingDefines = true; |
| 395 | } |
| 396 | |
| 397 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 398 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 399 | FindMacro(Buffers, Missing); |
| 400 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 401 | SourceLocation PCHMissingLoc = |
| 402 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 403 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 404 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 405 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 406 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 407 | if (ConflictingDefines) |
| 408 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 410 | // Determine what predefines were introduced based on command-line |
| 411 | // parameters that were not present when building the PCH |
| 412 | // file. Extra #defines are okay, so long as the identifiers being |
| 413 | // defined were not used within the precompiled header. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 414 | std::vector<llvm::StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 415 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 416 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 418 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 419 | llvm::StringRef &Extra = ExtraPredefines[I]; |
| 420 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 421 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 422 | return true; |
| 423 | } |
| 424 | |
| 425 | // This is an extra macro definition. Determine the name of the |
| 426 | // macro we're defining. |
| 427 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 429 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 430 | assert(EndOfMacroName != std::string::npos && |
| 431 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 432 | llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 433 | |
| 434 | // Check whether this name was used somewhere in the PCH file. If |
| 435 | // so, defining it as a macro could change behavior, so we reject |
| 436 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 437 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 438 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 439 | return true; |
| 440 | } |
| 441 | |
| 442 | // Add this definition to the suggested predefines buffer. |
| 443 | SuggestedPredefines += Extra; |
| 444 | SuggestedPredefines += '\n'; |
| 445 | } |
| 446 | |
| 447 | // If we get here, it's because the predefines buffer had compatible |
| 448 | // contents. Accept the PCH file. |
| 449 | return false; |
| 450 | } |
| 451 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 452 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 453 | unsigned ID) { |
| 454 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 455 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | void PCHValidator::ReadCounter(unsigned Value) { |
| 459 | PP.setCounterValue(Value); |
| 460 | } |
| 461 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 462 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 463 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 464 | //===----------------------------------------------------------------------===// |
| 465 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 466 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 467 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 468 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 471 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 472 | namespace { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 473 | class ASTSelectorLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 474 | ASTReader &Reader; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 475 | |
| 476 | public: |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 477 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 478 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 479 | ObjCMethodList Instance, Factory; |
| 480 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 481 | |
| 482 | typedef Selector external_key_type; |
| 483 | typedef external_key_type internal_key_type; |
| 484 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 485 | explicit ASTSelectorLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 486 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 487 | static bool EqualKey(const internal_key_type& a, |
| 488 | const internal_key_type& b) { |
| 489 | return a == b; |
| 490 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 491 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 492 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 493 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 494 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 496 | // This hopefully will just get inlined and removed by the optimizer. |
| 497 | static const internal_key_type& |
| 498 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 500 | static std::pair<unsigned, unsigned> |
| 501 | ReadKeyDataLength(const unsigned char*& d) { |
| 502 | using namespace clang::io; |
| 503 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 504 | unsigned DataLen = ReadUnalignedLE16(d); |
| 505 | return std::make_pair(KeyLen, DataLen); |
| 506 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 507 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 508 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 509 | using namespace clang::io; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 510 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 511 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 512 | IdentifierInfo *FirstII |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 513 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 514 | if (N == 0) |
| 515 | return SelTable.getNullarySelector(FirstII); |
| 516 | else if (N == 1) |
| 517 | return SelTable.getUnarySelector(FirstII); |
| 518 | |
| 519 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 520 | Args.push_back(FirstII); |
| 521 | for (unsigned I = 1; I != N; ++I) |
| 522 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 523 | |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 524 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 525 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 526 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 527 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 528 | using namespace clang::io; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 529 | |
| 530 | data_type Result; |
| 531 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 532 | Result.ID = ReadUnalignedLE32(d); |
| 533 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 534 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 535 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 536 | // Load instance methods |
| 537 | ObjCMethodList *Prev = 0; |
| 538 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 540 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 541 | if (!Result.Instance.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 542 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 543 | Result.Instance.Method = Method; |
| 544 | Prev = &Result.Instance; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 545 | continue; |
| 546 | } |
| 547 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 548 | ObjCMethodList *Mem = |
| 549 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 550 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 551 | Prev = Prev->Next; |
| 552 | } |
| 553 | |
| 554 | // Load factory methods |
| 555 | Prev = 0; |
| 556 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 557 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 558 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 559 | if (!Result.Factory.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 560 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 561 | Result.Factory.Method = Method; |
| 562 | Prev = &Result.Factory; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 563 | continue; |
| 564 | } |
| 565 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 566 | ObjCMethodList *Mem = |
| 567 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 568 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 569 | Prev = Prev->Next; |
| 570 | } |
| 571 | |
| 572 | return Result; |
| 573 | } |
| 574 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 575 | |
| 576 | } // end anonymous namespace |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 577 | |
| 578 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 579 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 580 | ASTSelectorLookupTable; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 581 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 582 | namespace clang { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 583 | class ASTIdentifierLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 584 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 585 | ASTReader::PerFileData &F; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 586 | |
| 587 | // If we know the IdentifierInfo in advance, it is here and we will |
| 588 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 589 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 590 | IdentifierInfo *KnownII; |
| 591 | |
| 592 | public: |
| 593 | typedef IdentifierInfo * data_type; |
| 594 | |
| 595 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 596 | |
| 597 | typedef external_key_type internal_key_type; |
| 598 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 599 | ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 600 | IdentifierInfo *II = 0) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 601 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 602 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 603 | static bool EqualKey(const internal_key_type& a, |
| 604 | const internal_key_type& b) { |
| 605 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 606 | : false; |
| 607 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 608 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 609 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 610 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 611 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 612 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 613 | // This hopefully will just get inlined and removed by the optimizer. |
| 614 | static const internal_key_type& |
| 615 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 616 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 617 | // This hopefully will just get inlined and removed by the optimizer. |
| 618 | static const external_key_type& |
| 619 | GetExternalKey(const internal_key_type& x) { return x; } |
| 620 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 621 | static std::pair<unsigned, unsigned> |
| 622 | ReadKeyDataLength(const unsigned char*& d) { |
| 623 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 624 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 625 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 626 | return std::make_pair(KeyLen, DataLen); |
| 627 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 628 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 629 | static std::pair<const char*, unsigned> |
| 630 | ReadKey(const unsigned char* d, unsigned n) { |
| 631 | assert(n >= 2 && d[n-1] == '\0'); |
| 632 | return std::make_pair((const char*) d, n-1); |
| 633 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 634 | |
| 635 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 636 | const unsigned char* d, |
| 637 | unsigned DataLen) { |
| 638 | using namespace clang::io; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 639 | IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 640 | bool IsInteresting = ID & 0x01; |
| 641 | |
| 642 | // Wipe out the "is interesting" bit. |
| 643 | ID = ID >> 1; |
| 644 | |
| 645 | if (!IsInteresting) { |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 646 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 647 | // and associate it with the persistent ID. |
| 648 | IdentifierInfo *II = KnownII; |
| 649 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 650 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 651 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 652 | II->setIsFromAST(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 653 | return II; |
| 654 | } |
| 655 | |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 656 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 657 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 658 | Bits >>= 1; |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 659 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 660 | Bits >>= 1; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 661 | bool Poisoned = Bits & 0x01; |
| 662 | Bits >>= 1; |
| 663 | bool ExtensionToken = Bits & 0x01; |
| 664 | Bits >>= 1; |
| 665 | bool hasMacroDefinition = Bits & 0x01; |
| 666 | Bits >>= 1; |
| 667 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 668 | Bits >>= 10; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 669 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 670 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 671 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 672 | |
| 673 | // Build the IdentifierInfo itself and link the identifier ID with |
| 674 | // the new IdentifierInfo. |
| 675 | IdentifierInfo *II = KnownII; |
| 676 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 677 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 678 | Reader.SetIdentifierInfo(ID, II); |
| 679 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 680 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 681 | // Token IDs are read-only. |
| 682 | if (HasRevertedTokenIDToIdentifier) |
| 683 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 684 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 685 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 686 | "Incorrect extension token flag"); |
| 687 | (void)ExtensionToken; |
| 688 | II->setIsPoisoned(Poisoned); |
| 689 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 690 | "Incorrect C++ operator keyword flag"); |
| 691 | (void)CPlusPlusOperatorKeyword; |
| 692 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 693 | // If this identifier is a macro, deserialize the macro |
| 694 | // definition. |
| 695 | if (hasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 696 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 697 | Reader.SetIdentifierIsMacro(II, F, Offset); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 698 | DataLen -= 4; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 699 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 700 | |
| 701 | // Read all of the declarations visible at global scope with this |
| 702 | // name. |
Chris Lattner | 6bf690f | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 703 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 704 | if (DataLen > 0) { |
| 705 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 706 | for (; DataLen > 0; DataLen -= 4) |
| 707 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 708 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 709 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 711 | II->setIsFromAST(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 712 | return II; |
| 713 | } |
| 714 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 715 | |
| 716 | } // end anonymous namespace |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 717 | |
| 718 | /// \brief The on-disk hash table used to contain information about |
| 719 | /// all of the identifiers in the program. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 720 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 721 | ASTIdentifierLookupTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 722 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 723 | namespace { |
| 724 | class ASTDeclContextNameLookupTrait { |
| 725 | ASTReader &Reader; |
| 726 | |
| 727 | public: |
| 728 | /// \brief Pair of begin/end iterators for DeclIDs. |
| 729 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 730 | |
| 731 | /// \brief Special internal key for declaration names. |
| 732 | /// The hash table creates keys for comparison; we do not create |
| 733 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 734 | struct DeclNameKey { |
| 735 | DeclarationName::NameKind Kind; |
| 736 | uint64_t Data; |
| 737 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 738 | }; |
| 739 | |
| 740 | typedef DeclarationName external_key_type; |
| 741 | typedef DeclNameKey internal_key_type; |
| 742 | |
| 743 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
| 744 | |
| 745 | static bool EqualKey(const internal_key_type& a, |
| 746 | const internal_key_type& b) { |
| 747 | return a.Kind == b.Kind && a.Data == b.Data; |
| 748 | } |
| 749 | |
| 750 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 751 | llvm::FoldingSetNodeID ID; |
| 752 | ID.AddInteger(Key.Kind); |
| 753 | |
| 754 | switch (Key.Kind) { |
| 755 | case DeclarationName::Identifier: |
| 756 | case DeclarationName::CXXLiteralOperatorName: |
| 757 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 758 | break; |
| 759 | case DeclarationName::ObjCZeroArgSelector: |
| 760 | case DeclarationName::ObjCOneArgSelector: |
| 761 | case DeclarationName::ObjCMultiArgSelector: |
| 762 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 763 | break; |
| 764 | case DeclarationName::CXXConstructorName: |
| 765 | case DeclarationName::CXXDestructorName: |
| 766 | case DeclarationName::CXXConversionFunctionName: |
| 767 | ID.AddInteger((TypeID)Key.Data); |
| 768 | break; |
| 769 | case DeclarationName::CXXOperatorName: |
| 770 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 771 | break; |
| 772 | case DeclarationName::CXXUsingDirective: |
| 773 | break; |
| 774 | } |
| 775 | |
| 776 | return ID.ComputeHash(); |
| 777 | } |
| 778 | |
| 779 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 780 | DeclNameKey Key; |
| 781 | Key.Kind = Name.getNameKind(); |
| 782 | switch (Name.getNameKind()) { |
| 783 | case DeclarationName::Identifier: |
| 784 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 785 | break; |
| 786 | case DeclarationName::ObjCZeroArgSelector: |
| 787 | case DeclarationName::ObjCOneArgSelector: |
| 788 | case DeclarationName::ObjCMultiArgSelector: |
| 789 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 790 | break; |
| 791 | case DeclarationName::CXXConstructorName: |
| 792 | case DeclarationName::CXXDestructorName: |
| 793 | case DeclarationName::CXXConversionFunctionName: |
| 794 | Key.Data = Reader.GetTypeID(Name.getCXXNameType()); |
| 795 | break; |
| 796 | case DeclarationName::CXXOperatorName: |
| 797 | Key.Data = Name.getCXXOverloadedOperator(); |
| 798 | break; |
| 799 | case DeclarationName::CXXLiteralOperatorName: |
| 800 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 801 | break; |
| 802 | case DeclarationName::CXXUsingDirective: |
| 803 | break; |
| 804 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 805 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 806 | return Key; |
| 807 | } |
| 808 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 809 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 810 | ASTContext *Context = Reader.getContext(); |
| 811 | switch (Key.Kind) { |
| 812 | case DeclarationName::Identifier: |
| 813 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 814 | |
| 815 | case DeclarationName::ObjCZeroArgSelector: |
| 816 | case DeclarationName::ObjCOneArgSelector: |
| 817 | case DeclarationName::ObjCMultiArgSelector: |
| 818 | return DeclarationName(Selector(Key.Data)); |
| 819 | |
| 820 | case DeclarationName::CXXConstructorName: |
| 821 | return Context->DeclarationNames.getCXXConstructorName( |
| 822 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 823 | |
| 824 | case DeclarationName::CXXDestructorName: |
| 825 | return Context->DeclarationNames.getCXXDestructorName( |
| 826 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 827 | |
| 828 | case DeclarationName::CXXConversionFunctionName: |
| 829 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 830 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 831 | |
| 832 | case DeclarationName::CXXOperatorName: |
| 833 | return Context->DeclarationNames.getCXXOperatorName( |
| 834 | (OverloadedOperatorKind)Key.Data); |
| 835 | |
| 836 | case DeclarationName::CXXLiteralOperatorName: |
| 837 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 838 | (IdentifierInfo*)Key.Data); |
| 839 | |
| 840 | case DeclarationName::CXXUsingDirective: |
| 841 | return DeclarationName::getUsingDirectiveName(); |
| 842 | } |
| 843 | |
| 844 | llvm_unreachable("Invalid Name Kind ?"); |
| 845 | } |
| 846 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 847 | static std::pair<unsigned, unsigned> |
| 848 | ReadKeyDataLength(const unsigned char*& d) { |
| 849 | using namespace clang::io; |
| 850 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 851 | unsigned DataLen = ReadUnalignedLE16(d); |
| 852 | return std::make_pair(KeyLen, DataLen); |
| 853 | } |
| 854 | |
| 855 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 856 | using namespace clang::io; |
| 857 | |
| 858 | DeclNameKey Key; |
| 859 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 860 | switch (Key.Kind) { |
| 861 | case DeclarationName::Identifier: |
| 862 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 863 | break; |
| 864 | case DeclarationName::ObjCZeroArgSelector: |
| 865 | case DeclarationName::ObjCOneArgSelector: |
| 866 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 867 | Key.Data = |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 868 | (uint64_t)Reader.DecodeSelector(ReadUnalignedLE32(d)).getAsOpaquePtr(); |
| 869 | break; |
| 870 | case DeclarationName::CXXConstructorName: |
| 871 | case DeclarationName::CXXDestructorName: |
| 872 | case DeclarationName::CXXConversionFunctionName: |
| 873 | Key.Data = ReadUnalignedLE32(d); // TypeID |
| 874 | break; |
| 875 | case DeclarationName::CXXOperatorName: |
| 876 | Key.Data = *d++; // OverloadedOperatorKind |
| 877 | break; |
| 878 | case DeclarationName::CXXLiteralOperatorName: |
| 879 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 880 | break; |
| 881 | case DeclarationName::CXXUsingDirective: |
| 882 | break; |
| 883 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 884 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 885 | return Key; |
| 886 | } |
| 887 | |
| 888 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 889 | unsigned DataLen) { |
| 890 | using namespace clang::io; |
| 891 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 892 | DeclID *Start = (DeclID *)d; |
| 893 | return std::make_pair(Start, Start + NumDecls); |
| 894 | } |
| 895 | }; |
| 896 | |
| 897 | } // end anonymous namespace |
| 898 | |
| 899 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 900 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 901 | ASTDeclContextNameLookupTable; |
| 902 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 903 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 904 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 905 | DeclContextInfo &Info) { |
| 906 | SavedStreamPosition SavedPosition(Cursor); |
| 907 | // First the lexical decls. |
| 908 | if (Offsets.first != 0) { |
| 909 | Cursor.JumpToBit(Offsets.first); |
| 910 | |
| 911 | RecordData Record; |
| 912 | const char *Blob; |
| 913 | unsigned BlobLen; |
| 914 | unsigned Code = Cursor.ReadCode(); |
| 915 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 916 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 917 | Error("Expected lexical block"); |
| 918 | return true; |
| 919 | } |
| 920 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 921 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 922 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 923 | } else { |
| 924 | Info.LexicalDecls = 0; |
| 925 | Info.NumLexicalDecls = 0; |
| 926 | } |
| 927 | |
| 928 | // Now the lookup table. |
| 929 | if (Offsets.second != 0) { |
| 930 | Cursor.JumpToBit(Offsets.second); |
| 931 | |
| 932 | RecordData Record; |
| 933 | const char *Blob; |
| 934 | unsigned BlobLen; |
| 935 | unsigned Code = Cursor.ReadCode(); |
| 936 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 937 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 938 | Error("Expected visible lookup table block"); |
| 939 | return true; |
| 940 | } |
| 941 | Info.NameLookupTableData |
| 942 | = ASTDeclContextNameLookupTable::Create( |
| 943 | (const unsigned char *)Blob + Record[0], |
| 944 | (const unsigned char *)Blob, |
| 945 | ASTDeclContextNameLookupTrait(*this)); |
Sebastian Redl | 0ea8f7f | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 946 | } else { |
| 947 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | return false; |
| 951 | } |
| 952 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 953 | void ASTReader::Error(const char *Msg) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 954 | Diag(diag::err_fe_pch_malformed) << Msg; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 957 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 958 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 959 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 960 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 961 | ActualOriginalFileName, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 962 | SuggestedPredefines); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 963 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 964 | } |
| 965 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 966 | //===----------------------------------------------------------------------===// |
| 967 | // Source Manager Deserialization |
| 968 | //===----------------------------------------------------------------------===// |
| 969 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 970 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 971 | /// \returns true if there was an error. |
| 972 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 973 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 974 | unsigned Idx = 0; |
| 975 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 976 | |
| 977 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 978 | std::map<int, int> FileIDs; |
| 979 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 980 | // Extract the file name |
| 981 | unsigned FilenameLen = Record[Idx++]; |
| 982 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 983 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 984 | MaybeAddSystemRootToFilename(Filename); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 985 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 986 | Filename.size()); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | // Parse the line entries |
| 990 | std::vector<LineEntry> Entries; |
| 991 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 992 | int FID = Record[Idx++]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 993 | |
| 994 | // Extract the line entries |
| 995 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 996 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 997 | Entries.clear(); |
| 998 | Entries.reserve(NumEntries); |
| 999 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1000 | unsigned FileOffset = Record[Idx++]; |
| 1001 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1002 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1003 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1004 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1005 | unsigned IncludeOffset = Record[Idx++]; |
| 1006 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1007 | FileKind, IncludeOffset)); |
| 1008 | } |
| 1009 | LineTable.AddEntry(FID, Entries); |
| 1010 | } |
| 1011 | |
| 1012 | return false; |
| 1013 | } |
| 1014 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1015 | namespace { |
| 1016 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1017 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1018 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1019 | const ino_t ino; |
| 1020 | const dev_t dev; |
| 1021 | const mode_t mode; |
| 1022 | const time_t mtime; |
| 1023 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1024 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1025 | ASTStatData(ino_t i, dev_t d, mode_t mo, time_t m, off_t s) |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1026 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1027 | }; |
| 1028 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1029 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1030 | public: |
| 1031 | typedef const char *external_key_type; |
| 1032 | typedef const char *internal_key_type; |
| 1033 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1034 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1035 | |
| 1036 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1037 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1041 | |
| 1042 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1043 | return strcmp(a, b) == 0; |
| 1044 | } |
| 1045 | |
| 1046 | static std::pair<unsigned, unsigned> |
| 1047 | ReadKeyDataLength(const unsigned char*& d) { |
| 1048 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1049 | unsigned DataLen = (unsigned) *d++; |
| 1050 | return std::make_pair(KeyLen + 1, DataLen); |
| 1051 | } |
| 1052 | |
| 1053 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1054 | return (const char *)d; |
| 1055 | } |
| 1056 | |
| 1057 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1058 | unsigned /*DataLen*/) { |
| 1059 | using namespace clang::io; |
| 1060 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1061 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1062 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1063 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1064 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1065 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1066 | return data_type(ino, dev, mode, mtime, size); |
| 1067 | } |
| 1068 | }; |
| 1069 | |
| 1070 | /// \brief stat() cache for precompiled headers. |
| 1071 | /// |
| 1072 | /// This cache is very similar to the stat cache used by pretokenized |
| 1073 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1074 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1075 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1076 | CacheTy *Cache; |
| 1077 | |
| 1078 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1079 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1080 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1081 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1082 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1083 | Cache = CacheTy::Create(Buckets, Base); |
| 1084 | } |
| 1085 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1086 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1087 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1088 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1089 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1090 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1091 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1092 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1093 | // 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] | 1094 | if (I == Cache->end()) { |
| 1095 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1096 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1097 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1098 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1099 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1100 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1101 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1102 | StatBuf.st_ino = Data.ino; |
| 1103 | StatBuf.st_dev = Data.dev; |
| 1104 | StatBuf.st_mtime = Data.mtime; |
| 1105 | StatBuf.st_mode = Data.mode; |
| 1106 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1107 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1108 | } |
| 1109 | }; |
| 1110 | } // end anonymous namespace |
| 1111 | |
| 1112 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1113 | /// \brief Read a source manager block |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1114 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1115 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1116 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1117 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1118 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1119 | // Set the source-location entry cursor to the current position in |
| 1120 | // the stream. This cursor will be used to read the contents of the |
| 1121 | // source manager block initially, and then lazily read |
| 1122 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1123 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1124 | |
| 1125 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1126 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1127 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1128 | return Failure; |
| 1129 | } |
| 1130 | |
| 1131 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1132 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1133 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1134 | return Failure; |
| 1135 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1136 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1137 | RecordData Record; |
| 1138 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1139 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1140 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1141 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1142 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1143 | return Failure; |
| 1144 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1145 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1146 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1147 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1148 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1149 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1150 | SLocEntryCursor.ReadSubBlockID(); |
| 1151 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1152 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1153 | return Failure; |
| 1154 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1155 | continue; |
| 1156 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1157 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1158 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1159 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1160 | continue; |
| 1161 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1162 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1163 | // Read a record. |
| 1164 | const char *BlobStart; |
| 1165 | unsigned BlobLen; |
| 1166 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1167 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1168 | default: // Default behavior: ignore. |
| 1169 | break; |
| 1170 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1171 | case SM_LINE_TABLE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1172 | if (ParseLineTable(F, Record)) |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1173 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1174 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1175 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1176 | case SM_SLOC_FILE_ENTRY: |
| 1177 | case SM_SLOC_BUFFER_ENTRY: |
| 1178 | case SM_SLOC_INSTANTIATION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1179 | // Once we hit one of the source location entries, we're done. |
| 1180 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1181 | } |
| 1182 | } |
| 1183 | } |
| 1184 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1185 | /// \brief If a header file is not found at the path that we expect it to be |
| 1186 | /// and the PCH file was moved from its original location, try to resolve the |
| 1187 | /// file by assuming that header+PCH were moved together and the header is in |
| 1188 | /// the same place relative to the PCH. |
| 1189 | static std::string |
| 1190 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1191 | const std::string &OriginalDir, |
| 1192 | const std::string &CurrDir) { |
| 1193 | assert(OriginalDir != CurrDir && |
| 1194 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1195 | using namespace llvm::sys; |
| 1196 | llvm::SmallString<128> filePath(Filename); |
| 1197 | fs::make_absolute(filePath); |
| 1198 | assert(path::is_absolute(OriginalDir)); |
| 1199 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1200 | |
| 1201 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1202 | fileDirE = path::end(path::parent_path(filePath)); |
| 1203 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1204 | origDirE = path::end(OriginalDir); |
| 1205 | // Skip the common path components from filePath and OriginalDir. |
| 1206 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1207 | *fileDirI == *origDirI) { |
| 1208 | ++fileDirI; |
| 1209 | ++origDirI; |
| 1210 | } |
| 1211 | for (; origDirI != origDirE; ++origDirI) |
| 1212 | path::append(currPCHPath, ".."); |
| 1213 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1214 | path::append(currPCHPath, path::filename(Filename)); |
| 1215 | return currPCHPath.str(); |
| 1216 | } |
| 1217 | |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1218 | /// \brief Get a cursor that's correctly positioned for reading the source |
| 1219 | /// location entry with the given ID. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1220 | ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1221 | assert(ID != 0 && ID <= TotalNumSLocEntries && |
| 1222 | "SLocCursorForID should only be called for real IDs."); |
| 1223 | |
| 1224 | ID -= 1; |
| 1225 | PerFileData *F = 0; |
| 1226 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1227 | F = Chain[N - I - 1]; |
| 1228 | if (ID < F->LocalNumSLocEntries) |
| 1229 | break; |
| 1230 | ID -= F->LocalNumSLocEntries; |
| 1231 | } |
| 1232 | assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); |
| 1233 | |
| 1234 | F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1235 | return F; |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1238 | /// \brief Read in the source location entry with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1239 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1240 | if (ID == 0) |
| 1241 | return Success; |
| 1242 | |
| 1243 | if (ID > TotalNumSLocEntries) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1244 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1245 | return Failure; |
| 1246 | } |
| 1247 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1248 | PerFileData *F = SLocCursorForID(ID); |
| 1249 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1250 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1251 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1252 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1253 | if (Code == llvm::bitc::END_BLOCK || |
| 1254 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1255 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1256 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1257 | return Failure; |
| 1258 | } |
| 1259 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1260 | RecordData Record; |
| 1261 | const char *BlobStart; |
| 1262 | unsigned BlobLen; |
| 1263 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1264 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1265 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1266 | return Failure; |
| 1267 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1268 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1269 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1270 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1271 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1272 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1273 | OriginalDir != CurrentDir) { |
| 1274 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1275 | OriginalDir, |
| 1276 | CurrentDir); |
| 1277 | if (!resolved.empty()) |
| 1278 | File = FileMgr.getFile(resolved); |
| 1279 | } |
Axel Naumann | 0433116 | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1280 | if (File == 0) |
| 1281 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1282 | (time_t)Record[5]); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1283 | if (File == 0) { |
| 1284 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1285 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1286 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1287 | Error(ErrorStr.c_str()); |
| 1288 | return Failure; |
| 1289 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1290 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1291 | if (Record.size() < 6) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1292 | Error("source location entry is incorrect"); |
| 1293 | return Failure; |
| 1294 | } |
| 1295 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1296 | if (!DisableValidation && |
| 1297 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1298 | #if !defined(LLVM_ON_WIN32) |
| 1299 | // In our regression testing, the Windows file system seems to |
| 1300 | // have inconsistent modification times that sometimes |
| 1301 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1302 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1303 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1304 | )) { |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1305 | Diag(diag::err_fe_pch_file_modified) |
| 1306 | << Filename; |
| 1307 | return Failure; |
| 1308 | } |
| 1309 | |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1310 | FileID FID = SourceMgr.createFileID(File, ReadSourceLocation(*F, Record[1]), |
| 1311 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1312 | ID, Record[0]); |
| 1313 | if (Record[3]) |
| 1314 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1315 | .setHasLineDirectives(); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1316 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1317 | break; |
| 1318 | } |
| 1319 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1320 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1321 | const char *Name = BlobStart; |
| 1322 | unsigned Offset = Record[0]; |
| 1323 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1324 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1325 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1326 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1327 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1328 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1329 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1330 | return Failure; |
| 1331 | } |
| 1332 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1333 | llvm::MemoryBuffer *Buffer |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1334 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1335 | Name); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1336 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1337 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1338 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1339 | PCHPredefinesBlock Block = { |
| 1340 | BufferID, |
| 1341 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1342 | }; |
| 1343 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1344 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1345 | |
| 1346 | break; |
| 1347 | } |
| 1348 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1349 | case SM_SLOC_INSTANTIATION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1350 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1351 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1352 | ReadSourceLocation(*F, Record[2]), |
| 1353 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1354 | Record[4], |
| 1355 | ID, |
| 1356 | Record[0]); |
| 1357 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1358 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | return Success; |
| 1362 | } |
| 1363 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1364 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1365 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1366 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1367 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1368 | unsigned BlockID) { |
| 1369 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1370 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1371 | return Failure; |
| 1372 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1373 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1374 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1375 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1376 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1377 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1378 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1379 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1380 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1381 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1382 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1383 | Cursor.ReadAbbrevRecord(); |
| 1384 | } |
| 1385 | } |
| 1386 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1387 | PreprocessedEntity *ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1388 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1389 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1390 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1391 | // Keep track of where we are in the stream, then jump back there |
| 1392 | // after reading this macro. |
| 1393 | SavedStreamPosition SavedPosition(Stream); |
| 1394 | |
| 1395 | Stream.JumpToBit(Offset); |
| 1396 | RecordData Record; |
| 1397 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1398 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1399 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1400 | while (true) { |
| 1401 | unsigned Code = Stream.ReadCode(); |
| 1402 | switch (Code) { |
| 1403 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1404 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1405 | |
| 1406 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1407 | // No known subblocks, always skip them. |
| 1408 | Stream.ReadSubBlockID(); |
| 1409 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1410 | Error("malformed block record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1411 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1412 | } |
| 1413 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1414 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1415 | case llvm::bitc::DEFINE_ABBREV: |
| 1416 | Stream.ReadAbbrevRecord(); |
| 1417 | continue; |
| 1418 | default: break; |
| 1419 | } |
| 1420 | |
| 1421 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1422 | const char *BlobStart = 0; |
| 1423 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1424 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1425 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1426 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1427 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1428 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1429 | case PP_MACRO_OBJECT_LIKE: |
| 1430 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1431 | // If we already have a macro, that means that we've hit the end |
| 1432 | // of the definition of the macro we were looking for. We're |
| 1433 | // done. |
| 1434 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1435 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1436 | |
| 1437 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1438 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1439 | Error("macro must have a name in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1440 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1441 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1442 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1443 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1444 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1445 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1446 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1447 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1448 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1449 | unsigned NextIndex = 3; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1450 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1451 | // Decode function-like macro info. |
| 1452 | bool isC99VarArgs = Record[3]; |
| 1453 | bool isGNUVarArgs = Record[4]; |
| 1454 | MacroArgs.clear(); |
| 1455 | unsigned NumArgs = Record[5]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1456 | NextIndex = 6 + NumArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1457 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1458 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1459 | |
| 1460 | // Install function-like macro info. |
| 1461 | MI->setIsFunctionLike(); |
| 1462 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1463 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1464 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1465 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1469 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1470 | |
| 1471 | // Remember that we saw this macro last so that we add the tokens that |
| 1472 | // form its body to it. |
| 1473 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1474 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1475 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1476 | // We have a macro definition. Load it now. |
| 1477 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1478 | getMacroDefinition(Record[NextIndex])); |
| 1479 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1480 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1481 | ++NumMacrosRead; |
| 1482 | break; |
| 1483 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1484 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1485 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1486 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1487 | // erroneous, just pretend we didn't see this. |
| 1488 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1489 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1490 | Token Tok; |
| 1491 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1492 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1493 | Tok.setLength(Record[1]); |
| 1494 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1495 | Tok.setIdentifierInfo(II); |
| 1496 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1497 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1498 | Macro->AddTokenToBody(Tok); |
| 1499 | break; |
| 1500 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1501 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1502 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1503 | |
| 1504 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1507 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(PerFileData &F) { |
| 1508 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1509 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1510 | switch (Code) { |
| 1511 | case llvm::bitc::END_BLOCK: |
| 1512 | return 0; |
| 1513 | |
| 1514 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1515 | Error("unexpected subblock record in preprocessor detail block"); |
| 1516 | return 0; |
| 1517 | |
| 1518 | case llvm::bitc::DEFINE_ABBREV: |
| 1519 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1520 | return 0; |
| 1521 | |
| 1522 | default: |
| 1523 | break; |
| 1524 | } |
| 1525 | |
| 1526 | if (!PP->getPreprocessingRecord()) { |
| 1527 | Error("no preprocessing record"); |
| 1528 | return 0; |
| 1529 | } |
| 1530 | |
| 1531 | // Read the record. |
| 1532 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1533 | const char *BlobStart = 0; |
| 1534 | unsigned BlobLen = 0; |
| 1535 | RecordData Record; |
| 1536 | PreprocessorDetailRecordTypes RecType = |
| 1537 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1538 | Code, Record, BlobStart, BlobLen); |
| 1539 | switch (RecType) { |
| 1540 | case PPD_MACRO_INSTANTIATION: { |
| 1541 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1542 | return PE; |
| 1543 | |
| 1544 | MacroInstantiation *MI |
| 1545 | = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), |
| 1546 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1547 | ReadSourceLocation(F, Record[2])), |
| 1548 | getMacroDefinition(Record[4])); |
| 1549 | PPRec.SetPreallocatedEntity(Record[0], MI); |
| 1550 | return MI; |
| 1551 | } |
| 1552 | |
| 1553 | case PPD_MACRO_DEFINITION: { |
| 1554 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1555 | return PE; |
| 1556 | |
| 1557 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
| 1558 | Error("out-of-bounds macro definition record"); |
| 1559 | return 0; |
| 1560 | } |
| 1561 | |
| 1562 | // Decode the identifier info and then check again; if the macro is |
| 1563 | // still defined and associated with the identifier, |
| 1564 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1565 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1566 | MacroDefinition *MD |
| 1567 | = new (PPRec) MacroDefinition(II, |
| 1568 | ReadSourceLocation(F, Record[5]), |
| 1569 | SourceRange( |
| 1570 | ReadSourceLocation(F, Record[2]), |
| 1571 | ReadSourceLocation(F, Record[3]))); |
| 1572 | |
| 1573 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1574 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
| 1575 | |
| 1576 | if (DeserializationListener) |
| 1577 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1578 | } |
| 1579 | |
| 1580 | return MacroDefinitionsLoaded[Record[1] - 1]; |
| 1581 | } |
| 1582 | |
| 1583 | case PPD_INCLUSION_DIRECTIVE: { |
| 1584 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1585 | return PE; |
| 1586 | |
| 1587 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1588 | const FileEntry *File |
| 1589 | = PP->getFileManager().getFile(llvm::StringRef(FullFileNameStart, |
| 1590 | BlobLen - Record[3])); |
| 1591 | |
| 1592 | // FIXME: Stable encoding |
| 1593 | InclusionDirective::InclusionKind Kind |
| 1594 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1595 | InclusionDirective *ID |
| 1596 | = new (PPRec) InclusionDirective(PPRec, Kind, |
| 1597 | llvm::StringRef(BlobStart, Record[3]), |
| 1598 | Record[4], |
| 1599 | File, |
| 1600 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1601 | ReadSourceLocation(F, Record[2]))); |
| 1602 | PPRec.SetPreallocatedEntity(Record[0], ID); |
| 1603 | return ID; |
| 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | Error("invalid offset in preprocessor detail block"); |
| 1608 | return 0; |
| 1609 | } |
| 1610 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1611 | namespace { |
| 1612 | /// \brief Trait class used to search the on-disk hash table containing all of |
| 1613 | /// the header search information. |
| 1614 | /// |
| 1615 | /// The on-disk hash table contains a mapping from each header path to |
| 1616 | /// information about that header (how many times it has been included, its |
| 1617 | /// controlling macro, etc.). Note that we actually hash based on the |
| 1618 | /// filename, and support "deep" comparisons of file names based on current |
| 1619 | /// inode numbers, so that the search can cope with non-normalized path names |
| 1620 | /// and symlinks. |
| 1621 | class HeaderFileInfoTrait { |
| 1622 | const char *SearchPath; |
| 1623 | struct stat SearchPathStatBuf; |
| 1624 | llvm::Optional<int> SearchPathStatResult; |
| 1625 | |
| 1626 | int StatSimpleCache(const char *Path, struct stat *StatBuf) { |
| 1627 | if (Path == SearchPath) { |
| 1628 | if (!SearchPathStatResult) |
| 1629 | SearchPathStatResult = stat(Path, &SearchPathStatBuf); |
| 1630 | |
| 1631 | *StatBuf = SearchPathStatBuf; |
| 1632 | return *SearchPathStatResult; |
| 1633 | } |
| 1634 | |
| 1635 | return stat(Path, StatBuf); |
| 1636 | } |
| 1637 | |
| 1638 | public: |
| 1639 | typedef const char *external_key_type; |
| 1640 | typedef const char *internal_key_type; |
| 1641 | |
| 1642 | typedef HeaderFileInfo data_type; |
| 1643 | |
| 1644 | HeaderFileInfoTrait(const char *SearchPath = 0) : SearchPath(SearchPath) { } |
| 1645 | |
| 1646 | static unsigned ComputeHash(const char *path) { |
| 1647 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1648 | } |
| 1649 | |
| 1650 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1651 | |
| 1652 | bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1653 | if (strcmp(a, b) == 0) |
| 1654 | return true; |
| 1655 | |
| 1656 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1657 | return false; |
| 1658 | |
| 1659 | // The file names match, but the path names don't. stat() the files to |
| 1660 | // see if they are the same. |
| 1661 | struct stat StatBufA, StatBufB; |
| 1662 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1663 | return false; |
| 1664 | |
| 1665 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1666 | } |
| 1667 | |
| 1668 | static std::pair<unsigned, unsigned> |
| 1669 | ReadKeyDataLength(const unsigned char*& d) { |
| 1670 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1671 | unsigned DataLen = (unsigned) *d++; |
| 1672 | return std::make_pair(KeyLen + 1, DataLen); |
| 1673 | } |
| 1674 | |
| 1675 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1676 | return (const char *)d; |
| 1677 | } |
| 1678 | |
| 1679 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1680 | unsigned DataLen) { |
| 1681 | const unsigned char *End = d + DataLen; |
| 1682 | using namespace clang::io; |
| 1683 | HeaderFileInfo HFI; |
| 1684 | unsigned Flags = *d++; |
| 1685 | HFI.isImport = (Flags >> 3) & 0x01; |
| 1686 | HFI.DirInfo = (Flags >> 1) & 0x03; |
| 1687 | HFI.Resolved = Flags & 0x01; |
| 1688 | HFI.NumIncludes = ReadUnalignedLE16(d); |
| 1689 | HFI.ControllingMacroID = ReadUnalignedLE32(d); |
| 1690 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1691 | (void)End; |
| 1692 | |
| 1693 | // This HeaderFileInfo was externally loaded. |
| 1694 | HFI.External = true; |
| 1695 | return HFI; |
| 1696 | } |
| 1697 | }; |
| 1698 | } |
| 1699 | |
| 1700 | /// \brief The on-disk hash table used for the global method pool. |
| 1701 | typedef OnDiskChainedHashTable<HeaderFileInfoTrait> |
| 1702 | HeaderFileInfoLookupTable; |
| 1703 | |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1704 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F, |
| 1705 | uint64_t Offset) { |
| 1706 | // Note that this identifier has a macro definition. |
| 1707 | II->setHasMacroDefinition(true); |
| 1708 | |
| 1709 | // Adjust the offset based on our position in the chain. |
| 1710 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1711 | if (Chain[I] == &F) |
| 1712 | break; |
| 1713 | |
| 1714 | Offset += Chain[I]->SizeInBits; |
| 1715 | } |
| 1716 | |
| 1717 | UnreadMacroRecordOffsets[II] = Offset; |
| 1718 | } |
| 1719 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1720 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1721 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1722 | PerFileData &F = *Chain[N - I - 1]; |
| 1723 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1724 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1725 | // If there was no preprocessor block, skip this file. |
| 1726 | if (!MacroCursor.getBitStreamReader()) |
| 1727 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1728 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1729 | llvm::BitstreamCursor Cursor = MacroCursor; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1730 | Cursor.JumpToBit(F.MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1731 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1732 | RecordData Record; |
| 1733 | while (true) { |
| 1734 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1735 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1736 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1737 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1738 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1739 | // No known subblocks, always skip them. |
| 1740 | Cursor.ReadSubBlockID(); |
| 1741 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1742 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1743 | return; |
| 1744 | } |
| 1745 | continue; |
| 1746 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1747 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1748 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1749 | Cursor.ReadAbbrevRecord(); |
| 1750 | continue; |
| 1751 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1752 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1753 | // Read a record. |
| 1754 | const char *BlobStart; |
| 1755 | unsigned BlobLen; |
| 1756 | Record.clear(); |
| 1757 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1758 | default: // Default behavior: ignore. |
| 1759 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1760 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1761 | case PP_MACRO_OBJECT_LIKE: |
| 1762 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1763 | DecodeIdentifierInfo(Record[0]); |
| 1764 | break; |
| 1765 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1766 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1767 | // Ignore tokens. |
| 1768 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1769 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1770 | } |
| 1771 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1772 | |
| 1773 | // Drain the unread macro-record offsets map. |
| 1774 | while (!UnreadMacroRecordOffsets.empty()) |
| 1775 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1776 | } |
| 1777 | |
| 1778 | void ASTReader::LoadMacroDefinition( |
| 1779 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1780 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
| 1781 | PerFileData *F = 0; |
| 1782 | uint64_t Offset = Pos->second; |
| 1783 | UnreadMacroRecordOffsets.erase(Pos); |
| 1784 | |
| 1785 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1786 | if (Offset < Chain[I]->SizeInBits) { |
| 1787 | F = Chain[I]; |
| 1788 | break; |
| 1789 | } |
| 1790 | |
| 1791 | Offset -= Chain[I]->SizeInBits; |
| 1792 | } |
| 1793 | if (!F) { |
| 1794 | Error("Malformed macro record offset"); |
| 1795 | return; |
| 1796 | } |
| 1797 | |
| 1798 | ReadMacroRecord(*F, Offset); |
| 1799 | } |
| 1800 | |
| 1801 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1802 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1803 | = UnreadMacroRecordOffsets.find(II); |
| 1804 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1805 | } |
| 1806 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1807 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1808 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1809 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1810 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1811 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1812 | unsigned Index = ID - 1; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1813 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1814 | PerFileData &F = *Chain[N - I - 1]; |
| 1815 | if (Index < F.LocalNumMacroDefinitions) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1816 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 1817 | F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]); |
| 1818 | LoadPreprocessedEntity(F); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1819 | break; |
| 1820 | } |
| 1821 | Index -= F.LocalNumMacroDefinitions; |
| 1822 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1823 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1826 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1829 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1830 | /// not an absolute path, add the system root to the beginning of the file |
| 1831 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1832 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1833 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1834 | if (!RelocatablePCH) |
| 1835 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1836 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1837 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1838 | return; |
| 1839 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1840 | if (isysroot == 0) { |
| 1841 | // If no system root was given, default to '/' |
| 1842 | Filename.insert(Filename.begin(), '/'); |
| 1843 | return; |
| 1844 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1845 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1846 | unsigned Length = strlen(isysroot); |
| 1847 | if (isysroot[Length - 1] != '/') |
| 1848 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1849 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1850 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1851 | } |
| 1852 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1853 | ASTReader::ASTReadResult |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1854 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1855 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1856 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1857 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1858 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1859 | return Failure; |
| 1860 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1861 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1862 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1863 | RecordData Record; |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1864 | bool First = true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1865 | while (!Stream.AtEndOfStream()) { |
| 1866 | unsigned Code = Stream.ReadCode(); |
| 1867 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1868 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1869 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1870 | return Failure; |
| 1871 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1872 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1873 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1877 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1878 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1879 | // We lazily load the decls block, but we want to set up the |
| 1880 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1881 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1882 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1883 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1884 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1885 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1886 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1887 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1888 | return Failure; |
| 1889 | } |
| 1890 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1891 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1892 | case DECL_UPDATES_BLOCK_ID: |
| 1893 | if (Stream.SkipBlock()) { |
| 1894 | Error("malformed block record in AST file"); |
| 1895 | return Failure; |
| 1896 | } |
| 1897 | break; |
| 1898 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1899 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1900 | F.MacroCursor = Stream; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1901 | if (PP) |
| 1902 | PP->setExternalSource(this); |
| 1903 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1904 | if (Stream.SkipBlock() || |
| 1905 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1906 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1907 | return Failure; |
| 1908 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1909 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1910 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1911 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1912 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1913 | F.PreprocessorDetailCursor = Stream; |
| 1914 | if (Stream.SkipBlock() || |
| 1915 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1916 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1917 | Error("malformed preprocessor detail record in AST file"); |
| 1918 | return Failure; |
| 1919 | } |
| 1920 | F.PreprocessorDetailStartOffset |
| 1921 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 1922 | break; |
| 1923 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1924 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1925 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1926 | case Success: |
| 1927 | break; |
| 1928 | |
| 1929 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1930 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1931 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1932 | |
| 1933 | case IgnorePCH: |
| 1934 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1935 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1936 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1937 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1938 | First = false; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1939 | continue; |
| 1940 | } |
| 1941 | |
| 1942 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1943 | Stream.ReadAbbrevRecord(); |
| 1944 | continue; |
| 1945 | } |
| 1946 | |
| 1947 | // Read and process a record. |
| 1948 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1949 | const char *BlobStart = 0; |
| 1950 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1951 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1952 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1953 | default: // Default behavior: ignore. |
| 1954 | break; |
| 1955 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1956 | case METADATA: { |
| 1957 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1958 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1959 | : diag::warn_pch_version_too_new); |
| 1960 | return IgnorePCH; |
| 1961 | } |
| 1962 | |
| 1963 | RelocatablePCH = Record[4]; |
| 1964 | if (Listener) { |
| 1965 | std::string TargetTriple(BlobStart, BlobLen); |
| 1966 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1967 | return IgnorePCH; |
| 1968 | } |
| 1969 | break; |
| 1970 | } |
| 1971 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1972 | case CHAINED_METADATA: { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1973 | if (!First) { |
| 1974 | Error("CHAINED_METADATA is not first record in block"); |
| 1975 | return Failure; |
| 1976 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1977 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1978 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1979 | : diag::warn_pch_version_too_new); |
| 1980 | return IgnorePCH; |
| 1981 | } |
| 1982 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 1983 | // Load the chained file, which is always a PCH file. |
| 1984 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1985 | case Failure: return Failure; |
| 1986 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1987 | case IgnorePCH: return IgnorePCH; |
| 1988 | case Success: break; |
| 1989 | } |
| 1990 | break; |
| 1991 | } |
| 1992 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1993 | case TYPE_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1994 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1995 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1996 | return Failure; |
| 1997 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1998 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1999 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2000 | break; |
| 2001 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2002 | case DECL_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2003 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2004 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2005 | return Failure; |
| 2006 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2007 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 2008 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2009 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2010 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2011 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2012 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2013 | /* No visible information */ 0, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2014 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 2015 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2016 | }; |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2017 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 2018 | .push_back(Info); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2019 | break; |
| 2020 | } |
| 2021 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2022 | case UPDATE_VISIBLE: { |
| 2023 | serialization::DeclID ID = Record[0]; |
| 2024 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 2025 | (const unsigned char *)BlobStart + Record[1], |
| 2026 | (const unsigned char *)BlobStart, |
| 2027 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2028 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2029 | DeclContextInfo Info = { |
| 2030 | Table, /* No lexical inforamtion */ 0, 0 |
| 2031 | }; |
| 2032 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 2033 | } else |
| 2034 | PendingVisibleUpdates[ID].push_back(Table); |
| 2035 | break; |
| 2036 | } |
| 2037 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2038 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2039 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 2040 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2041 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2042 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 2043 | Latest > FirstLatestDeclIDs[First]) && |
| 2044 | "The new latest is supposed to come after the previous latest"); |
| 2045 | FirstLatestDeclIDs[First] = Latest; |
| 2046 | } |
| 2047 | break; |
| 2048 | } |
| 2049 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2050 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2051 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2052 | return IgnorePCH; |
| 2053 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2054 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2055 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2056 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2057 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2058 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2059 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2060 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2061 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2062 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2063 | if (PP) |
| 2064 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2065 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2066 | break; |
| 2067 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2068 | case IDENTIFIER_OFFSET: |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2069 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2070 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2071 | return Failure; |
| 2072 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2073 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2074 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2075 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2076 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2077 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2078 | // Optimization for the first block. |
| 2079 | if (ExternalDefinitions.empty()) |
| 2080 | ExternalDefinitions.swap(Record); |
| 2081 | else |
| 2082 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 2083 | Record.begin(), Record.end()); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2084 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2085 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2086 | case SPECIAL_TYPES: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2087 | // Optimization for the first block |
| 2088 | if (SpecialTypes.empty()) |
| 2089 | SpecialTypes.swap(Record); |
| 2090 | else |
| 2091 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2092 | break; |
| 2093 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2094 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2095 | TotalNumStatements += Record[0]; |
| 2096 | TotalNumMacros += Record[1]; |
| 2097 | TotalLexicalDeclContexts += Record[2]; |
| 2098 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2099 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2100 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2101 | case TENTATIVE_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2102 | // Optimization for the first block. |
| 2103 | if (TentativeDefinitions.empty()) |
| 2104 | TentativeDefinitions.swap(Record); |
| 2105 | else |
| 2106 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 2107 | Record.begin(), Record.end()); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2108 | break; |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2109 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2110 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2111 | // Optimization for the first block. |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2112 | if (UnusedFileScopedDecls.empty()) |
| 2113 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2114 | else |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2115 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 2116 | Record.begin(), Record.end()); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2117 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2118 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2119 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2120 | // Later blocks overwrite earlier ones. |
| 2121 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2122 | break; |
| 2123 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2124 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2125 | // Optimization for the first block. |
| 2126 | if (LocallyScopedExternalDecls.empty()) |
| 2127 | LocallyScopedExternalDecls.swap(Record); |
| 2128 | else |
| 2129 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 2130 | Record.begin(), Record.end()); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2131 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2132 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2133 | case SELECTOR_OFFSETS: |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2134 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2135 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2136 | break; |
| 2137 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2138 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2139 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2140 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2141 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2142 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2143 | F.SelectorLookupTableData + Record[0], |
| 2144 | F.SelectorLookupTableData, |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2145 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2146 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2147 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2148 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2149 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2150 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2151 | break; |
| 2152 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2153 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2154 | if (!Record.empty() && Listener) |
| 2155 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2156 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2157 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2158 | case SOURCE_LOCATION_OFFSETS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2159 | F.SLocOffsets = (const uint32_t *)BlobStart; |
| 2160 | F.LocalNumSLocEntries = Record[0]; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2161 | F.LocalSLocSize = Record[1]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2162 | break; |
| 2163 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2164 | case SOURCE_LOCATION_PRELOADS: |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2165 | if (PreloadSLocEntries.empty()) |
| 2166 | PreloadSLocEntries.swap(Record); |
| 2167 | else |
| 2168 | PreloadSLocEntries.insert(PreloadSLocEntries.end(), |
| 2169 | Record.begin(), Record.end()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2170 | break; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2171 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2172 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2173 | if (!DisableStatCache) { |
| 2174 | ASTStatCache *MyStatCache = |
| 2175 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2176 | (const unsigned char *)BlobStart, |
| 2177 | NumStatHits, NumStatMisses); |
| 2178 | FileMgr.addStatCache(MyStatCache); |
| 2179 | F.StatCache = MyStatCache; |
| 2180 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2181 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2182 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2183 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2184 | case EXT_VECTOR_DECLS: |
Sebastian Redl | a9f2368 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 2185 | // Optimization for the first block. |
| 2186 | if (ExtVectorDecls.empty()) |
| 2187 | ExtVectorDecls.swap(Record); |
| 2188 | else |
| 2189 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 2190 | Record.begin(), Record.end()); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2191 | break; |
| 2192 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2193 | case VTABLE_USES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2194 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2195 | VTableUses.swap(Record); |
| 2196 | break; |
| 2197 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2198 | case DYNAMIC_CLASSES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2199 | // Optimization for the first block. |
| 2200 | if (DynamicClasses.empty()) |
| 2201 | DynamicClasses.swap(Record); |
| 2202 | else |
| 2203 | DynamicClasses.insert(DynamicClasses.end(), |
| 2204 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2205 | break; |
| 2206 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2207 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2208 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2209 | break; |
| 2210 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2211 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2212 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2213 | SemaDeclRefs.swap(Record); |
| 2214 | break; |
| 2215 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2216 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2217 | // 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] | 2218 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2219 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2220 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2221 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2222 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2223 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2224 | case ORIGINAL_PCH_DIR: |
| 2225 | // The primary AST will be the last to get here, so it will be the one |
| 2226 | // that's used. |
| 2227 | OriginalDir.assign(BlobStart, BlobLen); |
| 2228 | break; |
| 2229 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2230 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2231 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2232 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 2233 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2234 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2235 | return IgnorePCH; |
| 2236 | } |
| 2237 | break; |
| 2238 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2239 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2240 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2241 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2242 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2243 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2244 | break; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2245 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2246 | case DECL_UPDATE_OFFSETS: { |
| 2247 | if (Record.size() % 2 != 0) { |
| 2248 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2249 | return Failure; |
| 2250 | } |
| 2251 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
| 2252 | DeclUpdateOffsets[static_cast<DeclID>(Record[I])] |
| 2253 | .push_back(std::make_pair(&F, Record[I+1])); |
| 2254 | break; |
| 2255 | } |
| 2256 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2257 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2258 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2259 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2260 | return Failure; |
| 2261 | } |
| 2262 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2263 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2264 | std::make_pair(&F, Record[I+1]); |
| 2265 | break; |
| 2266 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2267 | |
| 2268 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2269 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2270 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2271 | return Failure; |
| 2272 | } |
| 2273 | |
| 2274 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2275 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
| 2276 | break; |
| 2277 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2278 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2279 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2280 | if (Record.size() % 2 != 0) { |
| 2281 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2282 | return Failure; |
| 2283 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2284 | if (PragmaDiagMappings.empty()) |
| 2285 | PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2286 | else |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2287 | PragmaDiagMappings.insert(PragmaDiagMappings.end(), |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2288 | Record.begin(), Record.end()); |
| 2289 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2290 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2291 | case CUDA_SPECIAL_DECL_REFS: |
| 2292 | // Later tables overwrite earlier ones. |
| 2293 | CUDASpecialDeclRefs.swap(Record); |
| 2294 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2295 | |
| 2296 | case HEADER_SEARCH_TABLE: |
| 2297 | F.HeaderFileInfoTableData = BlobStart; |
| 2298 | F.LocalNumHeaderFileInfos = Record[1]; |
| 2299 | if (Record[0]) { |
| 2300 | F.HeaderFileInfoTable |
| 2301 | = HeaderFileInfoLookupTable::Create( |
| 2302 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 2303 | (const unsigned char *)F.HeaderFileInfoTableData); |
| 2304 | if (PP) |
| 2305 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2306 | } |
| 2307 | break; |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame^] | 2308 | |
| 2309 | case FP_PRAGMA_OPTIONS: |
| 2310 | // Later tables overwrite earlier ones. |
| 2311 | FPPragmaOptions.swap(Record); |
| 2312 | break; |
| 2313 | |
| 2314 | case OPENCL_EXTENSIONS: |
| 2315 | // Later tables overwrite earlier ones. |
| 2316 | OpenCLExtensions.swap(Record); |
| 2317 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2318 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2319 | First = false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2320 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2321 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2322 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2325 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2326 | ASTFileType Type) { |
| 2327 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2328 | case Failure: return Failure; |
| 2329 | case IgnorePCH: return IgnorePCH; |
| 2330 | case Success: break; |
| 2331 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2332 | |
| 2333 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2334 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2335 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2336 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2337 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2338 | TotalNumSelectors = 0; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2339 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2340 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2341 | NextSLocOffset += Chain[I]->LocalSLocSize; |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2342 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2343 | TotalNumTypes += Chain[I]->LocalNumTypes; |
| 2344 | TotalNumDecls += Chain[I]->LocalNumDecls; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2345 | TotalNumPreallocatedPreprocessingEntities += |
| 2346 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2347 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2348 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2349 | } |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2350 | SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset); |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2351 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2352 | TypesLoaded.resize(TotalNumTypes); |
| 2353 | DeclsLoaded.resize(TotalNumDecls); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2354 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2355 | if (PP) { |
| 2356 | if (TotalNumIdentifiers > 0) |
| 2357 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2358 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2359 | if (!PP->getPreprocessingRecord()) |
| 2360 | PP->createPreprocessingRecord(); |
| 2361 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2362 | TotalNumPreallocatedPreprocessingEntities); |
| 2363 | } |
| 2364 | } |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2365 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2366 | // Preload SLocEntries. |
| 2367 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2368 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2369 | if (Result != Success) |
| 2370 | return Result; |
| 2371 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2372 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2373 | // Check the predefines buffers. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2374 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2375 | return IgnorePCH; |
| 2376 | |
| 2377 | if (PP) { |
| 2378 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2379 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2380 | // loaded into the IdentifierTable before we intercepted the |
| 2381 | // creation of identifiers. Iterate through the list of known |
| 2382 | // identifiers and determine whether we have to establish |
| 2383 | // preprocessor definitions or top-level identifier declaration |
| 2384 | // chains for those identifiers. |
| 2385 | // |
| 2386 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2387 | // since de-serializing declarations or macro definitions can add |
| 2388 | // new entries into the identifier table, invalidating the |
| 2389 | // iterators. |
| 2390 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2391 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2392 | IdEnd = PP->getIdentifierTable().end(); |
| 2393 | Id != IdEnd; ++Id) |
| 2394 | Identifiers.push_back(Id->second); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2395 | // We need to search the tables in all files. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2396 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2397 | ASTIdentifierLookupTable *IdTable |
| 2398 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2399 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2400 | // ones. |
| 2401 | if (!IdTable) |
| 2402 | continue; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2403 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2404 | IdentifierInfo *II = Identifiers[I]; |
| 2405 | // Look in the on-disk hash tables for an entry for this identifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2406 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2407 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2408 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2409 | if (Pos == IdTable->end()) |
| 2410 | continue; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2411 | |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2412 | // Dereferencing the iterator has the effect of populating the |
| 2413 | // IdentifierInfo node with the various declarations it needs. |
| 2414 | (void)*Pos; |
| 2415 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2416 | } |
| 2417 | } |
| 2418 | |
| 2419 | if (Context) |
| 2420 | InitializeContext(*Context); |
| 2421 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2422 | if (DeserializationListener) |
| 2423 | DeserializationListener->ReaderInitialized(this); |
| 2424 | |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2425 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2426 | // the source manager to the file source file from which the preamble was |
| 2427 | // built. This is the only valid way to use a precompiled preamble. |
| 2428 | if (Type == Preamble) { |
| 2429 | SourceLocation Loc |
| 2430 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2431 | if (Loc.isValid()) { |
| 2432 | std::pair<FileID, unsigned> Decomposed = SourceMgr.getDecomposedLoc(Loc); |
| 2433 | SourceMgr.SetPreambleFileID(Decomposed.first); |
| 2434 | } |
| 2435 | } |
| 2436 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2437 | return Success; |
| 2438 | } |
| 2439 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2440 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2441 | ASTFileType Type) { |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2442 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2443 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2444 | PerFileData &F = *Chain.back(); |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2445 | if (Prev) |
| 2446 | Prev->NextInSource = &F; |
| 2447 | else |
| 2448 | FirstInSource = &F; |
| 2449 | F.Loaders.push_back(Prev); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2450 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2451 | // Set the AST file name. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2452 | F.FileName = FileName; |
| 2453 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2454 | if (FileName != "-") { |
| 2455 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2456 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2457 | } |
| 2458 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2459 | // Open the AST file. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2460 | // |
| 2461 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2462 | std::string ErrStr; |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 2463 | llvm::error_code ec; |
| 2464 | if (FileName == "-") { |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 2465 | ec = llvm::MemoryBuffer::getSTDIN(F.Buffer); |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 2466 | if (ec) |
| 2467 | ErrStr = ec.message(); |
| 2468 | } else |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2469 | F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr)); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2470 | if (!F.Buffer) { |
| 2471 | Error(ErrStr.c_str()); |
| 2472 | return IgnorePCH; |
| 2473 | } |
| 2474 | |
| 2475 | // Initialize the stream |
| 2476 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2477 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2478 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2479 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2480 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2481 | |
| 2482 | // Sniff for the signature. |
| 2483 | if (Stream.Read(8) != 'C' || |
| 2484 | Stream.Read(8) != 'P' || |
| 2485 | Stream.Read(8) != 'C' || |
| 2486 | Stream.Read(8) != 'H') { |
| 2487 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2488 | return Failure; |
| 2489 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2490 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2491 | while (!Stream.AtEndOfStream()) { |
| 2492 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2493 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2494 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2495 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2496 | return Failure; |
| 2497 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2498 | |
| 2499 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2500 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2501 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2502 | switch (BlockID) { |
| 2503 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2504 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2505 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2506 | return Failure; |
| 2507 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2508 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2509 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2510 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2511 | case Success: |
| 2512 | break; |
| 2513 | |
| 2514 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2515 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2516 | |
| 2517 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2518 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2519 | // AST block, skipping subblocks, to see if there are other |
| 2520 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2521 | |
| 2522 | // Clear out any preallocated source location entries, so that |
| 2523 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2524 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2525 | |
| 2526 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2527 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2528 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2529 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2530 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2531 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2532 | break; |
| 2533 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2534 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2535 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2536 | return Failure; |
| 2537 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2538 | break; |
| 2539 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2540 | } |
| 2541 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2542 | return Success; |
| 2543 | } |
| 2544 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2545 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2546 | PP = &pp; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2547 | |
| 2548 | unsigned TotalNum = 0; |
| 2549 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2550 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2551 | if (TotalNum) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2552 | if (!PP->getPreprocessingRecord()) |
| 2553 | PP->createPreprocessingRecord(); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2554 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2555 | } |
| 2556 | } |
| 2557 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2558 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2559 | Context = &Ctx; |
| 2560 | assert(Context && "Passed null context!"); |
| 2561 | |
| 2562 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2563 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2564 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2565 | PP->setExternalSource(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2566 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2567 | |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2568 | // If we have an update block for the TU waiting, we have to add it before |
| 2569 | // deserializing the decl. |
| 2570 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2571 | if (DCU != DeclContextOffsets.end()) { |
| 2572 | // Insertion could invalidate map, so grab vector. |
| 2573 | DeclContextInfos T; |
| 2574 | T.swap(DCU->second); |
| 2575 | DeclContextOffsets.erase(DCU); |
| 2576 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2577 | } |
| 2578 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2579 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2580 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2581 | |
| 2582 | // Load the special types. |
| 2583 | Context->setBuiltinVaListType( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2584 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2585 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2586 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2587 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2588 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2589 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2590 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2591 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2592 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2593 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2594 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2595 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2596 | if (unsigned FastEnum |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2597 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2598 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2599 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2600 | QualType FileType = GetType(File); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2601 | if (FileType.isNull()) { |
| 2602 | Error("FILE type is NULL"); |
| 2603 | return; |
| 2604 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2605 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2606 | Context->setFILEDecl(Typedef->getDecl()); |
| 2607 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2608 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2609 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2610 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2611 | return; |
| 2612 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2613 | Context->setFILEDecl(Tag->getDecl()); |
| 2614 | } |
| 2615 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2616 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2617 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2618 | if (Jmp_bufType.isNull()) { |
| 2619 | Error("jmp_bug type is NULL"); |
| 2620 | return; |
| 2621 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2622 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2623 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2624 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2625 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2626 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2627 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2628 | return; |
| 2629 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2630 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2631 | } |
| 2632 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2633 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2634 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2635 | if (Sigjmp_bufType.isNull()) { |
| 2636 | Error("sigjmp_buf type is NULL"); |
| 2637 | return; |
| 2638 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2639 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2640 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2641 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2642 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2643 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2644 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2645 | } |
| 2646 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2647 | if (unsigned ObjCIdRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2648 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2649 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2650 | if (unsigned ObjCClassRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2651 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2652 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2653 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2654 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2655 | if (unsigned String |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2656 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2657 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2658 | if (unsigned ObjCSelRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2659 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2660 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2661 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2662 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2663 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2664 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2665 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2666 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2667 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2668 | |
| 2669 | // If there were any CUDA special declarations, deserialize them. |
| 2670 | if (!CUDASpecialDeclRefs.empty()) { |
| 2671 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 2672 | Context->setcudaConfigureCallDecl( |
| 2673 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2674 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2677 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2678 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2679 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2680 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2681 | FileManager &FileMgr, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2682 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2683 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2684 | std::string ErrStr; |
| 2685 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2686 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2687 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2688 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2689 | return std::string(); |
| 2690 | } |
| 2691 | |
| 2692 | // Initialize the stream |
| 2693 | llvm::BitstreamReader StreamFile; |
| 2694 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2695 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2696 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2697 | Stream.init(StreamFile); |
| 2698 | |
| 2699 | // Sniff for the signature. |
| 2700 | if (Stream.Read(8) != 'C' || |
| 2701 | Stream.Read(8) != 'P' || |
| 2702 | Stream.Read(8) != 'C' || |
| 2703 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2704 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2705 | return std::string(); |
| 2706 | } |
| 2707 | |
| 2708 | RecordData Record; |
| 2709 | while (!Stream.AtEndOfStream()) { |
| 2710 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2711 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2712 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2713 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2714 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2715 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2716 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2717 | case AST_BLOCK_ID: |
| 2718 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2719 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2720 | return std::string(); |
| 2721 | } |
| 2722 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2723 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2724 | default: |
| 2725 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2726 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2727 | return std::string(); |
| 2728 | } |
| 2729 | break; |
| 2730 | } |
| 2731 | continue; |
| 2732 | } |
| 2733 | |
| 2734 | if (Code == llvm::bitc::END_BLOCK) { |
| 2735 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2736 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2737 | return std::string(); |
| 2738 | } |
| 2739 | continue; |
| 2740 | } |
| 2741 | |
| 2742 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2743 | Stream.ReadAbbrevRecord(); |
| 2744 | continue; |
| 2745 | } |
| 2746 | |
| 2747 | Record.clear(); |
| 2748 | const char *BlobStart = 0; |
| 2749 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2750 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2751 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2752 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2753 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2754 | |
| 2755 | return std::string(); |
| 2756 | } |
| 2757 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2758 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2759 | /// structure. |
| 2760 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2761 | /// This routine parses the language options from the AST file and then gives |
| 2762 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2763 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2764 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2765 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2766 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2767 | if (Listener) { |
| 2768 | LangOptions LangOpts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2769 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2770 | #define PARSE_LANGOPT(Option) \ |
| 2771 | LangOpts.Option = Record[Idx]; \ |
| 2772 | ++Idx |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2773 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2774 | unsigned Idx = 0; |
| 2775 | PARSE_LANGOPT(Trigraphs); |
| 2776 | PARSE_LANGOPT(BCPLComment); |
| 2777 | PARSE_LANGOPT(DollarIdents); |
| 2778 | PARSE_LANGOPT(AsmPreprocessor); |
| 2779 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2780 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2781 | PARSE_LANGOPT(ImplicitInt); |
| 2782 | PARSE_LANGOPT(Digraphs); |
| 2783 | PARSE_LANGOPT(HexFloats); |
| 2784 | PARSE_LANGOPT(C99); |
| 2785 | PARSE_LANGOPT(Microsoft); |
| 2786 | PARSE_LANGOPT(CPlusPlus); |
| 2787 | PARSE_LANGOPT(CPlusPlus0x); |
| 2788 | PARSE_LANGOPT(CXXOperatorNames); |
| 2789 | PARSE_LANGOPT(ObjC1); |
| 2790 | PARSE_LANGOPT(ObjC2); |
| 2791 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 2792 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 2793 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 2794 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 2795 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2796 | PARSE_LANGOPT(PascalStrings); |
| 2797 | PARSE_LANGOPT(WritableStrings); |
| 2798 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2799 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2800 | PARSE_LANGOPT(Exceptions); |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 2801 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 2802 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2803 | PARSE_LANGOPT(NeXTRuntime); |
| 2804 | PARSE_LANGOPT(Freestanding); |
| 2805 | PARSE_LANGOPT(NoBuiltin); |
| 2806 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 2807 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2808 | PARSE_LANGOPT(Blocks); |
| 2809 | PARSE_LANGOPT(EmitAllDecls); |
| 2810 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2811 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 2812 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2813 | PARSE_LANGOPT(HeinousExtensions); |
| 2814 | PARSE_LANGOPT(Optimize); |
| 2815 | PARSE_LANGOPT(OptimizeSize); |
| 2816 | PARSE_LANGOPT(Static); |
| 2817 | PARSE_LANGOPT(PICLevel); |
| 2818 | PARSE_LANGOPT(GNUInline); |
| 2819 | PARSE_LANGOPT(NoInline); |
| 2820 | PARSE_LANGOPT(AccessControl); |
| 2821 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2822 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | b1bdced | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 2823 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2824 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2825 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 2826 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2827 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2828 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2829 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 2830 | PARSE_LANGOPT(CUDA); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2831 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame^] | 2832 | PARSE_LANGOPT(DefaultFPContract); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2833 | // FIXME: Missing ElideConstructors?! |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2834 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2835 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2836 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2837 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2838 | |
| 2839 | return false; |
| 2840 | } |
| 2841 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2842 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2843 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2844 | PerFileData &F = *Chain[I]; |
| 2845 | if (!F.PreprocessorDetailCursor.getBitStreamReader()) |
| 2846 | continue; |
| 2847 | |
| 2848 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 2849 | F.PreprocessorDetailCursor.JumpToBit(F.PreprocessorDetailStartOffset); |
| 2850 | while (LoadPreprocessedEntity(F)) { } |
| 2851 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2852 | } |
| 2853 | |
Douglas Gregor | 0a48029 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 2854 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2855 | PerFileData *F = 0; |
| 2856 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2857 | if (Offset < Chain[I]->SizeInBits) { |
| 2858 | F = Chain[I]; |
| 2859 | break; |
| 2860 | } |
| 2861 | |
| 2862 | Offset -= Chain[I]->SizeInBits; |
| 2863 | } |
| 2864 | |
| 2865 | if (!F) { |
| 2866 | Error("Malformed preprocessed entity offset"); |
| 2867 | return 0; |
| 2868 | } |
| 2869 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2870 | // Keep track of where we are in the stream, then jump back there |
| 2871 | // after reading this entity. |
| 2872 | SavedStreamPosition SavedPosition(F->PreprocessorDetailCursor); |
| 2873 | F->PreprocessorDetailCursor.JumpToBit(Offset); |
| 2874 | return LoadPreprocessedEntity(*F); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2877 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
| 2878 | HeaderFileInfoTrait Trait(FE->getName()); |
| 2879 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2880 | PerFileData &F = *Chain[I]; |
| 2881 | HeaderFileInfoLookupTable *Table |
| 2882 | = static_cast<HeaderFileInfoLookupTable *>(F.HeaderFileInfoTable); |
| 2883 | if (!Table) |
| 2884 | continue; |
| 2885 | |
| 2886 | // Look in the on-disk hash table for an entry for this file name. |
| 2887 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE->getName(), |
| 2888 | &Trait); |
| 2889 | if (Pos == Table->end()) |
| 2890 | continue; |
| 2891 | |
| 2892 | HeaderFileInfo HFI = *Pos; |
| 2893 | if (Listener) |
| 2894 | Listener->ReadHeaderFileInfo(HFI, FE->getUID()); |
| 2895 | |
| 2896 | return HFI; |
| 2897 | } |
| 2898 | |
| 2899 | return HeaderFileInfo(); |
| 2900 | } |
| 2901 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2902 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2903 | unsigned Idx = 0; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2904 | while (Idx < PragmaDiagMappings.size()) { |
| 2905 | SourceLocation |
| 2906 | Loc = SourceLocation::getFromRawEncoding(PragmaDiagMappings[Idx++]); |
| 2907 | while (1) { |
| 2908 | assert(Idx < PragmaDiagMappings.size() && |
| 2909 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 2910 | if (Idx >= PragmaDiagMappings.size()) |
| 2911 | break; // Something is messed up but at least avoid infinite loop in |
| 2912 | // release build. |
| 2913 | unsigned DiagID = PragmaDiagMappings[Idx++]; |
| 2914 | if (DiagID == (unsigned)-1) |
| 2915 | break; // no more diag/map pairs for this location. |
| 2916 | diag::Mapping Map = (diag::Mapping)PragmaDiagMappings[Idx++]; |
| 2917 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 2918 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2919 | } |
| 2920 | } |
| 2921 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2922 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2923 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2924 | PerFileData *F = 0; |
| 2925 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2926 | F = Chain[N - I - 1]; |
| 2927 | if (Index < F->LocalNumTypes) |
| 2928 | break; |
| 2929 | Index -= F->LocalNumTypes; |
| 2930 | } |
| 2931 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2932 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2936 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2937 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 2938 | /// routine actually reads the record corresponding to the type at the given |
| 2939 | /// location. It is a helper routine for GetType, which deals with reading type |
| 2940 | /// IDs. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2941 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2942 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2943 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2944 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2945 | // Keep track of where we are in the stream, then jump back there |
| 2946 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2947 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2948 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 2949 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 2950 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2951 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 2952 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2953 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2954 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2955 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2956 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2957 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 2958 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2959 | if (Record.size() != 2) { |
| 2960 | Error("Incorrect encoding of extended qualifier type"); |
| 2961 | return QualType(); |
| 2962 | } |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2963 | QualType Base = GetType(Record[0]); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2964 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 2965 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2966 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2967 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2968 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2969 | if (Record.size() != 1) { |
| 2970 | Error("Incorrect encoding of complex type"); |
| 2971 | return QualType(); |
| 2972 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2973 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2974 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2975 | } |
| 2976 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2977 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2978 | if (Record.size() != 1) { |
| 2979 | Error("Incorrect encoding of pointer type"); |
| 2980 | return QualType(); |
| 2981 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2982 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2983 | return Context->getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2986 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2987 | if (Record.size() != 1) { |
| 2988 | Error("Incorrect encoding of block pointer type"); |
| 2989 | return QualType(); |
| 2990 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2991 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2992 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2993 | } |
| 2994 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2995 | case TYPE_LVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2996 | if (Record.size() != 1) { |
| 2997 | Error("Incorrect encoding of lvalue reference type"); |
| 2998 | return QualType(); |
| 2999 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3000 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3001 | return Context->getLValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3002 | } |
| 3003 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3004 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3005 | if (Record.size() != 1) { |
| 3006 | Error("Incorrect encoding of rvalue reference type"); |
| 3007 | return QualType(); |
| 3008 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3009 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3010 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3011 | } |
| 3012 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3013 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3014 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3015 | Error("Incorrect encoding of member pointer type"); |
| 3016 | return QualType(); |
| 3017 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3018 | QualType PointeeType = GetType(Record[0]); |
| 3019 | QualType ClassType = GetType(Record[1]); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3020 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3021 | return QualType(); |
| 3022 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3023 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3024 | } |
| 3025 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3026 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3027 | QualType ElementType = GetType(Record[0]); |
| 3028 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3029 | unsigned IndexTypeQuals = Record[2]; |
| 3030 | unsigned Idx = 3; |
| 3031 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3032 | return Context->getConstantArrayType(ElementType, Size, |
| 3033 | ASM, IndexTypeQuals); |
| 3034 | } |
| 3035 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3036 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3037 | QualType ElementType = GetType(Record[0]); |
| 3038 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3039 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3040 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3041 | } |
| 3042 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3043 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3044 | QualType ElementType = GetType(Record[0]); |
| 3045 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3046 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3047 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3048 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 3049 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3050 | ASM, IndexTypeQuals, |
| 3051 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3052 | } |
| 3053 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3054 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3055 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3056 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3057 | return QualType(); |
| 3058 | } |
| 3059 | |
| 3060 | QualType ElementType = GetType(Record[0]); |
| 3061 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3062 | unsigned VecKind = Record[2]; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3063 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3064 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3065 | } |
| 3066 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3067 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3068 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3069 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3070 | return QualType(); |
| 3071 | } |
| 3072 | |
| 3073 | QualType ElementType = GetType(Record[0]); |
| 3074 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3075 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3076 | } |
| 3077 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3078 | case TYPE_FUNCTION_NO_PROTO: { |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3079 | if (Record.size() != 4) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3080 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3081 | return QualType(); |
| 3082 | } |
| 3083 | QualType ResultType = GetType(Record[0]); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3084 | FunctionType::ExtInfo Info(Record[1], Record[2], (CallingConv)Record[3]); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 3085 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3086 | } |
| 3087 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3088 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3089 | QualType ResultType = GetType(Record[0]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3090 | |
| 3091 | FunctionProtoType::ExtProtoInfo EPI; |
| 3092 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
| 3093 | /*regparm*/ Record[2], |
| 3094 | static_cast<CallingConv>(Record[3])); |
| 3095 | |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3096 | unsigned Idx = 4; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3097 | unsigned NumParams = Record[Idx++]; |
| 3098 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 3099 | for (unsigned I = 0; I != NumParams; ++I) |
| 3100 | ParamTypes.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3101 | |
| 3102 | EPI.Variadic = Record[Idx++]; |
| 3103 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3104 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3105 | EPI.HasExceptionSpec = Record[Idx++]; |
| 3106 | EPI.HasAnyExceptionSpec = Record[Idx++]; |
| 3107 | EPI.NumExceptions = Record[Idx++]; |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 3108 | llvm::SmallVector<QualType, 2> Exceptions; |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3109 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 3110 | Exceptions.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3111 | EPI.Exceptions = Exceptions.data(); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 3112 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3113 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3114 | } |
| 3115 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3116 | case TYPE_UNRESOLVED_USING: |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3117 | return Context->getTypeDeclType( |
| 3118 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 3119 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3120 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3121 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3122 | Error("incorrect encoding of typedef type"); |
| 3123 | return QualType(); |
| 3124 | } |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3125 | TypedefDecl *Decl = cast<TypedefDecl>(GetDecl(Record[0])); |
| 3126 | QualType Canonical = GetType(Record[1]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3127 | if (!Canonical.isNull()) |
| 3128 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3129 | return Context->getTypedefType(Decl, Canonical); |
| 3130 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3131 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3132 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3133 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3134 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3135 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3136 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3137 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3138 | return QualType(); |
| 3139 | } |
| 3140 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3141 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3142 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3143 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3144 | case TYPE_DECLTYPE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3145 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3146 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3147 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3148 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3149 | Error("incorrect encoding of record type"); |
| 3150 | return QualType(); |
| 3151 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3152 | bool IsDependent = Record[0]; |
| 3153 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3154 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3155 | return T; |
| 3156 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3157 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3158 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3159 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3160 | Error("incorrect encoding of enum type"); |
| 3161 | return QualType(); |
| 3162 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3163 | bool IsDependent = Record[0]; |
| 3164 | QualType T = Context->getEnumType(cast<EnumDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3165 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3166 | return T; |
| 3167 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3168 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3169 | case TYPE_ATTRIBUTED: { |
| 3170 | if (Record.size() != 3) { |
| 3171 | Error("incorrect encoding of attributed type"); |
| 3172 | return QualType(); |
| 3173 | } |
| 3174 | QualType modifiedType = GetType(Record[0]); |
| 3175 | QualType equivalentType = GetType(Record[1]); |
| 3176 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 3177 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 3178 | } |
| 3179 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3180 | case TYPE_PAREN: { |
| 3181 | if (Record.size() != 1) { |
| 3182 | Error("incorrect encoding of paren type"); |
| 3183 | return QualType(); |
| 3184 | } |
| 3185 | QualType InnerType = GetType(Record[0]); |
| 3186 | return Context->getParenType(InnerType); |
| 3187 | } |
| 3188 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3189 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3190 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3191 | Error("incorrect encoding of pack expansion type"); |
| 3192 | return QualType(); |
| 3193 | } |
| 3194 | QualType Pattern = GetType(Record[0]); |
| 3195 | if (Pattern.isNull()) |
| 3196 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3197 | llvm::Optional<unsigned> NumExpansions; |
| 3198 | if (Record[1]) |
| 3199 | NumExpansions = Record[1] - 1; |
| 3200 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3201 | } |
| 3202 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3203 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3204 | unsigned Idx = 0; |
| 3205 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3206 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3207 | QualType NamedType = GetType(Record[Idx++]); |
| 3208 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3209 | } |
| 3210 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3211 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3212 | unsigned Idx = 0; |
| 3213 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3214 | return Context->getObjCInterfaceType(ItfD); |
| 3215 | } |
| 3216 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3217 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3218 | unsigned Idx = 0; |
| 3219 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3220 | unsigned NumProtos = Record[Idx++]; |
| 3221 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 3222 | for (unsigned I = 0; I != NumProtos; ++I) |
| 3223 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3224 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3225 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3226 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3227 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3228 | unsigned Idx = 0; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3229 | QualType Pointee = GetType(Record[Idx++]); |
| 3230 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3231 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3232 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3233 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3234 | unsigned Idx = 0; |
| 3235 | QualType Parm = GetType(Record[Idx++]); |
| 3236 | QualType Replacement = GetType(Record[Idx++]); |
| 3237 | return |
| 3238 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3239 | Replacement); |
| 3240 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3241 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3242 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3243 | unsigned Idx = 0; |
| 3244 | QualType Parm = GetType(Record[Idx++]); |
| 3245 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3246 | return Context->getSubstTemplateTypeParmPackType( |
| 3247 | cast<TemplateTypeParmType>(Parm), |
| 3248 | ArgPack); |
| 3249 | } |
| 3250 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3251 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3252 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 3253 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3254 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3255 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3256 | return |
| 3257 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3258 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3259 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3260 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3261 | unsigned Idx = 0; |
| 3262 | unsigned Depth = Record[Idx++]; |
| 3263 | unsigned Index = Record[Idx++]; |
| 3264 | bool Pack = Record[Idx++]; |
| 3265 | IdentifierInfo *Name = GetIdentifierInfo(Record, Idx); |
| 3266 | return Context->getTemplateTypeParmType(Depth, Index, Pack, Name); |
| 3267 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3268 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3269 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3270 | unsigned Idx = 0; |
| 3271 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3272 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3273 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3274 | QualType Canon = GetType(Record[Idx++]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3275 | if (!Canon.isNull()) |
| 3276 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3277 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3278 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3279 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3280 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3281 | unsigned Idx = 0; |
| 3282 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3283 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3284 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
| 3285 | unsigned NumArgs = Record[Idx++]; |
| 3286 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 3287 | Args.reserve(NumArgs); |
| 3288 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3289 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3290 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3291 | Args.size(), Args.data()); |
| 3292 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3293 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3294 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3295 | unsigned Idx = 0; |
| 3296 | |
| 3297 | // ArrayType |
| 3298 | QualType ElementType = GetType(Record[Idx++]); |
| 3299 | ArrayType::ArraySizeModifier ASM |
| 3300 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3301 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3302 | |
| 3303 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3304 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3305 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3306 | |
| 3307 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3308 | IndexTypeQuals, Brackets); |
| 3309 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3310 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3311 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3312 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3313 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3314 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3315 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3316 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3317 | QualType Canon = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3318 | QualType T; |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3319 | if (Canon.isNull()) |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3320 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3321 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3322 | else |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3323 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
| 3324 | Args.size(), Canon); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3325 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3326 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3327 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3328 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3329 | // Suppress a GCC warning |
| 3330 | return QualType(); |
| 3331 | } |
| 3332 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3333 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3334 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3335 | ASTReader::PerFileData &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3336 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3337 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3338 | unsigned &Idx; |
| 3339 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3340 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3341 | unsigned &I) { |
| 3342 | return Reader.ReadSourceLocation(F, R, I); |
| 3343 | } |
| 3344 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3345 | public: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3346 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3347 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3348 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3349 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3350 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3351 | // We want compile-time assurance that we've enumerated all of |
| 3352 | // these, so unfortunately we have to declare them first, then |
| 3353 | // define them out-of-line. |
| 3354 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3355 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3356 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3357 | #include "clang/AST/TypeLocNodes.def" |
| 3358 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3359 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3360 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3361 | }; |
| 3362 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3363 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3364 | // nothing to do |
| 3365 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3366 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3367 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3368 | if (TL.needsExtraLocalData()) { |
| 3369 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3370 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3371 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3372 | TL.setModeAttr(Record[Idx++]); |
| 3373 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3374 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3375 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3376 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3377 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3378 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3379 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3380 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3381 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3382 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3383 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3384 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3385 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3386 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3387 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3388 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3389 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3390 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3391 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3392 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3393 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3394 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3395 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3396 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3397 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3398 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3399 | TL.setSizeExpr(0); |
| 3400 | } |
| 3401 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3402 | VisitArrayTypeLoc(TL); |
| 3403 | } |
| 3404 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3405 | VisitArrayTypeLoc(TL); |
| 3406 | } |
| 3407 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3408 | VisitArrayTypeLoc(TL); |
| 3409 | } |
| 3410 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3411 | DependentSizedArrayTypeLoc TL) { |
| 3412 | VisitArrayTypeLoc(TL); |
| 3413 | } |
| 3414 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3415 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3416 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3417 | } |
| 3418 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3419 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3420 | } |
| 3421 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3422 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3423 | } |
| 3424 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3425 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3426 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3427 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3428 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | 86acc2a | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 3429 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3430 | } |
| 3431 | } |
| 3432 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3433 | VisitFunctionTypeLoc(TL); |
| 3434 | } |
| 3435 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3436 | VisitFunctionTypeLoc(TL); |
| 3437 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3438 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3439 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3440 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3441 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3442 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3443 | } |
| 3444 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3445 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3446 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3447 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3448 | } |
| 3449 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3450 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3451 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3452 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3453 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3454 | } |
| 3455 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3456 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3457 | } |
| 3458 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3459 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3460 | } |
| 3461 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3462 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3463 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3464 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3465 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3466 | if (TL.hasAttrOperand()) { |
| 3467 | SourceRange range; |
| 3468 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3469 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3470 | TL.setAttrOperandParensRange(range); |
| 3471 | } |
| 3472 | if (TL.hasAttrExprOperand()) { |
| 3473 | if (Record[Idx++]) |
| 3474 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3475 | else |
| 3476 | TL.setAttrExprOperand(0); |
| 3477 | } else if (TL.hasAttrEnumOperand()) |
| 3478 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3479 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3480 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3481 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3482 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3483 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3484 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3485 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3486 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3487 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3488 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3489 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3490 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3491 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3492 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3493 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3494 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3495 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3496 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3497 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3498 | Reader.GetTemplateArgumentLocInfo(F, |
| 3499 | TL.getTypePtr()->getArg(i).getKind(), |
| 3500 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3501 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3502 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3503 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3504 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3505 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3506 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3507 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3508 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3509 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3510 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3511 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3512 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3513 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3514 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3515 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3516 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3517 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3518 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3519 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3520 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3521 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3522 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3523 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3524 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3525 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3526 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3527 | Reader.GetTemplateArgumentLocInfo(F, |
| 3528 | TL.getTypePtr()->getArg(I).getKind(), |
| 3529 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3530 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3531 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3532 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3533 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3534 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3535 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3536 | } |
| 3537 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3538 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3539 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3540 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3541 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3542 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3543 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3544 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3545 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3546 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3547 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3548 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3549 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3550 | unsigned &Idx) { |
| 3551 | QualType InfoTy = GetType(Record[Idx++]); |
| 3552 | if (InfoTy.isNull()) |
| 3553 | return 0; |
| 3554 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3555 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3556 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3557 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3558 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3559 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3560 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3561 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3562 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3563 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3564 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3565 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3566 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3567 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3568 | switch ((PredefinedTypeIDs)Index) { |
| 3569 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3570 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3571 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3572 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3573 | case PREDEF_TYPE_CHAR_U_ID: |
| 3574 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3575 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3576 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3577 | break; |
| 3578 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3579 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3580 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3581 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3582 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3583 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3584 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3585 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3586 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3587 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3588 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3589 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3590 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3591 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3592 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3593 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3594 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3595 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
| 3596 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
| 3597 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3598 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3599 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3600 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3601 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3602 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3603 | } |
| 3604 | |
| 3605 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3606 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3607 | } |
| 3608 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3609 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3610 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3611 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3612 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3613 | if (TypesLoaded[Index].isNull()) |
| 3614 | return QualType(); |
| 3615 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3616 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3617 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3618 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3619 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3620 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3621 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3622 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3623 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3624 | } |
| 3625 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3626 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3627 | return MakeTypeID(T, |
| 3628 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3629 | } |
| 3630 | |
| 3631 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3632 | if (T.isNull()) |
| 3633 | return TypeIdx(); |
| 3634 | assert(!T.getLocalFastQualifiers()); |
| 3635 | |
| 3636 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3637 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3638 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3639 | // If the type didn't come from the AST file use a specially marked index |
| 3640 | // so that any hash/key comparison fail since no such index is stored |
| 3641 | // in a AST file. |
| 3642 | if (I == TypeIdxs.end()) |
| 3643 | return TypeIdx(-1); |
| 3644 | return I->second; |
| 3645 | } |
| 3646 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3647 | unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const { |
| 3648 | unsigned Result = 0; |
| 3649 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 3650 | Result += Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3651 | |
| 3652 | return Result; |
| 3653 | } |
| 3654 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3655 | TemplateArgumentLocInfo |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3656 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3657 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3658 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3659 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3660 | switch (Kind) { |
| 3661 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3662 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3663 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3664 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3665 | case TemplateArgument::Template: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3666 | SourceRange QualifierRange = ReadSourceRange(F, Record, Index); |
| 3667 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3668 | return TemplateArgumentLocInfo(QualifierRange, TemplateNameLoc, |
| 3669 | SourceLocation()); |
| 3670 | } |
| 3671 | case TemplateArgument::TemplateExpansion: { |
| 3672 | SourceRange QualifierRange = ReadSourceRange(F, Record, Index); |
| 3673 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3674 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
| 3675 | return TemplateArgumentLocInfo(QualifierRange, TemplateNameLoc, |
| 3676 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3677 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3678 | case TemplateArgument::Null: |
| 3679 | case TemplateArgument::Integral: |
| 3680 | case TemplateArgument::Declaration: |
| 3681 | case TemplateArgument::Pack: |
| 3682 | return TemplateArgumentLocInfo(); |
| 3683 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3684 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3685 | return TemplateArgumentLocInfo(); |
| 3686 | } |
| 3687 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3688 | TemplateArgumentLoc |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3689 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3690 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3691 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3692 | |
| 3693 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3694 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3695 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3696 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3697 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3698 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3699 | } |
| 3700 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3701 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3702 | return GetDecl(ID); |
| 3703 | } |
| 3704 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3705 | uint64_t |
| 3706 | ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) { |
| 3707 | if (ID == 0) |
| 3708 | return 0; |
| 3709 | |
| 3710 | --ID; |
| 3711 | uint64_t Offset = 0; |
| 3712 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3713 | if (ID < Chain[I]->LocalNumCXXBaseSpecifiers) |
| 3714 | return Offset + Chain[I]->CXXBaseSpecifiersOffsets[ID]; |
| 3715 | |
| 3716 | ID -= Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3717 | Offset += Chain[I]->SizeInBits; |
| 3718 | } |
| 3719 | |
| 3720 | assert(false && "CXXBaseSpecifiers not found"); |
| 3721 | return 0; |
| 3722 | } |
| 3723 | |
| 3724 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 3725 | // Figure out which AST file contains this offset. |
| 3726 | PerFileData *F = 0; |
| 3727 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3728 | if (Offset < Chain[I]->SizeInBits) { |
| 3729 | F = Chain[I]; |
| 3730 | break; |
| 3731 | } |
| 3732 | |
| 3733 | Offset -= Chain[I]->SizeInBits; |
| 3734 | } |
| 3735 | |
| 3736 | if (!F) { |
| 3737 | Error("Malformed AST file: C++ base specifiers at impossible offset"); |
| 3738 | return 0; |
| 3739 | } |
| 3740 | |
| 3741 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3742 | SavedStreamPosition SavedPosition(Cursor); |
| 3743 | Cursor.JumpToBit(Offset); |
| 3744 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3745 | RecordData Record; |
| 3746 | unsigned Code = Cursor.ReadCode(); |
| 3747 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 3748 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 3749 | Error("Malformed AST file: missing C++ base specifiers"); |
| 3750 | return 0; |
| 3751 | } |
| 3752 | |
| 3753 | unsigned Idx = 0; |
| 3754 | unsigned NumBases = Record[Idx++]; |
| 3755 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 3756 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 3757 | for (unsigned I = 0; I != NumBases; ++I) |
| 3758 | Bases[I] = ReadCXXBaseSpecifier(*F, Record, Idx); |
| 3759 | return Bases; |
| 3760 | } |
| 3761 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3762 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3763 | if (!DeclsLoaded[0]) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 3764 | ReadDeclRecord(0, 1); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3765 | if (DeserializationListener) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3766 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3767 | } |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 3768 | |
| 3769 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 3770 | } |
| 3771 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3772 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3773 | if (ID == 0) |
| 3774 | return 0; |
| 3775 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3776 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3777 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3778 | return 0; |
| 3779 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3780 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3781 | unsigned Index = ID - 1; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3782 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3783 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3784 | if (DeserializationListener) |
| 3785 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3786 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3787 | |
| 3788 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3789 | } |
| 3790 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3791 | /// \brief Resolve the offset of a statement into a statement. |
| 3792 | /// |
| 3793 | /// This operation will read a new statement from the external |
| 3794 | /// source each time it is called, and is meant to be used via a |
| 3795 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3796 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 3797 | // Switch case IDs are per Decl. |
| 3798 | ClearSwitchCaseIDs(); |
| 3799 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3800 | // Offset here is a global offset across the entire chain. |
| 3801 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3802 | PerFileData &F = *Chain[N - I - 1]; |
| 3803 | if (Offset < F.SizeInBits) { |
| 3804 | // Since we know that this statement is part of a decl, make sure to use |
| 3805 | // the decl cursor to read it. |
| 3806 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3807 | return ReadStmtFromStream(F); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3808 | } |
| 3809 | Offset -= F.SizeInBits; |
| 3810 | } |
| 3811 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 3812 | } |
| 3813 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3814 | bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3815 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3816 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3817 | assert(DC->hasExternalLexicalStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3818 | "DeclContext has no lexical decls in storage"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3819 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3820 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 3821 | // at least. |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3822 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 3823 | // so make a copy of the vector. |
| 3824 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3825 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3826 | I != E; ++I) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3827 | // IDs can be 0 if this context doesn't contain declarations. |
| 3828 | if (!I->LexicalDecls) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3829 | continue; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3830 | |
| 3831 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3832 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 3833 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 3834 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 3835 | continue; |
| 3836 | |
| 3837 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3838 | assert(D && "Null decl in lexical decls"); |
| 3839 | Decls.push_back(D); |
| 3840 | } |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3841 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3842 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3843 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3844 | return false; |
| 3845 | } |
| 3846 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3847 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3848 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3849 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3850 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3851 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3852 | if (!Name) |
| 3853 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 3854 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3855 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3856 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 8b12273 | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 3857 | // 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] | 3858 | // and namespaces. For any given name, the last available results replace |
| 3859 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3860 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3861 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3862 | I != E; ++I) { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3863 | if (!I->NameLookupTableData) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3864 | continue; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3865 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3866 | ASTDeclContextNameLookupTable *LookupTable = |
| 3867 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3868 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 3869 | if (Pos == LookupTable->end()) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3870 | continue; |
| 3871 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3872 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 3873 | for (; Data.first != Data.second; ++Data.first) |
| 3874 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3875 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3876 | } |
| 3877 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3878 | ++NumVisibleDeclContextsRead; |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3879 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3880 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3881 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3882 | } |
| 3883 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 3884 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 3885 | assert(DC->hasExternalVisibleStorage() && |
| 3886 | "DeclContext has no visible decls in storage"); |
| 3887 | |
| 3888 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 3889 | // There might be visible decls in multiple parts of the chain, for the TU |
| 3890 | // and namespaces. |
| 3891 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 3892 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3893 | I != E; ++I) { |
| 3894 | if (!I->NameLookupTableData) |
| 3895 | continue; |
| 3896 | |
| 3897 | ASTDeclContextNameLookupTable *LookupTable = |
| 3898 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3899 | for (ASTDeclContextNameLookupTable::item_iterator |
| 3900 | ItemI = LookupTable->item_begin(), |
| 3901 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 3902 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 3903 | = *ItemI; |
| 3904 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 3905 | Decls.clear(); |
| 3906 | for (; Data.first != Data.second; ++Data.first) |
| 3907 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 3908 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 3909 | } |
| 3910 | } |
| 3911 | } |
| 3912 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3913 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3914 | assert(Consumer); |
| 3915 | while (!InterestingDecls.empty()) { |
| 3916 | DeclGroupRef DG(InterestingDecls.front()); |
| 3917 | InterestingDecls.pop_front(); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3918 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3919 | } |
| 3920 | } |
| 3921 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3922 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 3923 | this->Consumer = Consumer; |
| 3924 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3925 | if (!Consumer) |
| 3926 | return; |
| 3927 | |
| 3928 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3929 | // Force deserialization of this decl, which will cause it to be queued for |
| 3930 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 3931 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3932 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 3933 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3934 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3935 | } |
| 3936 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3937 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3938 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3939 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3940 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3941 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3942 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3943 | unsigned NumDeclsLoaded |
| 3944 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 3945 | (Decl *)0); |
| 3946 | unsigned NumIdentifiersLoaded |
| 3947 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 3948 | IdentifiersLoaded.end(), |
| 3949 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3950 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3951 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 3952 | SelectorsLoaded.end(), |
| 3953 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 3954 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3955 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 3956 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 3957 | if (TotalNumSLocEntries) |
| 3958 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 3959 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 3960 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3961 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3962 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3963 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 3964 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 3965 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3966 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3967 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 3968 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3969 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3970 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3971 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 3972 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3973 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3974 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3975 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 3976 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3977 | if (TotalNumStatements) |
| 3978 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 3979 | NumStatementsRead, TotalNumStatements, |
| 3980 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 3981 | if (TotalNumMacros) |
| 3982 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 3983 | NumMacrosRead, TotalNumMacros, |
| 3984 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 3985 | if (TotalLexicalDeclContexts) |
| 3986 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 3987 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 3988 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 3989 | * 100)); |
| 3990 | if (TotalVisibleDeclContexts) |
| 3991 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 3992 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 3993 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 3994 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3995 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3996 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3997 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 3998 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3999 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4000 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4001 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4002 | std::fprintf(stderr, "\n"); |
| 4003 | } |
| 4004 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4005 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4006 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4007 | S.ExternalSource = this; |
| 4008 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4009 | // Makes sure any declarations that were deserialized "too early" |
| 4010 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4011 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4012 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4013 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4014 | |
| 4015 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4016 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4017 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4018 | |
| 4019 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4020 | // them to Sema's list of tentative definitions. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4021 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4022 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4023 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4024 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 4025 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4026 | // If there were any unused file scoped decls, deserialize them and add to |
| 4027 | // Sema's list of unused file scoped decls. |
| 4028 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4029 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4030 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 4031 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4032 | |
| 4033 | // If there were any locally-scoped external declarations, |
| 4034 | // deserialize them and add them to Sema's table of locally-scoped |
| 4035 | // external declarations. |
| 4036 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4037 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4038 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 4039 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4040 | |
| 4041 | // If there were any ext_vector type declarations, deserialize them |
| 4042 | // and add them to Sema's vector of such declarations. |
| 4043 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 4044 | SemaObj->ExtVectorDecls.push_back( |
| 4045 | cast<TypedefDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4046 | |
| 4047 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 4048 | // Can we cut them down before writing them ? |
| 4049 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4050 | // If there were any dynamic classes declarations, deserialize them |
| 4051 | // and add them to Sema's vector of such declarations. |
| 4052 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 4053 | SemaObj->DynamicClasses.push_back( |
| 4054 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4055 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4056 | // Load the offsets of the declarations that Sema references. |
| 4057 | // They will be lazily deserialized when needed. |
| 4058 | if (!SemaDeclRefs.empty()) { |
| 4059 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 4060 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4061 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 4062 | } |
| 4063 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4064 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 4065 | |
| 4066 | // If there are @selector references added them to its pool. This is for |
| 4067 | // implementation of -Wselector. |
| 4068 | if (!F->ReferencedSelectorsData.empty()) { |
| 4069 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 4070 | unsigned I = 0; |
| 4071 | while (I < DataSize) { |
| 4072 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 4073 | SourceLocation SelLoc = ReadSourceLocation( |
| 4074 | *F, F->ReferencedSelectorsData, I); |
| 4075 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 4076 | } |
| 4077 | } |
| 4078 | |
| 4079 | // If there were any pending implicit instantiations, deserialize them |
| 4080 | // and add them to Sema's queue of such instantiations. |
| 4081 | assert(F->PendingInstantiations.size() % 2 == 0 && |
| 4082 | "Expected pairs of entries"); |
| 4083 | for (unsigned Idx = 0, N = F->PendingInstantiations.size(); Idx < N;) { |
| 4084 | ValueDecl *D=cast<ValueDecl>(GetDecl(F->PendingInstantiations[Idx++])); |
| 4085 | SourceLocation Loc = ReadSourceLocation(*F, F->PendingInstantiations,Idx); |
| 4086 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 4087 | } |
| 4088 | } |
| 4089 | |
| 4090 | // The two special data sets below always come from the most recent PCH, |
| 4091 | // which is at the front of the chain. |
| 4092 | PerFileData &F = *Chain.front(); |
| 4093 | |
| 4094 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 4095 | // Sema's list of weak undeclared identifiers. |
| 4096 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 4097 | unsigned Idx = 0; |
| 4098 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 4099 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4100 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4101 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 4102 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 4103 | Sema::WeakInfo WI(AliasId, Loc); |
| 4104 | WI.setUsed(Used); |
| 4105 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 4106 | } |
| 4107 | } |
| 4108 | |
| 4109 | // If there were any VTable uses, deserialize the information and add it |
| 4110 | // to Sema's vector and map of VTable uses. |
| 4111 | if (!VTableUses.empty()) { |
| 4112 | unsigned Idx = 0; |
| 4113 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 4114 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4115 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 4116 | bool DefinitionRequired = VTableUses[Idx++]; |
| 4117 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 4118 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4119 | } |
| 4120 | } |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame^] | 4121 | |
| 4122 | if (!FPPragmaOptions.empty()) { |
| 4123 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4124 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4125 | } |
| 4126 | |
| 4127 | if (!OpenCLExtensions.empty()) { |
| 4128 | unsigned I = 0; |
| 4129 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4130 | #include "clang/Basic/OpenCLExtensions.def" |
| 4131 | |
| 4132 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4133 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4134 | } |
| 4135 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4136 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4137 | // Try to find this name within our on-disk hash tables. We start with the |
| 4138 | // 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] | 4139 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4140 | ASTIdentifierLookupTable *IdTable |
| 4141 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4142 | if (!IdTable) |
| 4143 | continue; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4144 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4145 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4146 | if (Pos == IdTable->end()) |
| 4147 | continue; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4148 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4149 | // Dereferencing the iterator has the effect of building the |
| 4150 | // IdentifierInfo node and populating it with the various |
| 4151 | // declarations it needs. |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4152 | return *Pos; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4153 | } |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4154 | return 0; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4155 | } |
| 4156 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4157 | namespace clang { |
| 4158 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4159 | /// identifiers stored within a set of AST files. |
| 4160 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4161 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4162 | const ASTReader &Reader; |
| 4163 | |
| 4164 | /// \brief The current index into the chain of AST files stored in |
| 4165 | /// the AST reader. |
| 4166 | unsigned Index; |
| 4167 | |
| 4168 | /// \brief The current position within the identifier lookup table |
| 4169 | /// of the current AST file. |
| 4170 | ASTIdentifierLookupTable::key_iterator Current; |
| 4171 | |
| 4172 | /// \brief The end position within the identifier lookup table of |
| 4173 | /// the current AST file. |
| 4174 | ASTIdentifierLookupTable::key_iterator End; |
| 4175 | |
| 4176 | public: |
| 4177 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4178 | |
| 4179 | virtual llvm::StringRef Next(); |
| 4180 | }; |
| 4181 | } |
| 4182 | |
| 4183 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 4184 | : Reader(Reader), Index(Reader.Chain.size() - 1) { |
| 4185 | ASTIdentifierLookupTable *IdTable |
| 4186 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4187 | Current = IdTable->key_begin(); |
| 4188 | End = IdTable->key_end(); |
| 4189 | } |
| 4190 | |
| 4191 | llvm::StringRef ASTIdentifierIterator::Next() { |
| 4192 | while (Current == End) { |
| 4193 | // If we have exhausted all of our AST files, we're done. |
| 4194 | if (Index == 0) |
| 4195 | return llvm::StringRef(); |
| 4196 | |
| 4197 | --Index; |
| 4198 | ASTIdentifierLookupTable *IdTable |
| 4199 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4200 | Current = IdTable->key_begin(); |
| 4201 | End = IdTable->key_end(); |
| 4202 | } |
| 4203 | |
| 4204 | // We have any identifiers remaining in the current AST file; return |
| 4205 | // the next one. |
| 4206 | std::pair<const char*, unsigned> Key = *Current; |
| 4207 | ++Current; |
| 4208 | return llvm::StringRef(Key.first, Key.second); |
| 4209 | } |
| 4210 | |
| 4211 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4212 | return new ASTIdentifierIterator(*this); |
| 4213 | } |
| 4214 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4215 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4216 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4217 | // Find this selector in a hash table. We want to find the most recent entry. |
| 4218 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4219 | PerFileData &F = *Chain[I]; |
| 4220 | if (!F.SelectorLookupTable) |
| 4221 | continue; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4222 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4223 | ASTSelectorLookupTable *PoolTable |
| 4224 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 4225 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4226 | if (Pos != PoolTable->end()) { |
| 4227 | ++NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4228 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4229 | // disable this tracking when called via LoadSelector. |
| 4230 | // Also, should entries without methods count as misses? |
| 4231 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4232 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4233 | if (DeserializationListener) |
| 4234 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 4235 | return std::make_pair(Data.Instance, Data.Factory); |
| 4236 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4237 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4238 | |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4239 | ++NumMethodPoolMisses; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4240 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4241 | } |
| 4242 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4243 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4244 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4245 | ReadMethodPool(Sel); |
| 4246 | } |
| 4247 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4248 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4249 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4250 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4251 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4252 | if (DeserializationListener) |
| 4253 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4254 | } |
| 4255 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4256 | /// \brief Set the globally-visible declarations associated with the given |
| 4257 | /// identifier. |
| 4258 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4259 | /// 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] | 4260 | /// 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] | 4261 | /// them. |
| 4262 | /// |
| 4263 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4264 | /// declarations. |
| 4265 | /// |
| 4266 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4267 | /// visible at global scope. |
| 4268 | /// |
| 4269 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4270 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4271 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4272 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4273 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4274 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 4275 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4276 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4277 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4278 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4279 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4280 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4281 | return; |
| 4282 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4283 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4284 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4285 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4286 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4287 | if (SemaObj->TUScope) { |
| 4288 | // Introduce this declaration into the translation-unit scope |
| 4289 | // and add it to the declaration chain for this identifier, so |
| 4290 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4291 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4292 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4293 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4294 | } else { |
| 4295 | // Queue this declaration so that it will be added to the |
| 4296 | // translation unit scope and identifier's declaration chain |
| 4297 | // once a Sema object is known. |
| 4298 | PreloadedDecls.push_back(D); |
| 4299 | } |
| 4300 | } |
| 4301 | } |
| 4302 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4303 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4304 | if (ID == 0) |
| 4305 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4306 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4307 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4308 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4309 | return 0; |
| 4310 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4311 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4312 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4313 | ID -= 1; |
| 4314 | if (!IdentifiersLoaded[ID]) { |
| 4315 | unsigned Index = ID; |
| 4316 | const char *Str = 0; |
| 4317 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4318 | PerFileData *F = Chain[N - I - 1]; |
| 4319 | if (Index < F->LocalNumIdentifiers) { |
| 4320 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 4321 | Str = F->IdentifierTableData + Offset; |
| 4322 | break; |
| 4323 | } |
| 4324 | Index -= F->LocalNumIdentifiers; |
| 4325 | } |
| 4326 | assert(Str && "Broken Chain"); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4327 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4328 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4329 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4330 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4331 | // unsigned integers. This is important to avoid integer overflow when |
| 4332 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4333 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4334 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4335 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4336 | IdentifiersLoaded[ID] |
Kovarththanan Rajaratnam | 811f426 | 2010-03-12 10:32:27 +0000 | [diff] [blame] | 4337 | = &PP->getIdentifierTable().get(Str, StrLen); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4338 | if (DeserializationListener) |
| 4339 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4340 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4341 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4342 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4343 | } |
| 4344 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4345 | void ASTReader::ReadSLocEntry(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4346 | ReadSLocEntryRecord(ID); |
| 4347 | } |
| 4348 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4349 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4350 | if (ID == 0) |
| 4351 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4352 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4353 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4354 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4355 | return Selector(); |
| 4356 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4357 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4358 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4359 | // Load this selector from the selector table. |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4360 | unsigned Idx = ID - 1; |
| 4361 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4362 | PerFileData &F = *Chain[N - I - 1]; |
| 4363 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4364 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4365 | SelectorsLoaded[ID - 1] = |
| 4366 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 4367 | if (DeserializationListener) |
| 4368 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 4369 | break; |
| 4370 | } |
| 4371 | Idx -= F.LocalNumSelectors; |
| 4372 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4373 | } |
| 4374 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4375 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4376 | } |
| 4377 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4378 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4379 | return DecodeSelector(ID); |
| 4380 | } |
| 4381 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4382 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4383 | // ID 0 (the null selector) is considered an external selector. |
| 4384 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4385 | } |
| 4386 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4387 | DeclarationName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4388 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4389 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4390 | switch (Kind) { |
| 4391 | case DeclarationName::Identifier: |
| 4392 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 4393 | |
| 4394 | case DeclarationName::ObjCZeroArgSelector: |
| 4395 | case DeclarationName::ObjCOneArgSelector: |
| 4396 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 4397 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4398 | |
| 4399 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4400 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4401 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4402 | |
| 4403 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4404 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4405 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4406 | |
| 4407 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4408 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4409 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4410 | |
| 4411 | case DeclarationName::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4412 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4413 | (OverloadedOperatorKind)Record[Idx++]); |
| 4414 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4415 | case DeclarationName::CXXLiteralOperatorName: |
| 4416 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 4417 | GetIdentifierInfo(Record, Idx)); |
| 4418 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4419 | case DeclarationName::CXXUsingDirective: |
| 4420 | return DeclarationName::getUsingDirectiveName(); |
| 4421 | } |
| 4422 | |
| 4423 | // Required to silence GCC warning |
| 4424 | return DeclarationName(); |
| 4425 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4426 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4427 | void ASTReader::ReadDeclarationNameLoc(PerFileData &F, |
| 4428 | DeclarationNameLoc &DNLoc, |
| 4429 | DeclarationName Name, |
| 4430 | const RecordData &Record, unsigned &Idx) { |
| 4431 | switch (Name.getNameKind()) { |
| 4432 | case DeclarationName::CXXConstructorName: |
| 4433 | case DeclarationName::CXXDestructorName: |
| 4434 | case DeclarationName::CXXConversionFunctionName: |
| 4435 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4436 | break; |
| 4437 | |
| 4438 | case DeclarationName::CXXOperatorName: |
| 4439 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4440 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4441 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4442 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4443 | break; |
| 4444 | |
| 4445 | case DeclarationName::CXXLiteralOperatorName: |
| 4446 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4447 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4448 | break; |
| 4449 | |
| 4450 | case DeclarationName::Identifier: |
| 4451 | case DeclarationName::ObjCZeroArgSelector: |
| 4452 | case DeclarationName::ObjCOneArgSelector: |
| 4453 | case DeclarationName::ObjCMultiArgSelector: |
| 4454 | case DeclarationName::CXXUsingDirective: |
| 4455 | break; |
| 4456 | } |
| 4457 | } |
| 4458 | |
| 4459 | void ASTReader::ReadDeclarationNameInfo(PerFileData &F, |
| 4460 | DeclarationNameInfo &NameInfo, |
| 4461 | const RecordData &Record, unsigned &Idx) { |
| 4462 | NameInfo.setName(ReadDeclarationName(Record, Idx)); |
| 4463 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4464 | DeclarationNameLoc DNLoc; |
| 4465 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4466 | NameInfo.setInfo(DNLoc); |
| 4467 | } |
| 4468 | |
| 4469 | void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info, |
| 4470 | const RecordData &Record, unsigned &Idx) { |
| 4471 | Info.NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4472 | Info.NNSRange = ReadSourceRange(F, Record, Idx); |
| 4473 | unsigned NumTPLists = Record[Idx++]; |
| 4474 | Info.NumTemplParamLists = NumTPLists; |
| 4475 | if (NumTPLists) { |
| 4476 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 4477 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4478 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4479 | } |
| 4480 | } |
| 4481 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4482 | TemplateName |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4483 | ASTReader::ReadTemplateName(PerFileData &F, const RecordData &Record, |
| 4484 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4485 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4486 | switch (Kind) { |
| 4487 | case TemplateName::Template: |
| 4488 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 4489 | |
| 4490 | case TemplateName::OverloadedTemplate: { |
| 4491 | unsigned size = Record[Idx++]; |
| 4492 | UnresolvedSet<8> Decls; |
| 4493 | while (size--) |
| 4494 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 4495 | |
| 4496 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 4497 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4498 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4499 | case TemplateName::QualifiedTemplate: { |
| 4500 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4501 | bool hasTemplKeyword = Record[Idx++]; |
| 4502 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 4503 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 4504 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4505 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4506 | case TemplateName::DependentTemplate: { |
| 4507 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4508 | if (Record[Idx++]) // isIdentifier |
| 4509 | return Context->getDependentTemplateName(NNS, |
| 4510 | GetIdentifierInfo(Record, Idx)); |
| 4511 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4512 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4513 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4514 | |
| 4515 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4516 | TemplateTemplateParmDecl *Param |
| 4517 | = cast_or_null<TemplateTemplateParmDecl>(GetDecl(Record[Idx++])); |
| 4518 | if (!Param) |
| 4519 | return TemplateName(); |
| 4520 | |
| 4521 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 4522 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 4523 | return TemplateName(); |
| 4524 | |
| 4525 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 4526 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4527 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4528 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4529 | assert(0 && "Unhandled template name kind!"); |
| 4530 | return TemplateName(); |
| 4531 | } |
| 4532 | |
| 4533 | TemplateArgument |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4534 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4535 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4536 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 4537 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4538 | case TemplateArgument::Null: |
| 4539 | return TemplateArgument(); |
| 4540 | case TemplateArgument::Type: |
| 4541 | return TemplateArgument(GetType(Record[Idx++])); |
| 4542 | case TemplateArgument::Declaration: |
| 4543 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4544 | case TemplateArgument::Integral: { |
| 4545 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 4546 | QualType T = GetType(Record[Idx++]); |
| 4547 | return TemplateArgument(Value, T); |
| 4548 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4549 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4550 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4551 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4552 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4553 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 4554 | if (unsigned NumExpansions = Record[Idx++]) |
| 4555 | NumTemplateExpansions = NumExpansions - 1; |
| 4556 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4557 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4558 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4559 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4560 | case TemplateArgument::Pack: { |
| 4561 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4562 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 4563 | for (unsigned I = 0; I != NumArgs; ++I) |
| 4564 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 4565 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4566 | } |
| 4567 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4568 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4569 | assert(0 && "Unhandled template argument kind!"); |
| 4570 | return TemplateArgument(); |
| 4571 | } |
| 4572 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4573 | TemplateParameterList * |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4574 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 4575 | const RecordData &Record, unsigned &Idx) { |
| 4576 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 4577 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 4578 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4579 | |
| 4580 | unsigned NumParams = Record[Idx++]; |
| 4581 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 4582 | Params.reserve(NumParams); |
| 4583 | while (NumParams--) |
| 4584 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4585 | |
| 4586 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4587 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 4588 | Params.data(), Params.size(), RAngleLoc); |
| 4589 | return TemplateParams; |
| 4590 | } |
| 4591 | |
| 4592 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4593 | ASTReader:: |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4594 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4595 | PerFileData &F, const RecordData &Record, |
| 4596 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4597 | unsigned NumTemplateArgs = Record[Idx++]; |
| 4598 | TemplArgs.reserve(NumTemplateArgs); |
| 4599 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4600 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4601 | } |
| 4602 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4603 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4604 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4605 | const RecordData &Record, unsigned &Idx) { |
| 4606 | unsigned NumDecls = Record[Idx++]; |
| 4607 | while (NumDecls--) { |
| 4608 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 4609 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 4610 | Set.addDecl(D, AS); |
| 4611 | } |
| 4612 | } |
| 4613 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4614 | CXXBaseSpecifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4615 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4616 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4617 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 4618 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 4619 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4620 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4621 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4622 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4623 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4624 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4625 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4626 | Result.setInheritConstructors(inheritConstructors); |
| 4627 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4628 | } |
| 4629 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4630 | std::pair<CXXCtorInitializer **, unsigned> |
| 4631 | ASTReader::ReadCXXCtorInitializers(PerFileData &F, const RecordData &Record, |
| 4632 | unsigned &Idx) { |
| 4633 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4634 | unsigned NumInitializers = Record[Idx++]; |
| 4635 | if (NumInitializers) { |
| 4636 | ASTContext &C = *getContext(); |
| 4637 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4638 | CtorInitializers |
| 4639 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4640 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 4641 | TypeSourceInfo *BaseClassInfo = 0; |
| 4642 | bool IsBaseVirtual = false; |
| 4643 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4644 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4645 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4646 | bool IsBaseInitializer = Record[Idx++]; |
| 4647 | if (IsBaseInitializer) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4648 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4649 | IsBaseVirtual = Record[Idx++]; |
| 4650 | } else { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4651 | bool IsIndirectMemberInitializer = Record[Idx++]; |
| 4652 | if (IsIndirectMemberInitializer) |
| 4653 | IndirectMember = cast<IndirectFieldDecl>(GetDecl(Record[Idx++])); |
| 4654 | else |
| 4655 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4656 | } |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 4657 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4658 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4659 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 4660 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4661 | bool IsWritten = Record[Idx++]; |
| 4662 | unsigned SourceOrderOrNumArrayIndices; |
| 4663 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 4664 | if (IsWritten) { |
| 4665 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4666 | } else { |
| 4667 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4668 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 4669 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 4670 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 4671 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4672 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4673 | CXXCtorInitializer *BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4674 | if (IsBaseInitializer) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4675 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 4676 | LParenLoc, Init, RParenLoc, |
| 4677 | MemberOrEllipsisLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4678 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4679 | if (Member) |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4680 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 4681 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4682 | else |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4683 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 4684 | MemberOrEllipsisLoc, LParenLoc, |
| 4685 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4686 | } else { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4687 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 4688 | LParenLoc, Init, RParenLoc, |
| 4689 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4690 | } |
| 4691 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 4692 | if (IsWritten) |
| 4693 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4694 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4695 | } |
| 4696 | } |
| 4697 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4698 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4699 | } |
| 4700 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4701 | NestedNameSpecifier * |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4702 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4703 | unsigned N = Record[Idx++]; |
| 4704 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 4705 | for (unsigned I = 0; I != N; ++I) { |
| 4706 | NestedNameSpecifier::SpecifierKind Kind |
| 4707 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4708 | switch (Kind) { |
| 4709 | case NestedNameSpecifier::Identifier: { |
| 4710 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 4711 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 4712 | break; |
| 4713 | } |
| 4714 | |
| 4715 | case NestedNameSpecifier::Namespace: { |
| 4716 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 4717 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 4718 | break; |
| 4719 | } |
| 4720 | |
| 4721 | case NestedNameSpecifier::TypeSpec: |
| 4722 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4723 | const Type *T = GetType(Record[Idx++]).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 4724 | if (!T) |
| 4725 | return 0; |
| 4726 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4727 | bool Template = Record[Idx++]; |
| 4728 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 4729 | break; |
| 4730 | } |
| 4731 | |
| 4732 | case NestedNameSpecifier::Global: { |
| 4733 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4734 | // No associated value, and there can't be a prefix. |
| 4735 | break; |
| 4736 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4737 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 4738 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4739 | } |
| 4740 | return NNS; |
| 4741 | } |
| 4742 | |
| 4743 | SourceRange |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4744 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 4745 | unsigned &Idx) { |
| 4746 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 4747 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 4748 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4749 | } |
| 4750 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4751 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4752 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4753 | unsigned BitWidth = Record[Idx++]; |
| 4754 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 4755 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 4756 | Idx += NumWords; |
| 4757 | return Result; |
| 4758 | } |
| 4759 | |
| 4760 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4761 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4762 | bool isUnsigned = Record[Idx++]; |
| 4763 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 4764 | } |
| 4765 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4766 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4767 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4768 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 4769 | } |
| 4770 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4771 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4772 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4773 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 4774 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4775 | Idx += Len; |
| 4776 | return Result; |
| 4777 | } |
| 4778 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4779 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4780 | unsigned &Idx) { |
| 4781 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 4782 | return CXXTemporary::Create(*Context, Decl); |
| 4783 | } |
| 4784 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4785 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 4786 | return Diag(SourceLocation(), DiagID); |
| 4787 | } |
| 4788 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4789 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4790 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4791 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4792 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4793 | /// \brief Retrieve the identifier table associated with the |
| 4794 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4795 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4796 | assert(PP && "Forgot to set Preprocessor ?"); |
| 4797 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4798 | } |
| 4799 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4800 | /// \brief Record that the given ID maps to the given switch-case |
| 4801 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4802 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4803 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 4804 | SwitchCaseStmts[ID] = SC; |
| 4805 | } |
| 4806 | |
| 4807 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4808 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4809 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 4810 | return SwitchCaseStmts[ID]; |
| 4811 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4812 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4813 | void ASTReader::ClearSwitchCaseIDs() { |
| 4814 | SwitchCaseStmts.clear(); |
| 4815 | } |
| 4816 | |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4817 | /// \brief Record that the given label statement has been |
| 4818 | /// deserialized and has the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4819 | void ASTReader::RecordLabelStmt(LabelStmt *S, unsigned ID) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4820 | assert(LabelStmts.find(ID) == LabelStmts.end() && |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4821 | "Deserialized label twice"); |
| 4822 | LabelStmts[ID] = S; |
| 4823 | |
| 4824 | // If we've already seen any goto statements that point to this |
| 4825 | // label, resolve them now. |
| 4826 | typedef std::multimap<unsigned, GotoStmt *>::iterator GotoIter; |
| 4827 | std::pair<GotoIter, GotoIter> Gotos = UnresolvedGotoStmts.equal_range(ID); |
| 4828 | for (GotoIter Goto = Gotos.first; Goto != Gotos.second; ++Goto) |
| 4829 | Goto->second->setLabel(S); |
| 4830 | UnresolvedGotoStmts.erase(Gotos.first, Gotos.second); |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4831 | |
| 4832 | // If we've already seen any address-label statements that point to |
| 4833 | // this label, resolve them now. |
| 4834 | typedef std::multimap<unsigned, AddrLabelExpr *>::iterator AddrLabelIter; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4835 | std::pair<AddrLabelIter, AddrLabelIter> AddrLabels |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4836 | = UnresolvedAddrLabelExprs.equal_range(ID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4837 | for (AddrLabelIter AddrLabel = AddrLabels.first; |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4838 | AddrLabel != AddrLabels.second; ++AddrLabel) |
| 4839 | AddrLabel->second->setLabel(S); |
| 4840 | UnresolvedAddrLabelExprs.erase(AddrLabels.first, AddrLabels.second); |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4841 | } |
| 4842 | |
| 4843 | /// \brief Set the label of the given statement to the label |
| 4844 | /// identified by ID. |
| 4845 | /// |
| 4846 | /// Depending on the order in which the label and other statements |
| 4847 | /// referencing that label occur, this operation may complete |
| 4848 | /// immediately (updating the statement) or it may queue the |
| 4849 | /// statement to be back-patched later. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4850 | void ASTReader::SetLabelOf(GotoStmt *S, unsigned ID) { |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4851 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 4852 | if (Label != LabelStmts.end()) { |
| 4853 | // We've already seen this label, so set the label of the goto and |
| 4854 | // we're done. |
| 4855 | S->setLabel(Label->second); |
| 4856 | } else { |
| 4857 | // We haven't seen this label yet, so add this goto to the set of |
| 4858 | // unresolved goto statements. |
| 4859 | UnresolvedGotoStmts.insert(std::make_pair(ID, S)); |
| 4860 | } |
| 4861 | } |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4862 | |
| 4863 | /// \brief Set the label of the given expression to the label |
| 4864 | /// identified by ID. |
| 4865 | /// |
| 4866 | /// Depending on the order in which the label and other statements |
| 4867 | /// referencing that label occur, this operation may complete |
| 4868 | /// immediately (updating the statement) or it may queue the |
| 4869 | /// statement to be back-patched later. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4870 | void ASTReader::SetLabelOf(AddrLabelExpr *S, unsigned ID) { |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4871 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 4872 | if (Label != LabelStmts.end()) { |
| 4873 | // We've already seen this label, so set the label of the |
| 4874 | // label-address expression and we're done. |
| 4875 | S->setLabel(Label->second); |
| 4876 | } else { |
| 4877 | // We haven't seen this label yet, so add this label-address |
| 4878 | // expression to the set of unresolved label-address expressions. |
| 4879 | UnresolvedAddrLabelExprs.insert(std::make_pair(ID, S)); |
| 4880 | } |
| 4881 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4882 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4883 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4884 | assert(NumCurrentElementsDeserializing && |
| 4885 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 4886 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4887 | // If any identifiers with corresponding top-level declarations have |
| 4888 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4889 | while (!PendingIdentifierInfos.empty()) { |
| 4890 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 4891 | PendingIdentifierInfos.front().DeclIDs, true); |
| 4892 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4893 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4894 | |
Argyrios Kyrtzidis | 0895d15 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 4895 | // Ready to load previous declarations of Decls that were delayed. |
| 4896 | while (!PendingPreviousDecls.empty()) { |
| 4897 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 4898 | PendingPreviousDecls.front().second); |
| 4899 | PendingPreviousDecls.pop_front(); |
| 4900 | } |
| 4901 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4902 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 4903 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4904 | if (Consumer) |
| 4905 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 4906 | |
| 4907 | assert(PendingForwardRefs.size() == 0 && |
| 4908 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4909 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4910 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4911 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4912 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4913 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4914 | const char *isysroot, bool DisableValidation, |
| 4915 | bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4916 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 4917 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 4918 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
| 4919 | Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4920 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 4921 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), NextSLocOffset(0), |
| 4922 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 4923 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 4924 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 4925 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
| 4926 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 4927 | NumCurrentElementsDeserializing(0) |
| 4928 | { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4929 | RelocatablePCH = false; |
| 4930 | } |
| 4931 | |
| 4932 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 4933 | Diagnostic &Diags, const char *isysroot, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4934 | bool DisableValidation, bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4935 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
| 4936 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4937 | isysroot(isysroot), DisableValidation(DisableValidation), |
| 4938 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 4939 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4940 | NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0), |
| 4941 | NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), |
| 4942 | NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
| 4943 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4944 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4945 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4946 | RelocatablePCH = false; |
| 4947 | } |
| 4948 | |
| 4949 | ASTReader::~ASTReader() { |
| 4950 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 4951 | delete Chain[e - i - 1]; |
| 4952 | // Delete all visible decl lookup tables |
| 4953 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 4954 | E = DeclContextOffsets.end(); |
| 4955 | I != E; ++I) { |
| 4956 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 4957 | J != F; ++J) { |
| 4958 | if (J->NameLookupTableData) |
| 4959 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 4960 | J->NameLookupTableData); |
| 4961 | } |
| 4962 | } |
| 4963 | for (DeclContextVisibleUpdatesPending::iterator |
| 4964 | I = PendingVisibleUpdates.begin(), |
| 4965 | E = PendingVisibleUpdates.end(); |
| 4966 | I != E; ++I) { |
| 4967 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 4968 | F = I->second.end(); |
| 4969 | J != F; ++J) |
| 4970 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 4971 | } |
| 4972 | } |
| 4973 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 4974 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
| 4975 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 4976 | LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), |
| 4977 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4978 | MacroDefinitionOffsets(0), |
| 4979 | LocalNumHeaderFileInfos(0), HeaderFileInfoTableData(0), |
| 4980 | HeaderFileInfoTable(0), |
| 4981 | LocalNumSelectors(0), SelectorOffsets(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 4982 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4983 | DeclOffsets(0), LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
| 4984 | LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 4985 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4986 | {} |
| 4987 | |
| 4988 | ASTReader::PerFileData::~PerFileData() { |
| 4989 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4990 | delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4991 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 4992 | } |
| 4993 | |