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); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 100 | PARSE_LANGOPT_IMPORTANT(ObjCExceptions, diag::warn_pch_objc_exceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame^] | 101 | PARSE_LANGOPT_IMPORTANT(CXXExceptions, diag::warn_pch_cxx_exceptions); |
| 102 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 103 | PARSE_LANGOPT_IMPORTANT(MSBitfields, diag::warn_pch_ms_bitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 104 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 105 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 106 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 108 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 109 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 110 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 111 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 112 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 113 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 115 | diag::warn_pch_heinous_extensions); |
| 116 | // FIXME: Most of the options below are benign if the macro wasn't |
| 117 | // used. Unfortunately, this means that a PCH compiled without |
| 118 | // optimization can't be used with optimization turned on, even |
| 119 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 120 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 121 | // doesn't matter. We could consider making this some special kind |
| 122 | // of check. |
| 123 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 124 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 125 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 126 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 127 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 128 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
| 129 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 130 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 131 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 132 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 133 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 134 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 135 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 136 | return true; |
| 137 | } |
| 138 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 139 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 140 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 141 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 142 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 143 | PARSE_LANGOPT_IMPORTANT(CUDA, diag::warn_pch_cuda); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 144 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 145 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 146 | PARSE_LANGOPT_BENIGN(SpellChecking); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 147 | PARSE_LANGOPT_BENIGN(DefaultFPContract); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 148 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 149 | #undef PARSE_LANGOPT_BENIGN |
| 150 | |
| 151 | return false; |
| 152 | } |
| 153 | |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 154 | bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) { |
| 155 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 156 | return false; |
| 157 | |
| 158 | Reader.Diag(diag::warn_pch_target_triple) |
| 159 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 160 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 163 | namespace { |
| 164 | struct EmptyStringRef { |
| 165 | bool operator ()(llvm::StringRef r) const { return r.empty(); } |
| 166 | }; |
| 167 | struct EmptyBlock { |
| 168 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 169 | }; |
| 170 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 171 | |
| 172 | static bool EqualConcatenations(llvm::SmallVector<llvm::StringRef, 2> L, |
| 173 | PCHPredefinesBlocks R) { |
| 174 | // First, sum up the lengths. |
| 175 | unsigned LL = 0, RL = 0; |
| 176 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 177 | LL += L[I].size(); |
| 178 | } |
| 179 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 180 | RL += R[I].Data.size(); |
| 181 | } |
| 182 | if (LL != RL) |
| 183 | return false; |
| 184 | if (LL == 0 && RL == 0) |
| 185 | return true; |
| 186 | |
| 187 | // Kick out empty parts, they confuse the algorithm below. |
| 188 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 189 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 190 | |
| 191 | // Do it the hard way. At this point, both vectors must be non-empty. |
| 192 | llvm::StringRef LR = L[0], RR = R[0].Data; |
| 193 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 194 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 195 | for (;;) { |
| 196 | // Compare the current pieces. |
| 197 | if (LR.size() == RR.size()) { |
| 198 | // If they're the same length, it's pretty easy. |
| 199 | if (LR != RR) |
| 200 | return false; |
| 201 | // Both pieces are done, advance. |
| 202 | ++LI; |
| 203 | ++RI; |
| 204 | // If either string is done, they're both done, since they're the same |
| 205 | // length. |
| 206 | if (LI == LN) { |
| 207 | assert(RI == RN && "Strings not the same length after all?"); |
| 208 | return true; |
| 209 | } |
| 210 | LR = L[LI]; |
| 211 | RR = R[RI].Data; |
| 212 | } else if (LR.size() < RR.size()) { |
| 213 | // Right piece is longer. |
| 214 | if (!RR.startswith(LR)) |
| 215 | return false; |
| 216 | ++LI; |
| 217 | assert(LI != LN && "Strings not the same length after all?"); |
| 218 | RR = RR.substr(LR.size()); |
| 219 | LR = L[LI]; |
| 220 | } else { |
| 221 | // Left piece is longer. |
| 222 | if (!LR.startswith(RR)) |
| 223 | return false; |
| 224 | ++RI; |
| 225 | assert(RI != RN && "Strings not the same length after all?"); |
| 226 | LR = LR.substr(RR.size()); |
| 227 | RR = R[RI].Data; |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | static std::pair<FileID, llvm::StringRef::size_type> |
| 233 | FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) { |
| 234 | std::pair<FileID, llvm::StringRef::size_type> Res; |
| 235 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 236 | Res.second = Buffers[I].Data.find(MacroDef); |
| 237 | if (Res.second != llvm::StringRef::npos) { |
| 238 | Res.first = Buffers[I].BufferID; |
| 239 | break; |
| 240 | } |
| 241 | } |
| 242 | return Res; |
| 243 | } |
| 244 | |
| 245 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 246 | llvm::StringRef OriginalFileName, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 247 | std::string &SuggestedPredefines) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 248 | // We are in the context of an implicit include, so the predefines buffer will |
| 249 | // have a #include entry for the PCH file itself (as normalized by the |
| 250 | // preprocessor initialization). Find it and skip over it in the checking |
| 251 | // below. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 252 | llvm::SmallString<256> PCHInclude; |
| 253 | PCHInclude += "#include \""; |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 254 | PCHInclude += NormalizeDashIncludePath(OriginalFileName); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 255 | PCHInclude += "\"\n"; |
| 256 | std::pair<llvm::StringRef,llvm::StringRef> Split = |
| 257 | llvm::StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 258 | llvm::StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 259 | if (Left == PP.getPredefines()) { |
| 260 | Error("Missing PCH include entry!"); |
| 261 | return true; |
| 262 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 263 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 264 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 265 | // command line, we're done. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 266 | llvm::SmallVector<llvm::StringRef, 2> CommandLine; |
| 267 | CommandLine.push_back(Left); |
| 268 | CommandLine.push_back(Right); |
| 269 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 270 | return false; |
| 271 | |
| 272 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 273 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 274 | // The predefines buffers are different. Determine what the differences are, |
| 275 | // and whether they require us to reject the PCH file. |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 276 | llvm::SmallVector<llvm::StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 277 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 278 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 279 | |
| 280 | llvm::SmallVector<llvm::StringRef, 8> CmdLineLines; |
| 281 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 282 | |
| 283 | // Pick out implicit #includes after the PCH and don't consider them for |
| 284 | // validation; we will insert them into SuggestedPredefines so that the |
| 285 | // preprocessor includes them. |
| 286 | std::string IncludesAfterPCH; |
| 287 | llvm::SmallVector<llvm::StringRef, 8> AfterPCHLines; |
| 288 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 289 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 290 | if (AfterPCHLines[i].startswith("#include ")) { |
| 291 | IncludesAfterPCH += AfterPCHLines[i]; |
| 292 | IncludesAfterPCH += '\n'; |
| 293 | } else { |
| 294 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | // Make sure we add the includes last into SuggestedPredefines before we |
| 299 | // exit this function. |
| 300 | struct AddIncludesRAII { |
| 301 | std::string &SuggestedPredefines; |
| 302 | std::string &IncludesAfterPCH; |
| 303 | |
| 304 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 305 | std::string &IncludesAfterPCH) |
| 306 | : SuggestedPredefines(SuggestedPredefines), |
| 307 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 308 | ~AddIncludesRAII() { |
| 309 | SuggestedPredefines += IncludesAfterPCH; |
| 310 | } |
| 311 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 312 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 313 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 314 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 315 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 316 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 317 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 318 | // Determine which predefines that were used to build the PCH file are missing |
| 319 | // from the command line. |
| 320 | std::vector<llvm::StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 321 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 322 | CmdLineLines.begin(), CmdLineLines.end(), |
| 323 | std::back_inserter(MissingPredefines)); |
| 324 | |
| 325 | bool MissingDefines = false; |
| 326 | bool ConflictingDefines = false; |
| 327 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 328 | llvm::StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 329 | if (Missing.startswith("#include ")) { |
| 330 | // An -include was specified when generating the PCH; it is included in |
| 331 | // the PCH, just ignore it. |
| 332 | continue; |
| 333 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 334 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 335 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 336 | return true; |
| 337 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 338 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 339 | // This is a macro definition. Determine the name of the macro we're |
| 340 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 341 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 342 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 343 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 344 | assert(EndOfMacroName != std::string::npos && |
| 345 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 346 | llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 347 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 348 | // Determine whether this macro was given a different definition on the |
| 349 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 350 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 351 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 352 | llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 353 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 354 | MacroDefStart); |
| 355 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 356 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 357 | // Different macro; we're done. |
| 358 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 359 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 360 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 361 | |
| 362 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 363 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 365 | (*ConflictPos)[MacroDefLen] != '(') |
| 366 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 367 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 368 | // We found a conflicting macro definition. |
| 369 | break; |
| 370 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 371 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 372 | if (ConflictPos != CmdLineLines.end()) { |
| 373 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 374 | << MacroName; |
| 375 | |
| 376 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 377 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 378 | FindMacro(Buffers, Missing); |
| 379 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 380 | SourceLocation PCHMissingLoc = |
| 381 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 382 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 383 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 384 | |
| 385 | ConflictingDefines = true; |
| 386 | continue; |
| 387 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 389 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 390 | // 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] | 391 | if (ConflictingDefines) |
| 392 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 393 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 394 | if (!MissingDefines) { |
| 395 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 396 | MissingDefines = true; |
| 397 | } |
| 398 | |
| 399 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 400 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 401 | FindMacro(Buffers, Missing); |
| 402 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 403 | SourceLocation PCHMissingLoc = |
| 404 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 405 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 406 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 407 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 408 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 409 | if (ConflictingDefines) |
| 410 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 411 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 412 | // Determine what predefines were introduced based on command-line |
| 413 | // parameters that were not present when building the PCH |
| 414 | // file. Extra #defines are okay, so long as the identifiers being |
| 415 | // defined were not used within the precompiled header. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 416 | std::vector<llvm::StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 417 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 418 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 419 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 420 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 421 | llvm::StringRef &Extra = ExtraPredefines[I]; |
| 422 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 423 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 424 | return true; |
| 425 | } |
| 426 | |
| 427 | // This is an extra macro definition. Determine the name of the |
| 428 | // macro we're defining. |
| 429 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 430 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 431 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 432 | assert(EndOfMacroName != std::string::npos && |
| 433 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 434 | llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 435 | |
| 436 | // Check whether this name was used somewhere in the PCH file. If |
| 437 | // so, defining it as a macro could change behavior, so we reject |
| 438 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 439 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 440 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 441 | return true; |
| 442 | } |
| 443 | |
| 444 | // Add this definition to the suggested predefines buffer. |
| 445 | SuggestedPredefines += Extra; |
| 446 | SuggestedPredefines += '\n'; |
| 447 | } |
| 448 | |
| 449 | // If we get here, it's because the predefines buffer had compatible |
| 450 | // contents. Accept the PCH file. |
| 451 | return false; |
| 452 | } |
| 453 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 454 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 455 | unsigned ID) { |
| 456 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 457 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | void PCHValidator::ReadCounter(unsigned Value) { |
| 461 | PP.setCounterValue(Value); |
| 462 | } |
| 463 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 464 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 465 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 466 | //===----------------------------------------------------------------------===// |
| 467 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 468 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 469 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 470 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 473 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 474 | namespace { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 475 | class ASTSelectorLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 476 | ASTReader &Reader; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 477 | |
| 478 | public: |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 479 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 480 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 481 | ObjCMethodList Instance, Factory; |
| 482 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 483 | |
| 484 | typedef Selector external_key_type; |
| 485 | typedef external_key_type internal_key_type; |
| 486 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 487 | explicit ASTSelectorLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 488 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 489 | static bool EqualKey(const internal_key_type& a, |
| 490 | const internal_key_type& b) { |
| 491 | return a == b; |
| 492 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 493 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 494 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 495 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 496 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 497 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 498 | // This hopefully will just get inlined and removed by the optimizer. |
| 499 | static const internal_key_type& |
| 500 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 501 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 502 | static std::pair<unsigned, unsigned> |
| 503 | ReadKeyDataLength(const unsigned char*& d) { |
| 504 | using namespace clang::io; |
| 505 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 506 | unsigned DataLen = ReadUnalignedLE16(d); |
| 507 | return std::make_pair(KeyLen, DataLen); |
| 508 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 509 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 510 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 511 | using namespace clang::io; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 512 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 513 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 514 | IdentifierInfo *FirstII |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 515 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 516 | if (N == 0) |
| 517 | return SelTable.getNullarySelector(FirstII); |
| 518 | else if (N == 1) |
| 519 | return SelTable.getUnarySelector(FirstII); |
| 520 | |
| 521 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 522 | Args.push_back(FirstII); |
| 523 | for (unsigned I = 1; I != N; ++I) |
| 524 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 525 | |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 526 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 527 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 529 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 530 | using namespace clang::io; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 531 | |
| 532 | data_type Result; |
| 533 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 534 | Result.ID = ReadUnalignedLE32(d); |
| 535 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 536 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 537 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 538 | // Load instance methods |
| 539 | ObjCMethodList *Prev = 0; |
| 540 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 541 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 542 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 543 | if (!Result.Instance.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 544 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 545 | Result.Instance.Method = Method; |
| 546 | Prev = &Result.Instance; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 547 | continue; |
| 548 | } |
| 549 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 550 | ObjCMethodList *Mem = |
| 551 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 552 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 553 | Prev = Prev->Next; |
| 554 | } |
| 555 | |
| 556 | // Load factory methods |
| 557 | Prev = 0; |
| 558 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 559 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 560 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 561 | if (!Result.Factory.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 562 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 563 | Result.Factory.Method = Method; |
| 564 | Prev = &Result.Factory; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 565 | continue; |
| 566 | } |
| 567 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 568 | ObjCMethodList *Mem = |
| 569 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 570 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 571 | Prev = Prev->Next; |
| 572 | } |
| 573 | |
| 574 | return Result; |
| 575 | } |
| 576 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 577 | |
| 578 | } // end anonymous namespace |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 579 | |
| 580 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 581 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 582 | ASTSelectorLookupTable; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 583 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 584 | namespace clang { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 585 | class ASTIdentifierLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 586 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 587 | ASTReader::PerFileData &F; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 588 | |
| 589 | // If we know the IdentifierInfo in advance, it is here and we will |
| 590 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 591 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 592 | IdentifierInfo *KnownII; |
| 593 | |
| 594 | public: |
| 595 | typedef IdentifierInfo * data_type; |
| 596 | |
| 597 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 598 | |
| 599 | typedef external_key_type internal_key_type; |
| 600 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 601 | ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 602 | IdentifierInfo *II = 0) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 603 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 604 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 605 | static bool EqualKey(const internal_key_type& a, |
| 606 | const internal_key_type& b) { |
| 607 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 608 | : false; |
| 609 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 610 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 611 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 612 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 613 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 614 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 615 | // This hopefully will just get inlined and removed by the optimizer. |
| 616 | static const internal_key_type& |
| 617 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 618 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 619 | // This hopefully will just get inlined and removed by the optimizer. |
| 620 | static const external_key_type& |
| 621 | GetExternalKey(const internal_key_type& x) { return x; } |
| 622 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 623 | static std::pair<unsigned, unsigned> |
| 624 | ReadKeyDataLength(const unsigned char*& d) { |
| 625 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 626 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 627 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 628 | return std::make_pair(KeyLen, DataLen); |
| 629 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 630 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 631 | static std::pair<const char*, unsigned> |
| 632 | ReadKey(const unsigned char* d, unsigned n) { |
| 633 | assert(n >= 2 && d[n-1] == '\0'); |
| 634 | return std::make_pair((const char*) d, n-1); |
| 635 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 636 | |
| 637 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 638 | const unsigned char* d, |
| 639 | unsigned DataLen) { |
| 640 | using namespace clang::io; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 641 | IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 642 | bool IsInteresting = ID & 0x01; |
| 643 | |
| 644 | // Wipe out the "is interesting" bit. |
| 645 | ID = ID >> 1; |
| 646 | |
| 647 | if (!IsInteresting) { |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 648 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 649 | // and associate it with the persistent ID. |
| 650 | IdentifierInfo *II = KnownII; |
| 651 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 652 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 653 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 654 | II->setIsFromAST(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 655 | return II; |
| 656 | } |
| 657 | |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 658 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 659 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 660 | Bits >>= 1; |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 661 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 662 | Bits >>= 1; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 663 | bool Poisoned = Bits & 0x01; |
| 664 | Bits >>= 1; |
| 665 | bool ExtensionToken = Bits & 0x01; |
| 666 | Bits >>= 1; |
| 667 | bool hasMacroDefinition = Bits & 0x01; |
| 668 | Bits >>= 1; |
| 669 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 670 | Bits >>= 10; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 671 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 672 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 673 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 674 | |
| 675 | // Build the IdentifierInfo itself and link the identifier ID with |
| 676 | // the new IdentifierInfo. |
| 677 | IdentifierInfo *II = KnownII; |
| 678 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 679 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 680 | Reader.SetIdentifierInfo(ID, II); |
| 681 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 682 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 683 | // Token IDs are read-only. |
| 684 | if (HasRevertedTokenIDToIdentifier) |
| 685 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 686 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 687 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 688 | "Incorrect extension token flag"); |
| 689 | (void)ExtensionToken; |
| 690 | II->setIsPoisoned(Poisoned); |
| 691 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 692 | "Incorrect C++ operator keyword flag"); |
| 693 | (void)CPlusPlusOperatorKeyword; |
| 694 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 695 | // If this identifier is a macro, deserialize the macro |
| 696 | // definition. |
| 697 | if (hasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 698 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 699 | Reader.SetIdentifierIsMacro(II, F, Offset); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 700 | DataLen -= 4; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 701 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 702 | |
| 703 | // Read all of the declarations visible at global scope with this |
| 704 | // name. |
Chris Lattner | 6bf690f | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 705 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 706 | if (DataLen > 0) { |
| 707 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 708 | for (; DataLen > 0; DataLen -= 4) |
| 709 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 710 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 711 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 712 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 713 | II->setIsFromAST(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 714 | return II; |
| 715 | } |
| 716 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 717 | |
| 718 | } // end anonymous namespace |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 719 | |
| 720 | /// \brief The on-disk hash table used to contain information about |
| 721 | /// all of the identifiers in the program. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 722 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 723 | ASTIdentifierLookupTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 724 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 725 | namespace { |
| 726 | class ASTDeclContextNameLookupTrait { |
| 727 | ASTReader &Reader; |
| 728 | |
| 729 | public: |
| 730 | /// \brief Pair of begin/end iterators for DeclIDs. |
| 731 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 732 | |
| 733 | /// \brief Special internal key for declaration names. |
| 734 | /// The hash table creates keys for comparison; we do not create |
| 735 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 736 | struct DeclNameKey { |
| 737 | DeclarationName::NameKind Kind; |
| 738 | uint64_t Data; |
| 739 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 740 | }; |
| 741 | |
| 742 | typedef DeclarationName external_key_type; |
| 743 | typedef DeclNameKey internal_key_type; |
| 744 | |
| 745 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
| 746 | |
| 747 | static bool EqualKey(const internal_key_type& a, |
| 748 | const internal_key_type& b) { |
| 749 | return a.Kind == b.Kind && a.Data == b.Data; |
| 750 | } |
| 751 | |
| 752 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 753 | llvm::FoldingSetNodeID ID; |
| 754 | ID.AddInteger(Key.Kind); |
| 755 | |
| 756 | switch (Key.Kind) { |
| 757 | case DeclarationName::Identifier: |
| 758 | case DeclarationName::CXXLiteralOperatorName: |
| 759 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 760 | break; |
| 761 | case DeclarationName::ObjCZeroArgSelector: |
| 762 | case DeclarationName::ObjCOneArgSelector: |
| 763 | case DeclarationName::ObjCMultiArgSelector: |
| 764 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 765 | break; |
| 766 | case DeclarationName::CXXConstructorName: |
| 767 | case DeclarationName::CXXDestructorName: |
| 768 | case DeclarationName::CXXConversionFunctionName: |
| 769 | ID.AddInteger((TypeID)Key.Data); |
| 770 | break; |
| 771 | case DeclarationName::CXXOperatorName: |
| 772 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 773 | break; |
| 774 | case DeclarationName::CXXUsingDirective: |
| 775 | break; |
| 776 | } |
| 777 | |
| 778 | return ID.ComputeHash(); |
| 779 | } |
| 780 | |
| 781 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 782 | DeclNameKey Key; |
| 783 | Key.Kind = Name.getNameKind(); |
| 784 | switch (Name.getNameKind()) { |
| 785 | case DeclarationName::Identifier: |
| 786 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 787 | break; |
| 788 | case DeclarationName::ObjCZeroArgSelector: |
| 789 | case DeclarationName::ObjCOneArgSelector: |
| 790 | case DeclarationName::ObjCMultiArgSelector: |
| 791 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 792 | break; |
| 793 | case DeclarationName::CXXConstructorName: |
| 794 | case DeclarationName::CXXDestructorName: |
| 795 | case DeclarationName::CXXConversionFunctionName: |
| 796 | Key.Data = Reader.GetTypeID(Name.getCXXNameType()); |
| 797 | break; |
| 798 | case DeclarationName::CXXOperatorName: |
| 799 | Key.Data = Name.getCXXOverloadedOperator(); |
| 800 | break; |
| 801 | case DeclarationName::CXXLiteralOperatorName: |
| 802 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 803 | break; |
| 804 | case DeclarationName::CXXUsingDirective: |
| 805 | break; |
| 806 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 807 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 808 | return Key; |
| 809 | } |
| 810 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 811 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 812 | ASTContext *Context = Reader.getContext(); |
| 813 | switch (Key.Kind) { |
| 814 | case DeclarationName::Identifier: |
| 815 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 816 | |
| 817 | case DeclarationName::ObjCZeroArgSelector: |
| 818 | case DeclarationName::ObjCOneArgSelector: |
| 819 | case DeclarationName::ObjCMultiArgSelector: |
| 820 | return DeclarationName(Selector(Key.Data)); |
| 821 | |
| 822 | case DeclarationName::CXXConstructorName: |
| 823 | return Context->DeclarationNames.getCXXConstructorName( |
| 824 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 825 | |
| 826 | case DeclarationName::CXXDestructorName: |
| 827 | return Context->DeclarationNames.getCXXDestructorName( |
| 828 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 829 | |
| 830 | case DeclarationName::CXXConversionFunctionName: |
| 831 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 832 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 833 | |
| 834 | case DeclarationName::CXXOperatorName: |
| 835 | return Context->DeclarationNames.getCXXOperatorName( |
| 836 | (OverloadedOperatorKind)Key.Data); |
| 837 | |
| 838 | case DeclarationName::CXXLiteralOperatorName: |
| 839 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 840 | (IdentifierInfo*)Key.Data); |
| 841 | |
| 842 | case DeclarationName::CXXUsingDirective: |
| 843 | return DeclarationName::getUsingDirectiveName(); |
| 844 | } |
| 845 | |
| 846 | llvm_unreachable("Invalid Name Kind ?"); |
| 847 | } |
| 848 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 849 | static std::pair<unsigned, unsigned> |
| 850 | ReadKeyDataLength(const unsigned char*& d) { |
| 851 | using namespace clang::io; |
| 852 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 853 | unsigned DataLen = ReadUnalignedLE16(d); |
| 854 | return std::make_pair(KeyLen, DataLen); |
| 855 | } |
| 856 | |
| 857 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 858 | using namespace clang::io; |
| 859 | |
| 860 | DeclNameKey Key; |
| 861 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 862 | switch (Key.Kind) { |
| 863 | case DeclarationName::Identifier: |
| 864 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 865 | break; |
| 866 | case DeclarationName::ObjCZeroArgSelector: |
| 867 | case DeclarationName::ObjCOneArgSelector: |
| 868 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 869 | Key.Data = |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 870 | (uint64_t)Reader.DecodeSelector(ReadUnalignedLE32(d)).getAsOpaquePtr(); |
| 871 | break; |
| 872 | case DeclarationName::CXXConstructorName: |
| 873 | case DeclarationName::CXXDestructorName: |
| 874 | case DeclarationName::CXXConversionFunctionName: |
| 875 | Key.Data = ReadUnalignedLE32(d); // TypeID |
| 876 | break; |
| 877 | case DeclarationName::CXXOperatorName: |
| 878 | Key.Data = *d++; // OverloadedOperatorKind |
| 879 | break; |
| 880 | case DeclarationName::CXXLiteralOperatorName: |
| 881 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 882 | break; |
| 883 | case DeclarationName::CXXUsingDirective: |
| 884 | break; |
| 885 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 886 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 887 | return Key; |
| 888 | } |
| 889 | |
| 890 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 891 | unsigned DataLen) { |
| 892 | using namespace clang::io; |
| 893 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 894 | DeclID *Start = (DeclID *)d; |
| 895 | return std::make_pair(Start, Start + NumDecls); |
| 896 | } |
| 897 | }; |
| 898 | |
| 899 | } // end anonymous namespace |
| 900 | |
| 901 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 902 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 903 | ASTDeclContextNameLookupTable; |
| 904 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 905 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 906 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 907 | DeclContextInfo &Info) { |
| 908 | SavedStreamPosition SavedPosition(Cursor); |
| 909 | // First the lexical decls. |
| 910 | if (Offsets.first != 0) { |
| 911 | Cursor.JumpToBit(Offsets.first); |
| 912 | |
| 913 | RecordData Record; |
| 914 | const char *Blob; |
| 915 | unsigned BlobLen; |
| 916 | unsigned Code = Cursor.ReadCode(); |
| 917 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 918 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 919 | Error("Expected lexical block"); |
| 920 | return true; |
| 921 | } |
| 922 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 923 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 924 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 925 | } else { |
| 926 | Info.LexicalDecls = 0; |
| 927 | Info.NumLexicalDecls = 0; |
| 928 | } |
| 929 | |
| 930 | // Now the lookup table. |
| 931 | if (Offsets.second != 0) { |
| 932 | Cursor.JumpToBit(Offsets.second); |
| 933 | |
| 934 | RecordData Record; |
| 935 | const char *Blob; |
| 936 | unsigned BlobLen; |
| 937 | unsigned Code = Cursor.ReadCode(); |
| 938 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 939 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 940 | Error("Expected visible lookup table block"); |
| 941 | return true; |
| 942 | } |
| 943 | Info.NameLookupTableData |
| 944 | = ASTDeclContextNameLookupTable::Create( |
| 945 | (const unsigned char *)Blob + Record[0], |
| 946 | (const unsigned char *)Blob, |
| 947 | ASTDeclContextNameLookupTrait(*this)); |
Sebastian Redl | 0ea8f7f | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 948 | } else { |
| 949 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | return false; |
| 953 | } |
| 954 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 955 | void ASTReader::Error(const char *Msg) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 956 | Diag(diag::err_fe_pch_malformed) << Msg; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 957 | } |
| 958 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 959 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 960 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 961 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 962 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 963 | ActualOriginalFileName, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 964 | SuggestedPredefines); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 965 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 966 | } |
| 967 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 968 | //===----------------------------------------------------------------------===// |
| 969 | // Source Manager Deserialization |
| 970 | //===----------------------------------------------------------------------===// |
| 971 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 972 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 973 | /// \returns true if there was an error. |
| 974 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 975 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 976 | unsigned Idx = 0; |
| 977 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 978 | |
| 979 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 980 | std::map<int, int> FileIDs; |
| 981 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 982 | // Extract the file name |
| 983 | unsigned FilenameLen = Record[Idx++]; |
| 984 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 985 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 986 | MaybeAddSystemRootToFilename(Filename); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 987 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 988 | Filename.size()); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | // Parse the line entries |
| 992 | std::vector<LineEntry> Entries; |
| 993 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 994 | int FID = Record[Idx++]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 995 | |
| 996 | // Extract the line entries |
| 997 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 998 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 999 | Entries.clear(); |
| 1000 | Entries.reserve(NumEntries); |
| 1001 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1002 | unsigned FileOffset = Record[Idx++]; |
| 1003 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1004 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1005 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1006 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1007 | unsigned IncludeOffset = Record[Idx++]; |
| 1008 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1009 | FileKind, IncludeOffset)); |
| 1010 | } |
| 1011 | LineTable.AddEntry(FID, Entries); |
| 1012 | } |
| 1013 | |
| 1014 | return false; |
| 1015 | } |
| 1016 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1017 | namespace { |
| 1018 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1019 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1020 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1021 | const ino_t ino; |
| 1022 | const dev_t dev; |
| 1023 | const mode_t mode; |
| 1024 | const time_t mtime; |
| 1025 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1026 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1027 | 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] | 1028 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1029 | }; |
| 1030 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1031 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1032 | public: |
| 1033 | typedef const char *external_key_type; |
| 1034 | typedef const char *internal_key_type; |
| 1035 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1036 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1037 | |
| 1038 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1039 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1043 | |
| 1044 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1045 | return strcmp(a, b) == 0; |
| 1046 | } |
| 1047 | |
| 1048 | static std::pair<unsigned, unsigned> |
| 1049 | ReadKeyDataLength(const unsigned char*& d) { |
| 1050 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1051 | unsigned DataLen = (unsigned) *d++; |
| 1052 | return std::make_pair(KeyLen + 1, DataLen); |
| 1053 | } |
| 1054 | |
| 1055 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1056 | return (const char *)d; |
| 1057 | } |
| 1058 | |
| 1059 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1060 | unsigned /*DataLen*/) { |
| 1061 | using namespace clang::io; |
| 1062 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1063 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1064 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1065 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1066 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1067 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1068 | return data_type(ino, dev, mode, mtime, size); |
| 1069 | } |
| 1070 | }; |
| 1071 | |
| 1072 | /// \brief stat() cache for precompiled headers. |
| 1073 | /// |
| 1074 | /// This cache is very similar to the stat cache used by pretokenized |
| 1075 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1076 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1077 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1078 | CacheTy *Cache; |
| 1079 | |
| 1080 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1081 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1082 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1083 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1084 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1085 | Cache = CacheTy::Create(Buckets, Base); |
| 1086 | } |
| 1087 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1088 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1089 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1090 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1091 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1092 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1093 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1094 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1095 | // 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] | 1096 | if (I == Cache->end()) { |
| 1097 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1098 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1099 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1100 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1101 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1102 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1103 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1104 | StatBuf.st_ino = Data.ino; |
| 1105 | StatBuf.st_dev = Data.dev; |
| 1106 | StatBuf.st_mtime = Data.mtime; |
| 1107 | StatBuf.st_mode = Data.mode; |
| 1108 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1109 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1110 | } |
| 1111 | }; |
| 1112 | } // end anonymous namespace |
| 1113 | |
| 1114 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1115 | /// \brief Read a source manager block |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1116 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1117 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1118 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1119 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1120 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1121 | // Set the source-location entry cursor to the current position in |
| 1122 | // the stream. This cursor will be used to read the contents of the |
| 1123 | // source manager block initially, and then lazily read |
| 1124 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1125 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1126 | |
| 1127 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1128 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1129 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1130 | return Failure; |
| 1131 | } |
| 1132 | |
| 1133 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1134 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1135 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1136 | return Failure; |
| 1137 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1138 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1139 | RecordData Record; |
| 1140 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1141 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1142 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1143 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1144 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1145 | return Failure; |
| 1146 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1147 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1148 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1149 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1150 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1151 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1152 | SLocEntryCursor.ReadSubBlockID(); |
| 1153 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1154 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1155 | return Failure; |
| 1156 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1157 | continue; |
| 1158 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1159 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1160 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1161 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1162 | continue; |
| 1163 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1164 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1165 | // Read a record. |
| 1166 | const char *BlobStart; |
| 1167 | unsigned BlobLen; |
| 1168 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1169 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1170 | default: // Default behavior: ignore. |
| 1171 | break; |
| 1172 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1173 | case SM_LINE_TABLE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1174 | if (ParseLineTable(F, Record)) |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1175 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1176 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1177 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1178 | case SM_SLOC_FILE_ENTRY: |
| 1179 | case SM_SLOC_BUFFER_ENTRY: |
| 1180 | case SM_SLOC_INSTANTIATION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1181 | // Once we hit one of the source location entries, we're done. |
| 1182 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | } |
| 1186 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1187 | /// \brief If a header file is not found at the path that we expect it to be |
| 1188 | /// and the PCH file was moved from its original location, try to resolve the |
| 1189 | /// file by assuming that header+PCH were moved together and the header is in |
| 1190 | /// the same place relative to the PCH. |
| 1191 | static std::string |
| 1192 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1193 | const std::string &OriginalDir, |
| 1194 | const std::string &CurrDir) { |
| 1195 | assert(OriginalDir != CurrDir && |
| 1196 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1197 | using namespace llvm::sys; |
| 1198 | llvm::SmallString<128> filePath(Filename); |
| 1199 | fs::make_absolute(filePath); |
| 1200 | assert(path::is_absolute(OriginalDir)); |
| 1201 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1202 | |
| 1203 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1204 | fileDirE = path::end(path::parent_path(filePath)); |
| 1205 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1206 | origDirE = path::end(OriginalDir); |
| 1207 | // Skip the common path components from filePath and OriginalDir. |
| 1208 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1209 | *fileDirI == *origDirI) { |
| 1210 | ++fileDirI; |
| 1211 | ++origDirI; |
| 1212 | } |
| 1213 | for (; origDirI != origDirE; ++origDirI) |
| 1214 | path::append(currPCHPath, ".."); |
| 1215 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1216 | path::append(currPCHPath, path::filename(Filename)); |
| 1217 | return currPCHPath.str(); |
| 1218 | } |
| 1219 | |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1220 | /// \brief Get a cursor that's correctly positioned for reading the source |
| 1221 | /// location entry with the given ID. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1222 | ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1223 | assert(ID != 0 && ID <= TotalNumSLocEntries && |
| 1224 | "SLocCursorForID should only be called for real IDs."); |
| 1225 | |
| 1226 | ID -= 1; |
| 1227 | PerFileData *F = 0; |
| 1228 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1229 | F = Chain[N - I - 1]; |
| 1230 | if (ID < F->LocalNumSLocEntries) |
| 1231 | break; |
| 1232 | ID -= F->LocalNumSLocEntries; |
| 1233 | } |
| 1234 | assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); |
| 1235 | |
| 1236 | F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1237 | return F; |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1240 | /// \brief Read in the source location entry with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1241 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1242 | if (ID == 0) |
| 1243 | return Success; |
| 1244 | |
| 1245 | if (ID > TotalNumSLocEntries) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1246 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1247 | return Failure; |
| 1248 | } |
| 1249 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1250 | PerFileData *F = SLocCursorForID(ID); |
| 1251 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1252 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1253 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1254 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1255 | if (Code == llvm::bitc::END_BLOCK || |
| 1256 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1257 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1258 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1259 | return Failure; |
| 1260 | } |
| 1261 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1262 | RecordData Record; |
| 1263 | const char *BlobStart; |
| 1264 | unsigned BlobLen; |
| 1265 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1266 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1267 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1268 | return Failure; |
| 1269 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1270 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1271 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1272 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1273 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1274 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1275 | OriginalDir != CurrentDir) { |
| 1276 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1277 | OriginalDir, |
| 1278 | CurrentDir); |
| 1279 | if (!resolved.empty()) |
| 1280 | File = FileMgr.getFile(resolved); |
| 1281 | } |
Axel Naumann | 0433116 | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1282 | if (File == 0) |
| 1283 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1284 | (time_t)Record[5]); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1285 | if (File == 0) { |
| 1286 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1287 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1288 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1289 | Error(ErrorStr.c_str()); |
| 1290 | return Failure; |
| 1291 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1292 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1293 | if (Record.size() < 6) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1294 | Error("source location entry is incorrect"); |
| 1295 | return Failure; |
| 1296 | } |
| 1297 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1298 | if (!DisableValidation && |
| 1299 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1300 | #if !defined(LLVM_ON_WIN32) |
| 1301 | // In our regression testing, the Windows file system seems to |
| 1302 | // have inconsistent modification times that sometimes |
| 1303 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1304 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1305 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1306 | )) { |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1307 | Diag(diag::err_fe_pch_file_modified) |
| 1308 | << Filename; |
| 1309 | return Failure; |
| 1310 | } |
| 1311 | |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1312 | FileID FID = SourceMgr.createFileID(File, ReadSourceLocation(*F, Record[1]), |
| 1313 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1314 | ID, Record[0]); |
| 1315 | if (Record[3]) |
| 1316 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1317 | .setHasLineDirectives(); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1318 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1319 | break; |
| 1320 | } |
| 1321 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1322 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1323 | const char *Name = BlobStart; |
| 1324 | unsigned Offset = Record[0]; |
| 1325 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1326 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1327 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1328 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1329 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1330 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1331 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1332 | return Failure; |
| 1333 | } |
| 1334 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1335 | llvm::MemoryBuffer *Buffer |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1336 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1337 | Name); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1338 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1339 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1340 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1341 | PCHPredefinesBlock Block = { |
| 1342 | BufferID, |
| 1343 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1344 | }; |
| 1345 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1346 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1347 | |
| 1348 | break; |
| 1349 | } |
| 1350 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1351 | case SM_SLOC_INSTANTIATION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1352 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1353 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1354 | ReadSourceLocation(*F, Record[2]), |
| 1355 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1356 | Record[4], |
| 1357 | ID, |
| 1358 | Record[0]); |
| 1359 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1360 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | return Success; |
| 1364 | } |
| 1365 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1366 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1367 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1368 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1369 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1370 | unsigned BlockID) { |
| 1371 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1372 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1373 | return Failure; |
| 1374 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1375 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1376 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1377 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1378 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1379 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1380 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1381 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1382 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1383 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1384 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1385 | Cursor.ReadAbbrevRecord(); |
| 1386 | } |
| 1387 | } |
| 1388 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1389 | PreprocessedEntity *ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1390 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1391 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1392 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1393 | // Keep track of where we are in the stream, then jump back there |
| 1394 | // after reading this macro. |
| 1395 | SavedStreamPosition SavedPosition(Stream); |
| 1396 | |
| 1397 | Stream.JumpToBit(Offset); |
| 1398 | RecordData Record; |
| 1399 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1400 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1401 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1402 | while (true) { |
| 1403 | unsigned Code = Stream.ReadCode(); |
| 1404 | switch (Code) { |
| 1405 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1406 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1407 | |
| 1408 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1409 | // No known subblocks, always skip them. |
| 1410 | Stream.ReadSubBlockID(); |
| 1411 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1412 | Error("malformed block record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1413 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1414 | } |
| 1415 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1417 | case llvm::bitc::DEFINE_ABBREV: |
| 1418 | Stream.ReadAbbrevRecord(); |
| 1419 | continue; |
| 1420 | default: break; |
| 1421 | } |
| 1422 | |
| 1423 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1424 | const char *BlobStart = 0; |
| 1425 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1426 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1427 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1428 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1429 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1430 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1431 | case PP_MACRO_OBJECT_LIKE: |
| 1432 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1433 | // If we already have a macro, that means that we've hit the end |
| 1434 | // of the definition of the macro we were looking for. We're |
| 1435 | // done. |
| 1436 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1437 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1438 | |
| 1439 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1440 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1441 | Error("macro must have a name in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1442 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1443 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1444 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1445 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1446 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1447 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1448 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1449 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1450 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1451 | unsigned NextIndex = 3; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1452 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1453 | // Decode function-like macro info. |
| 1454 | bool isC99VarArgs = Record[3]; |
| 1455 | bool isGNUVarArgs = Record[4]; |
| 1456 | MacroArgs.clear(); |
| 1457 | unsigned NumArgs = Record[5]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1458 | NextIndex = 6 + NumArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1459 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1460 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1461 | |
| 1462 | // Install function-like macro info. |
| 1463 | MI->setIsFunctionLike(); |
| 1464 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1465 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1466 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1467 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1471 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1472 | |
| 1473 | // Remember that we saw this macro last so that we add the tokens that |
| 1474 | // form its body to it. |
| 1475 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1476 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1477 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1478 | // We have a macro definition. Load it now. |
| 1479 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1480 | getMacroDefinition(Record[NextIndex])); |
| 1481 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1482 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1483 | ++NumMacrosRead; |
| 1484 | break; |
| 1485 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1486 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1487 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1488 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1489 | // erroneous, just pretend we didn't see this. |
| 1490 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1491 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1492 | Token Tok; |
| 1493 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1494 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1495 | Tok.setLength(Record[1]); |
| 1496 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1497 | Tok.setIdentifierInfo(II); |
| 1498 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1499 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1500 | Macro->AddTokenToBody(Tok); |
| 1501 | break; |
| 1502 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1503 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1504 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1505 | |
| 1506 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1509 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(PerFileData &F) { |
| 1510 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1511 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1512 | switch (Code) { |
| 1513 | case llvm::bitc::END_BLOCK: |
| 1514 | return 0; |
| 1515 | |
| 1516 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1517 | Error("unexpected subblock record in preprocessor detail block"); |
| 1518 | return 0; |
| 1519 | |
| 1520 | case llvm::bitc::DEFINE_ABBREV: |
| 1521 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1522 | return 0; |
| 1523 | |
| 1524 | default: |
| 1525 | break; |
| 1526 | } |
| 1527 | |
| 1528 | if (!PP->getPreprocessingRecord()) { |
| 1529 | Error("no preprocessing record"); |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | // Read the record. |
| 1534 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1535 | const char *BlobStart = 0; |
| 1536 | unsigned BlobLen = 0; |
| 1537 | RecordData Record; |
| 1538 | PreprocessorDetailRecordTypes RecType = |
| 1539 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1540 | Code, Record, BlobStart, BlobLen); |
| 1541 | switch (RecType) { |
| 1542 | case PPD_MACRO_INSTANTIATION: { |
| 1543 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1544 | return PE; |
| 1545 | |
| 1546 | MacroInstantiation *MI |
| 1547 | = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), |
| 1548 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1549 | ReadSourceLocation(F, Record[2])), |
| 1550 | getMacroDefinition(Record[4])); |
| 1551 | PPRec.SetPreallocatedEntity(Record[0], MI); |
| 1552 | return MI; |
| 1553 | } |
| 1554 | |
| 1555 | case PPD_MACRO_DEFINITION: { |
| 1556 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1557 | return PE; |
| 1558 | |
| 1559 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
| 1560 | Error("out-of-bounds macro definition record"); |
| 1561 | return 0; |
| 1562 | } |
| 1563 | |
| 1564 | // Decode the identifier info and then check again; if the macro is |
| 1565 | // still defined and associated with the identifier, |
| 1566 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1567 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1568 | MacroDefinition *MD |
| 1569 | = new (PPRec) MacroDefinition(II, |
| 1570 | ReadSourceLocation(F, Record[5]), |
| 1571 | SourceRange( |
| 1572 | ReadSourceLocation(F, Record[2]), |
| 1573 | ReadSourceLocation(F, Record[3]))); |
| 1574 | |
| 1575 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1576 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
| 1577 | |
| 1578 | if (DeserializationListener) |
| 1579 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1580 | } |
| 1581 | |
| 1582 | return MacroDefinitionsLoaded[Record[1] - 1]; |
| 1583 | } |
| 1584 | |
| 1585 | case PPD_INCLUSION_DIRECTIVE: { |
| 1586 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1587 | return PE; |
| 1588 | |
| 1589 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1590 | const FileEntry *File |
| 1591 | = PP->getFileManager().getFile(llvm::StringRef(FullFileNameStart, |
| 1592 | BlobLen - Record[3])); |
| 1593 | |
| 1594 | // FIXME: Stable encoding |
| 1595 | InclusionDirective::InclusionKind Kind |
| 1596 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1597 | InclusionDirective *ID |
| 1598 | = new (PPRec) InclusionDirective(PPRec, Kind, |
| 1599 | llvm::StringRef(BlobStart, Record[3]), |
| 1600 | Record[4], |
| 1601 | File, |
| 1602 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1603 | ReadSourceLocation(F, Record[2]))); |
| 1604 | PPRec.SetPreallocatedEntity(Record[0], ID); |
| 1605 | return ID; |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | Error("invalid offset in preprocessor detail block"); |
| 1610 | return 0; |
| 1611 | } |
| 1612 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1613 | namespace { |
| 1614 | /// \brief Trait class used to search the on-disk hash table containing all of |
| 1615 | /// the header search information. |
| 1616 | /// |
| 1617 | /// The on-disk hash table contains a mapping from each header path to |
| 1618 | /// information about that header (how many times it has been included, its |
| 1619 | /// controlling macro, etc.). Note that we actually hash based on the |
| 1620 | /// filename, and support "deep" comparisons of file names based on current |
| 1621 | /// inode numbers, so that the search can cope with non-normalized path names |
| 1622 | /// and symlinks. |
| 1623 | class HeaderFileInfoTrait { |
| 1624 | const char *SearchPath; |
| 1625 | struct stat SearchPathStatBuf; |
| 1626 | llvm::Optional<int> SearchPathStatResult; |
| 1627 | |
| 1628 | int StatSimpleCache(const char *Path, struct stat *StatBuf) { |
| 1629 | if (Path == SearchPath) { |
| 1630 | if (!SearchPathStatResult) |
| 1631 | SearchPathStatResult = stat(Path, &SearchPathStatBuf); |
| 1632 | |
| 1633 | *StatBuf = SearchPathStatBuf; |
| 1634 | return *SearchPathStatResult; |
| 1635 | } |
| 1636 | |
| 1637 | return stat(Path, StatBuf); |
| 1638 | } |
| 1639 | |
| 1640 | public: |
| 1641 | typedef const char *external_key_type; |
| 1642 | typedef const char *internal_key_type; |
| 1643 | |
| 1644 | typedef HeaderFileInfo data_type; |
| 1645 | |
| 1646 | HeaderFileInfoTrait(const char *SearchPath = 0) : SearchPath(SearchPath) { } |
| 1647 | |
| 1648 | static unsigned ComputeHash(const char *path) { |
| 1649 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1650 | } |
| 1651 | |
| 1652 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1653 | |
| 1654 | bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1655 | if (strcmp(a, b) == 0) |
| 1656 | return true; |
| 1657 | |
| 1658 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1659 | return false; |
| 1660 | |
| 1661 | // The file names match, but the path names don't. stat() the files to |
| 1662 | // see if they are the same. |
| 1663 | struct stat StatBufA, StatBufB; |
| 1664 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1665 | return false; |
| 1666 | |
| 1667 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1668 | } |
| 1669 | |
| 1670 | static std::pair<unsigned, unsigned> |
| 1671 | ReadKeyDataLength(const unsigned char*& d) { |
| 1672 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1673 | unsigned DataLen = (unsigned) *d++; |
| 1674 | return std::make_pair(KeyLen + 1, DataLen); |
| 1675 | } |
| 1676 | |
| 1677 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1678 | return (const char *)d; |
| 1679 | } |
| 1680 | |
| 1681 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1682 | unsigned DataLen) { |
| 1683 | const unsigned char *End = d + DataLen; |
| 1684 | using namespace clang::io; |
| 1685 | HeaderFileInfo HFI; |
| 1686 | unsigned Flags = *d++; |
| 1687 | HFI.isImport = (Flags >> 3) & 0x01; |
| 1688 | HFI.DirInfo = (Flags >> 1) & 0x03; |
| 1689 | HFI.Resolved = Flags & 0x01; |
| 1690 | HFI.NumIncludes = ReadUnalignedLE16(d); |
| 1691 | HFI.ControllingMacroID = ReadUnalignedLE32(d); |
| 1692 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1693 | (void)End; |
| 1694 | |
| 1695 | // This HeaderFileInfo was externally loaded. |
| 1696 | HFI.External = true; |
| 1697 | return HFI; |
| 1698 | } |
| 1699 | }; |
| 1700 | } |
| 1701 | |
| 1702 | /// \brief The on-disk hash table used for the global method pool. |
| 1703 | typedef OnDiskChainedHashTable<HeaderFileInfoTrait> |
| 1704 | HeaderFileInfoLookupTable; |
| 1705 | |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1706 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F, |
| 1707 | uint64_t Offset) { |
| 1708 | // Note that this identifier has a macro definition. |
| 1709 | II->setHasMacroDefinition(true); |
| 1710 | |
| 1711 | // Adjust the offset based on our position in the chain. |
| 1712 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1713 | if (Chain[I] == &F) |
| 1714 | break; |
| 1715 | |
| 1716 | Offset += Chain[I]->SizeInBits; |
| 1717 | } |
| 1718 | |
| 1719 | UnreadMacroRecordOffsets[II] = Offset; |
| 1720 | } |
| 1721 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1722 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1723 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1724 | PerFileData &F = *Chain[N - I - 1]; |
| 1725 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1726 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1727 | // If there was no preprocessor block, skip this file. |
| 1728 | if (!MacroCursor.getBitStreamReader()) |
| 1729 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1730 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1731 | llvm::BitstreamCursor Cursor = MacroCursor; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1732 | Cursor.JumpToBit(F.MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1733 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1734 | RecordData Record; |
| 1735 | while (true) { |
| 1736 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1737 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1738 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1739 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1740 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1741 | // No known subblocks, always skip them. |
| 1742 | Cursor.ReadSubBlockID(); |
| 1743 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1744 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1745 | return; |
| 1746 | } |
| 1747 | continue; |
| 1748 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1749 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1750 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1751 | Cursor.ReadAbbrevRecord(); |
| 1752 | continue; |
| 1753 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1754 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1755 | // Read a record. |
| 1756 | const char *BlobStart; |
| 1757 | unsigned BlobLen; |
| 1758 | Record.clear(); |
| 1759 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1760 | default: // Default behavior: ignore. |
| 1761 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1762 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1763 | case PP_MACRO_OBJECT_LIKE: |
| 1764 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1765 | DecodeIdentifierInfo(Record[0]); |
| 1766 | break; |
| 1767 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1768 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1769 | // Ignore tokens. |
| 1770 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1771 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1772 | } |
| 1773 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1774 | |
| 1775 | // Drain the unread macro-record offsets map. |
| 1776 | while (!UnreadMacroRecordOffsets.empty()) |
| 1777 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1778 | } |
| 1779 | |
| 1780 | void ASTReader::LoadMacroDefinition( |
| 1781 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1782 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
| 1783 | PerFileData *F = 0; |
| 1784 | uint64_t Offset = Pos->second; |
| 1785 | UnreadMacroRecordOffsets.erase(Pos); |
| 1786 | |
| 1787 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1788 | if (Offset < Chain[I]->SizeInBits) { |
| 1789 | F = Chain[I]; |
| 1790 | break; |
| 1791 | } |
| 1792 | |
| 1793 | Offset -= Chain[I]->SizeInBits; |
| 1794 | } |
| 1795 | if (!F) { |
| 1796 | Error("Malformed macro record offset"); |
| 1797 | return; |
| 1798 | } |
| 1799 | |
| 1800 | ReadMacroRecord(*F, Offset); |
| 1801 | } |
| 1802 | |
| 1803 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1804 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1805 | = UnreadMacroRecordOffsets.find(II); |
| 1806 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1809 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1810 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1811 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1812 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1813 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1814 | unsigned Index = ID - 1; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1815 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1816 | PerFileData &F = *Chain[N - I - 1]; |
| 1817 | if (Index < F.LocalNumMacroDefinitions) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1818 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 1819 | F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]); |
| 1820 | LoadPreprocessedEntity(F); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1821 | break; |
| 1822 | } |
| 1823 | Index -= F.LocalNumMacroDefinitions; |
| 1824 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1825 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1828 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1831 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1832 | /// not an absolute path, add the system root to the beginning of the file |
| 1833 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1834 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1835 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1836 | if (!RelocatablePCH) |
| 1837 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1838 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1839 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1840 | return; |
| 1841 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1842 | if (isysroot == 0) { |
| 1843 | // If no system root was given, default to '/' |
| 1844 | Filename.insert(Filename.begin(), '/'); |
| 1845 | return; |
| 1846 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1847 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1848 | unsigned Length = strlen(isysroot); |
| 1849 | if (isysroot[Length - 1] != '/') |
| 1850 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1851 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1852 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1853 | } |
| 1854 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1855 | ASTReader::ASTReadResult |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1856 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1857 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1858 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1859 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1860 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1861 | return Failure; |
| 1862 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1863 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1864 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1865 | RecordData Record; |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1866 | bool First = true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1867 | while (!Stream.AtEndOfStream()) { |
| 1868 | unsigned Code = Stream.ReadCode(); |
| 1869 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1870 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1871 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1872 | return Failure; |
| 1873 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1874 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1875 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1879 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1880 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1881 | // We lazily load the decls block, but we want to set up the |
| 1882 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1883 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1884 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1885 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1886 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1887 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1888 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1889 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1890 | return Failure; |
| 1891 | } |
| 1892 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1893 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1894 | case DECL_UPDATES_BLOCK_ID: |
| 1895 | if (Stream.SkipBlock()) { |
| 1896 | Error("malformed block record in AST file"); |
| 1897 | return Failure; |
| 1898 | } |
| 1899 | break; |
| 1900 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1901 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1902 | F.MacroCursor = Stream; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1903 | if (PP) |
| 1904 | PP->setExternalSource(this); |
| 1905 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1906 | if (Stream.SkipBlock() || |
| 1907 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1908 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1909 | return Failure; |
| 1910 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1911 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1912 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1913 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1914 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1915 | F.PreprocessorDetailCursor = Stream; |
| 1916 | if (Stream.SkipBlock() || |
| 1917 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1918 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1919 | Error("malformed preprocessor detail record in AST file"); |
| 1920 | return Failure; |
| 1921 | } |
| 1922 | F.PreprocessorDetailStartOffset |
| 1923 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 1924 | break; |
| 1925 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1926 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1927 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1928 | case Success: |
| 1929 | break; |
| 1930 | |
| 1931 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1932 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1933 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1934 | |
| 1935 | case IgnorePCH: |
| 1936 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1937 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1938 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1939 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1940 | First = false; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1941 | continue; |
| 1942 | } |
| 1943 | |
| 1944 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1945 | Stream.ReadAbbrevRecord(); |
| 1946 | continue; |
| 1947 | } |
| 1948 | |
| 1949 | // Read and process a record. |
| 1950 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1951 | const char *BlobStart = 0; |
| 1952 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1953 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1954 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1955 | default: // Default behavior: ignore. |
| 1956 | break; |
| 1957 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1958 | case METADATA: { |
| 1959 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1960 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1961 | : diag::warn_pch_version_too_new); |
| 1962 | return IgnorePCH; |
| 1963 | } |
| 1964 | |
| 1965 | RelocatablePCH = Record[4]; |
| 1966 | if (Listener) { |
| 1967 | std::string TargetTriple(BlobStart, BlobLen); |
| 1968 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1969 | return IgnorePCH; |
| 1970 | } |
| 1971 | break; |
| 1972 | } |
| 1973 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1974 | case CHAINED_METADATA: { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1975 | if (!First) { |
| 1976 | Error("CHAINED_METADATA is not first record in block"); |
| 1977 | return Failure; |
| 1978 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1979 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1980 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1981 | : diag::warn_pch_version_too_new); |
| 1982 | return IgnorePCH; |
| 1983 | } |
| 1984 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 1985 | // Load the chained file, which is always a PCH file. |
| 1986 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1987 | case Failure: return Failure; |
| 1988 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1989 | case IgnorePCH: return IgnorePCH; |
| 1990 | case Success: break; |
| 1991 | } |
| 1992 | break; |
| 1993 | } |
| 1994 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1995 | case TYPE_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1996 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1997 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1998 | return Failure; |
| 1999 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2000 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 2001 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2002 | break; |
| 2003 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2004 | case DECL_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2005 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2006 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2007 | return Failure; |
| 2008 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2009 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 2010 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2011 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2012 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2013 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2014 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2015 | /* No visible information */ 0, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2016 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 2017 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2018 | }; |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2019 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 2020 | .push_back(Info); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2021 | break; |
| 2022 | } |
| 2023 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2024 | case UPDATE_VISIBLE: { |
| 2025 | serialization::DeclID ID = Record[0]; |
| 2026 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 2027 | (const unsigned char *)BlobStart + Record[1], |
| 2028 | (const unsigned char *)BlobStart, |
| 2029 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2030 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2031 | DeclContextInfo Info = { |
| 2032 | Table, /* No lexical inforamtion */ 0, 0 |
| 2033 | }; |
| 2034 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 2035 | } else |
| 2036 | PendingVisibleUpdates[ID].push_back(Table); |
| 2037 | break; |
| 2038 | } |
| 2039 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2040 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2041 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 2042 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2043 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2044 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 2045 | Latest > FirstLatestDeclIDs[First]) && |
| 2046 | "The new latest is supposed to come after the previous latest"); |
| 2047 | FirstLatestDeclIDs[First] = Latest; |
| 2048 | } |
| 2049 | break; |
| 2050 | } |
| 2051 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2052 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2053 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2054 | return IgnorePCH; |
| 2055 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2056 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2057 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2058 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2059 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2060 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2061 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2062 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2063 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2064 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2065 | if (PP) |
| 2066 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2067 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2068 | break; |
| 2069 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2070 | case IDENTIFIER_OFFSET: |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2071 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2072 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2073 | return Failure; |
| 2074 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2075 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2076 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2077 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2078 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2079 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2080 | // Optimization for the first block. |
| 2081 | if (ExternalDefinitions.empty()) |
| 2082 | ExternalDefinitions.swap(Record); |
| 2083 | else |
| 2084 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 2085 | Record.begin(), Record.end()); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2086 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2087 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2088 | case SPECIAL_TYPES: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2089 | // Optimization for the first block |
| 2090 | if (SpecialTypes.empty()) |
| 2091 | SpecialTypes.swap(Record); |
| 2092 | else |
| 2093 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2094 | break; |
| 2095 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2096 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2097 | TotalNumStatements += Record[0]; |
| 2098 | TotalNumMacros += Record[1]; |
| 2099 | TotalLexicalDeclContexts += Record[2]; |
| 2100 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2101 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2102 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2103 | case TENTATIVE_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2104 | // Optimization for the first block. |
| 2105 | if (TentativeDefinitions.empty()) |
| 2106 | TentativeDefinitions.swap(Record); |
| 2107 | else |
| 2108 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 2109 | Record.begin(), Record.end()); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2110 | break; |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2111 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2112 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2113 | // Optimization for the first block. |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2114 | if (UnusedFileScopedDecls.empty()) |
| 2115 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2116 | else |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2117 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 2118 | Record.begin(), Record.end()); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2119 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2120 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2121 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2122 | // Later blocks overwrite earlier ones. |
| 2123 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2124 | break; |
| 2125 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2126 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2127 | // Optimization for the first block. |
| 2128 | if (LocallyScopedExternalDecls.empty()) |
| 2129 | LocallyScopedExternalDecls.swap(Record); |
| 2130 | else |
| 2131 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 2132 | Record.begin(), Record.end()); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2133 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2134 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2135 | case SELECTOR_OFFSETS: |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2136 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2137 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2138 | break; |
| 2139 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2140 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2141 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2142 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2143 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2144 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2145 | F.SelectorLookupTableData + Record[0], |
| 2146 | F.SelectorLookupTableData, |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2147 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2148 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2149 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2150 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2151 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2152 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2153 | break; |
| 2154 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2155 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2156 | if (!Record.empty() && Listener) |
| 2157 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2158 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2159 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2160 | case SOURCE_LOCATION_OFFSETS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2161 | F.SLocOffsets = (const uint32_t *)BlobStart; |
| 2162 | F.LocalNumSLocEntries = Record[0]; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2163 | F.LocalSLocSize = Record[1]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2164 | break; |
| 2165 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2166 | case SOURCE_LOCATION_PRELOADS: |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2167 | if (PreloadSLocEntries.empty()) |
| 2168 | PreloadSLocEntries.swap(Record); |
| 2169 | else |
| 2170 | PreloadSLocEntries.insert(PreloadSLocEntries.end(), |
| 2171 | Record.begin(), Record.end()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2172 | break; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2173 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2174 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2175 | if (!DisableStatCache) { |
| 2176 | ASTStatCache *MyStatCache = |
| 2177 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2178 | (const unsigned char *)BlobStart, |
| 2179 | NumStatHits, NumStatMisses); |
| 2180 | FileMgr.addStatCache(MyStatCache); |
| 2181 | F.StatCache = MyStatCache; |
| 2182 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2183 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2184 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2185 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2186 | case EXT_VECTOR_DECLS: |
Sebastian Redl | a9f2368 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 2187 | // Optimization for the first block. |
| 2188 | if (ExtVectorDecls.empty()) |
| 2189 | ExtVectorDecls.swap(Record); |
| 2190 | else |
| 2191 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 2192 | Record.begin(), Record.end()); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2193 | break; |
| 2194 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2195 | case VTABLE_USES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2196 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2197 | VTableUses.swap(Record); |
| 2198 | break; |
| 2199 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2200 | case DYNAMIC_CLASSES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2201 | // Optimization for the first block. |
| 2202 | if (DynamicClasses.empty()) |
| 2203 | DynamicClasses.swap(Record); |
| 2204 | else |
| 2205 | DynamicClasses.insert(DynamicClasses.end(), |
| 2206 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2207 | break; |
| 2208 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2209 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2210 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2211 | break; |
| 2212 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2213 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2214 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2215 | SemaDeclRefs.swap(Record); |
| 2216 | break; |
| 2217 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2218 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2219 | // 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] | 2220 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2221 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2222 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2223 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2224 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2225 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2226 | case ORIGINAL_PCH_DIR: |
| 2227 | // The primary AST will be the last to get here, so it will be the one |
| 2228 | // that's used. |
| 2229 | OriginalDir.assign(BlobStart, BlobLen); |
| 2230 | break; |
| 2231 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2232 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2233 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2234 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 2235 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2236 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2237 | return IgnorePCH; |
| 2238 | } |
| 2239 | break; |
| 2240 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2241 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2242 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2243 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2244 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2245 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2246 | break; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2247 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2248 | case DECL_UPDATE_OFFSETS: { |
| 2249 | if (Record.size() % 2 != 0) { |
| 2250 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2251 | return Failure; |
| 2252 | } |
| 2253 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
| 2254 | DeclUpdateOffsets[static_cast<DeclID>(Record[I])] |
| 2255 | .push_back(std::make_pair(&F, Record[I+1])); |
| 2256 | break; |
| 2257 | } |
| 2258 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2259 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2260 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2261 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2262 | return Failure; |
| 2263 | } |
| 2264 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2265 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2266 | std::make_pair(&F, Record[I+1]); |
| 2267 | break; |
| 2268 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2269 | |
| 2270 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2271 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2272 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2273 | return Failure; |
| 2274 | } |
| 2275 | |
| 2276 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2277 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
| 2278 | break; |
| 2279 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2280 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2281 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2282 | if (Record.size() % 2 != 0) { |
| 2283 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2284 | return Failure; |
| 2285 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2286 | if (PragmaDiagMappings.empty()) |
| 2287 | PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2288 | else |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2289 | PragmaDiagMappings.insert(PragmaDiagMappings.end(), |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2290 | Record.begin(), Record.end()); |
| 2291 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2292 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2293 | case CUDA_SPECIAL_DECL_REFS: |
| 2294 | // Later tables overwrite earlier ones. |
| 2295 | CUDASpecialDeclRefs.swap(Record); |
| 2296 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2297 | |
| 2298 | case HEADER_SEARCH_TABLE: |
| 2299 | F.HeaderFileInfoTableData = BlobStart; |
| 2300 | F.LocalNumHeaderFileInfos = Record[1]; |
| 2301 | if (Record[0]) { |
| 2302 | F.HeaderFileInfoTable |
| 2303 | = HeaderFileInfoLookupTable::Create( |
| 2304 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 2305 | (const unsigned char *)F.HeaderFileInfoTableData); |
| 2306 | if (PP) |
| 2307 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2308 | } |
| 2309 | break; |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2310 | |
| 2311 | case FP_PRAGMA_OPTIONS: |
| 2312 | // Later tables overwrite earlier ones. |
| 2313 | FPPragmaOptions.swap(Record); |
| 2314 | break; |
| 2315 | |
| 2316 | case OPENCL_EXTENSIONS: |
| 2317 | // Later tables overwrite earlier ones. |
| 2318 | OpenCLExtensions.swap(Record); |
| 2319 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2320 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2321 | First = false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2322 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2323 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2324 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2327 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2328 | ASTFileType Type) { |
| 2329 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2330 | case Failure: return Failure; |
| 2331 | case IgnorePCH: return IgnorePCH; |
| 2332 | case Success: break; |
| 2333 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2334 | |
| 2335 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2336 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2337 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2338 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2339 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2340 | TotalNumSelectors = 0; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2341 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2342 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2343 | NextSLocOffset += Chain[I]->LocalSLocSize; |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2344 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2345 | TotalNumTypes += Chain[I]->LocalNumTypes; |
| 2346 | TotalNumDecls += Chain[I]->LocalNumDecls; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2347 | TotalNumPreallocatedPreprocessingEntities += |
| 2348 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2349 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2350 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2351 | } |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2352 | SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset); |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2353 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2354 | TypesLoaded.resize(TotalNumTypes); |
| 2355 | DeclsLoaded.resize(TotalNumDecls); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2356 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2357 | if (PP) { |
| 2358 | if (TotalNumIdentifiers > 0) |
| 2359 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2360 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2361 | if (!PP->getPreprocessingRecord()) |
| 2362 | PP->createPreprocessingRecord(); |
| 2363 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2364 | TotalNumPreallocatedPreprocessingEntities); |
| 2365 | } |
| 2366 | } |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2367 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2368 | // Preload SLocEntries. |
| 2369 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2370 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2371 | if (Result != Success) |
| 2372 | return Result; |
| 2373 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2374 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2375 | // Check the predefines buffers. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2376 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2377 | return IgnorePCH; |
| 2378 | |
| 2379 | if (PP) { |
| 2380 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2381 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2382 | // loaded into the IdentifierTable before we intercepted the |
| 2383 | // creation of identifiers. Iterate through the list of known |
| 2384 | // identifiers and determine whether we have to establish |
| 2385 | // preprocessor definitions or top-level identifier declaration |
| 2386 | // chains for those identifiers. |
| 2387 | // |
| 2388 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2389 | // since de-serializing declarations or macro definitions can add |
| 2390 | // new entries into the identifier table, invalidating the |
| 2391 | // iterators. |
| 2392 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2393 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2394 | IdEnd = PP->getIdentifierTable().end(); |
| 2395 | Id != IdEnd; ++Id) |
| 2396 | Identifiers.push_back(Id->second); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2397 | // We need to search the tables in all files. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2398 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2399 | ASTIdentifierLookupTable *IdTable |
| 2400 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2401 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2402 | // ones. |
| 2403 | if (!IdTable) |
| 2404 | continue; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2405 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2406 | IdentifierInfo *II = Identifiers[I]; |
| 2407 | // 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] | 2408 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2409 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2410 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2411 | if (Pos == IdTable->end()) |
| 2412 | continue; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2413 | |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2414 | // Dereferencing the iterator has the effect of populating the |
| 2415 | // IdentifierInfo node with the various declarations it needs. |
| 2416 | (void)*Pos; |
| 2417 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2418 | } |
| 2419 | } |
| 2420 | |
| 2421 | if (Context) |
| 2422 | InitializeContext(*Context); |
| 2423 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2424 | if (DeserializationListener) |
| 2425 | DeserializationListener->ReaderInitialized(this); |
| 2426 | |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2427 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2428 | // the source manager to the file source file from which the preamble was |
| 2429 | // built. This is the only valid way to use a precompiled preamble. |
| 2430 | if (Type == Preamble) { |
| 2431 | SourceLocation Loc |
| 2432 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2433 | if (Loc.isValid()) { |
| 2434 | std::pair<FileID, unsigned> Decomposed = SourceMgr.getDecomposedLoc(Loc); |
| 2435 | SourceMgr.SetPreambleFileID(Decomposed.first); |
| 2436 | } |
| 2437 | } |
| 2438 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2439 | return Success; |
| 2440 | } |
| 2441 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2442 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2443 | ASTFileType Type) { |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2444 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2445 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2446 | PerFileData &F = *Chain.back(); |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2447 | if (Prev) |
| 2448 | Prev->NextInSource = &F; |
| 2449 | else |
| 2450 | FirstInSource = &F; |
| 2451 | F.Loaders.push_back(Prev); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2452 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2453 | // Set the AST file name. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2454 | F.FileName = FileName; |
| 2455 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2456 | if (FileName != "-") { |
| 2457 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2458 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2459 | } |
| 2460 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2461 | // Open the AST file. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2462 | // |
| 2463 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2464 | std::string ErrStr; |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 2465 | llvm::error_code ec; |
| 2466 | if (FileName == "-") { |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 2467 | ec = llvm::MemoryBuffer::getSTDIN(F.Buffer); |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 2468 | if (ec) |
| 2469 | ErrStr = ec.message(); |
| 2470 | } else |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2471 | F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr)); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2472 | if (!F.Buffer) { |
| 2473 | Error(ErrStr.c_str()); |
| 2474 | return IgnorePCH; |
| 2475 | } |
| 2476 | |
| 2477 | // Initialize the stream |
| 2478 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2479 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2480 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2481 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2482 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2483 | |
| 2484 | // Sniff for the signature. |
| 2485 | if (Stream.Read(8) != 'C' || |
| 2486 | Stream.Read(8) != 'P' || |
| 2487 | Stream.Read(8) != 'C' || |
| 2488 | Stream.Read(8) != 'H') { |
| 2489 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2490 | return Failure; |
| 2491 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2492 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2493 | while (!Stream.AtEndOfStream()) { |
| 2494 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2495 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2496 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2497 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2498 | return Failure; |
| 2499 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2500 | |
| 2501 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2502 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2503 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2504 | switch (BlockID) { |
| 2505 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2506 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2507 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2508 | return Failure; |
| 2509 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2510 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2511 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2512 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2513 | case Success: |
| 2514 | break; |
| 2515 | |
| 2516 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2517 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2518 | |
| 2519 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2520 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2521 | // AST block, skipping subblocks, to see if there are other |
| 2522 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2523 | |
| 2524 | // Clear out any preallocated source location entries, so that |
| 2525 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2526 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2527 | |
| 2528 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2529 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2530 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2531 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2532 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2533 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2534 | break; |
| 2535 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2536 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2537 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2538 | return Failure; |
| 2539 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2540 | break; |
| 2541 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2542 | } |
| 2543 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2544 | return Success; |
| 2545 | } |
| 2546 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2547 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2548 | PP = &pp; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2549 | |
| 2550 | unsigned TotalNum = 0; |
| 2551 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2552 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2553 | if (TotalNum) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2554 | if (!PP->getPreprocessingRecord()) |
| 2555 | PP->createPreprocessingRecord(); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2556 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2557 | } |
| 2558 | } |
| 2559 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2560 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2561 | Context = &Ctx; |
| 2562 | assert(Context && "Passed null context!"); |
| 2563 | |
| 2564 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2565 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2566 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2567 | PP->setExternalSource(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2568 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2569 | |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2570 | // If we have an update block for the TU waiting, we have to add it before |
| 2571 | // deserializing the decl. |
| 2572 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2573 | if (DCU != DeclContextOffsets.end()) { |
| 2574 | // Insertion could invalidate map, so grab vector. |
| 2575 | DeclContextInfos T; |
| 2576 | T.swap(DCU->second); |
| 2577 | DeclContextOffsets.erase(DCU); |
| 2578 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2579 | } |
| 2580 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2581 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2582 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2583 | |
| 2584 | // Load the special types. |
| 2585 | Context->setBuiltinVaListType( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2586 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2587 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2588 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2589 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2590 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2591 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2592 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2593 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2594 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2595 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2596 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2597 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2598 | if (unsigned FastEnum |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2599 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2600 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2601 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2602 | QualType FileType = GetType(File); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2603 | if (FileType.isNull()) { |
| 2604 | Error("FILE type is NULL"); |
| 2605 | return; |
| 2606 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2607 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2608 | Context->setFILEDecl(Typedef->getDecl()); |
| 2609 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2610 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2611 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2612 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2613 | return; |
| 2614 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2615 | Context->setFILEDecl(Tag->getDecl()); |
| 2616 | } |
| 2617 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2618 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2619 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2620 | if (Jmp_bufType.isNull()) { |
| 2621 | Error("jmp_bug type is NULL"); |
| 2622 | return; |
| 2623 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2624 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2625 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2626 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2627 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2628 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2629 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2630 | return; |
| 2631 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2632 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2633 | } |
| 2634 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2635 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2636 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2637 | if (Sigjmp_bufType.isNull()) { |
| 2638 | Error("sigjmp_buf type is NULL"); |
| 2639 | return; |
| 2640 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2641 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2642 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2643 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2644 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2645 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2646 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2647 | } |
| 2648 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2649 | if (unsigned ObjCIdRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2650 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2651 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2652 | if (unsigned ObjCClassRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2653 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2654 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2655 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2656 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2657 | if (unsigned String |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2658 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2659 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2660 | if (unsigned ObjCSelRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2661 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2662 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2663 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2664 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2665 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2666 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2667 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2668 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2669 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2670 | |
| 2671 | // If there were any CUDA special declarations, deserialize them. |
| 2672 | if (!CUDASpecialDeclRefs.empty()) { |
| 2673 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 2674 | Context->setcudaConfigureCallDecl( |
| 2675 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2676 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2677 | } |
| 2678 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2679 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2680 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2681 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2682 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2683 | FileManager &FileMgr, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2684 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2685 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2686 | std::string ErrStr; |
| 2687 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2688 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2689 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2690 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2691 | return std::string(); |
| 2692 | } |
| 2693 | |
| 2694 | // Initialize the stream |
| 2695 | llvm::BitstreamReader StreamFile; |
| 2696 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2697 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2698 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2699 | Stream.init(StreamFile); |
| 2700 | |
| 2701 | // Sniff for the signature. |
| 2702 | if (Stream.Read(8) != 'C' || |
| 2703 | Stream.Read(8) != 'P' || |
| 2704 | Stream.Read(8) != 'C' || |
| 2705 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2706 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2707 | return std::string(); |
| 2708 | } |
| 2709 | |
| 2710 | RecordData Record; |
| 2711 | while (!Stream.AtEndOfStream()) { |
| 2712 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2713 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2714 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2715 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2716 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2717 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2718 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2719 | case AST_BLOCK_ID: |
| 2720 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2721 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2722 | return std::string(); |
| 2723 | } |
| 2724 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2725 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2726 | default: |
| 2727 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2728 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2729 | return std::string(); |
| 2730 | } |
| 2731 | break; |
| 2732 | } |
| 2733 | continue; |
| 2734 | } |
| 2735 | |
| 2736 | if (Code == llvm::bitc::END_BLOCK) { |
| 2737 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2738 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2739 | return std::string(); |
| 2740 | } |
| 2741 | continue; |
| 2742 | } |
| 2743 | |
| 2744 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2745 | Stream.ReadAbbrevRecord(); |
| 2746 | continue; |
| 2747 | } |
| 2748 | |
| 2749 | Record.clear(); |
| 2750 | const char *BlobStart = 0; |
| 2751 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2752 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2753 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2754 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2755 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2756 | |
| 2757 | return std::string(); |
| 2758 | } |
| 2759 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2760 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2761 | /// structure. |
| 2762 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2763 | /// This routine parses the language options from the AST file and then gives |
| 2764 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2765 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2766 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2767 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2768 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2769 | if (Listener) { |
| 2770 | LangOptions LangOpts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2771 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2772 | #define PARSE_LANGOPT(Option) \ |
| 2773 | LangOpts.Option = Record[Idx]; \ |
| 2774 | ++Idx |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2775 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2776 | unsigned Idx = 0; |
| 2777 | PARSE_LANGOPT(Trigraphs); |
| 2778 | PARSE_LANGOPT(BCPLComment); |
| 2779 | PARSE_LANGOPT(DollarIdents); |
| 2780 | PARSE_LANGOPT(AsmPreprocessor); |
| 2781 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2782 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2783 | PARSE_LANGOPT(ImplicitInt); |
| 2784 | PARSE_LANGOPT(Digraphs); |
| 2785 | PARSE_LANGOPT(HexFloats); |
| 2786 | PARSE_LANGOPT(C99); |
| 2787 | PARSE_LANGOPT(Microsoft); |
| 2788 | PARSE_LANGOPT(CPlusPlus); |
| 2789 | PARSE_LANGOPT(CPlusPlus0x); |
| 2790 | PARSE_LANGOPT(CXXOperatorNames); |
| 2791 | PARSE_LANGOPT(ObjC1); |
| 2792 | PARSE_LANGOPT(ObjC2); |
| 2793 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 2794 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 2795 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 2796 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 2797 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2798 | PARSE_LANGOPT(PascalStrings); |
| 2799 | PARSE_LANGOPT(WritableStrings); |
| 2800 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2801 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2802 | PARSE_LANGOPT(Exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 2803 | PARSE_LANGOPT(ObjCExceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame^] | 2804 | PARSE_LANGOPT(CXXExceptions); |
| 2805 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 2806 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2807 | PARSE_LANGOPT(NeXTRuntime); |
| 2808 | PARSE_LANGOPT(Freestanding); |
| 2809 | PARSE_LANGOPT(NoBuiltin); |
| 2810 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 2811 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2812 | PARSE_LANGOPT(Blocks); |
| 2813 | PARSE_LANGOPT(EmitAllDecls); |
| 2814 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2815 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 2816 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2817 | PARSE_LANGOPT(HeinousExtensions); |
| 2818 | PARSE_LANGOPT(Optimize); |
| 2819 | PARSE_LANGOPT(OptimizeSize); |
| 2820 | PARSE_LANGOPT(Static); |
| 2821 | PARSE_LANGOPT(PICLevel); |
| 2822 | PARSE_LANGOPT(GNUInline); |
| 2823 | PARSE_LANGOPT(NoInline); |
| 2824 | PARSE_LANGOPT(AccessControl); |
| 2825 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2826 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | b1bdced | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 2827 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2828 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2829 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 2830 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2831 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2832 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2833 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 2834 | PARSE_LANGOPT(CUDA); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2835 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2836 | PARSE_LANGOPT(DefaultFPContract); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2837 | // FIXME: Missing ElideConstructors?! |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2838 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2839 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2840 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2841 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2842 | |
| 2843 | return false; |
| 2844 | } |
| 2845 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2846 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2847 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2848 | PerFileData &F = *Chain[I]; |
| 2849 | if (!F.PreprocessorDetailCursor.getBitStreamReader()) |
| 2850 | continue; |
| 2851 | |
| 2852 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 2853 | F.PreprocessorDetailCursor.JumpToBit(F.PreprocessorDetailStartOffset); |
| 2854 | while (LoadPreprocessedEntity(F)) { } |
| 2855 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2856 | } |
| 2857 | |
Douglas Gregor | 0a48029 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 2858 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2859 | PerFileData *F = 0; |
| 2860 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2861 | if (Offset < Chain[I]->SizeInBits) { |
| 2862 | F = Chain[I]; |
| 2863 | break; |
| 2864 | } |
| 2865 | |
| 2866 | Offset -= Chain[I]->SizeInBits; |
| 2867 | } |
| 2868 | |
| 2869 | if (!F) { |
| 2870 | Error("Malformed preprocessed entity offset"); |
| 2871 | return 0; |
| 2872 | } |
| 2873 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2874 | // Keep track of where we are in the stream, then jump back there |
| 2875 | // after reading this entity. |
| 2876 | SavedStreamPosition SavedPosition(F->PreprocessorDetailCursor); |
| 2877 | F->PreprocessorDetailCursor.JumpToBit(Offset); |
| 2878 | return LoadPreprocessedEntity(*F); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2879 | } |
| 2880 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2881 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
| 2882 | HeaderFileInfoTrait Trait(FE->getName()); |
| 2883 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2884 | PerFileData &F = *Chain[I]; |
| 2885 | HeaderFileInfoLookupTable *Table |
| 2886 | = static_cast<HeaderFileInfoLookupTable *>(F.HeaderFileInfoTable); |
| 2887 | if (!Table) |
| 2888 | continue; |
| 2889 | |
| 2890 | // Look in the on-disk hash table for an entry for this file name. |
| 2891 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE->getName(), |
| 2892 | &Trait); |
| 2893 | if (Pos == Table->end()) |
| 2894 | continue; |
| 2895 | |
| 2896 | HeaderFileInfo HFI = *Pos; |
| 2897 | if (Listener) |
| 2898 | Listener->ReadHeaderFileInfo(HFI, FE->getUID()); |
| 2899 | |
| 2900 | return HFI; |
| 2901 | } |
| 2902 | |
| 2903 | return HeaderFileInfo(); |
| 2904 | } |
| 2905 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2906 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2907 | unsigned Idx = 0; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2908 | while (Idx < PragmaDiagMappings.size()) { |
| 2909 | SourceLocation |
| 2910 | Loc = SourceLocation::getFromRawEncoding(PragmaDiagMappings[Idx++]); |
| 2911 | while (1) { |
| 2912 | assert(Idx < PragmaDiagMappings.size() && |
| 2913 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 2914 | if (Idx >= PragmaDiagMappings.size()) |
| 2915 | break; // Something is messed up but at least avoid infinite loop in |
| 2916 | // release build. |
| 2917 | unsigned DiagID = PragmaDiagMappings[Idx++]; |
| 2918 | if (DiagID == (unsigned)-1) |
| 2919 | break; // no more diag/map pairs for this location. |
| 2920 | diag::Mapping Map = (diag::Mapping)PragmaDiagMappings[Idx++]; |
| 2921 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 2922 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2923 | } |
| 2924 | } |
| 2925 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2926 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2927 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2928 | PerFileData *F = 0; |
| 2929 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2930 | F = Chain[N - I - 1]; |
| 2931 | if (Index < F->LocalNumTypes) |
| 2932 | break; |
| 2933 | Index -= F->LocalNumTypes; |
| 2934 | } |
| 2935 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2936 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2937 | } |
| 2938 | |
| 2939 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2940 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2941 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 2942 | /// routine actually reads the record corresponding to the type at the given |
| 2943 | /// location. It is a helper routine for GetType, which deals with reading type |
| 2944 | /// IDs. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2945 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2946 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2947 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2948 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2949 | // Keep track of where we are in the stream, then jump back there |
| 2950 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2951 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2952 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 2953 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 2954 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2955 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 2956 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2957 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2958 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2959 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2960 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2961 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 2962 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2963 | if (Record.size() != 2) { |
| 2964 | Error("Incorrect encoding of extended qualifier type"); |
| 2965 | return QualType(); |
| 2966 | } |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2967 | QualType Base = GetType(Record[0]); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2968 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 2969 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2970 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2971 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2972 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2973 | if (Record.size() != 1) { |
| 2974 | Error("Incorrect encoding of complex type"); |
| 2975 | return QualType(); |
| 2976 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2977 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2978 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2979 | } |
| 2980 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2981 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2982 | if (Record.size() != 1) { |
| 2983 | Error("Incorrect encoding of pointer type"); |
| 2984 | return QualType(); |
| 2985 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2986 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2987 | return Context->getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2988 | } |
| 2989 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2990 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2991 | if (Record.size() != 1) { |
| 2992 | Error("Incorrect encoding of block pointer type"); |
| 2993 | return QualType(); |
| 2994 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2995 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2996 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2997 | } |
| 2998 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2999 | case TYPE_LVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3000 | if (Record.size() != 1) { |
| 3001 | Error("Incorrect encoding of lvalue reference type"); |
| 3002 | return QualType(); |
| 3003 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3004 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3005 | return Context->getLValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3006 | } |
| 3007 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3008 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3009 | if (Record.size() != 1) { |
| 3010 | Error("Incorrect encoding of rvalue reference type"); |
| 3011 | return QualType(); |
| 3012 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3013 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3014 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3015 | } |
| 3016 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3017 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3018 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3019 | Error("Incorrect encoding of member pointer type"); |
| 3020 | return QualType(); |
| 3021 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3022 | QualType PointeeType = GetType(Record[0]); |
| 3023 | QualType ClassType = GetType(Record[1]); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3024 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3025 | return QualType(); |
| 3026 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3027 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3028 | } |
| 3029 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3030 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3031 | QualType ElementType = GetType(Record[0]); |
| 3032 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3033 | unsigned IndexTypeQuals = Record[2]; |
| 3034 | unsigned Idx = 3; |
| 3035 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3036 | return Context->getConstantArrayType(ElementType, Size, |
| 3037 | ASM, IndexTypeQuals); |
| 3038 | } |
| 3039 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3040 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3041 | QualType ElementType = GetType(Record[0]); |
| 3042 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3043 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3044 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3045 | } |
| 3046 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3047 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3048 | QualType ElementType = GetType(Record[0]); |
| 3049 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3050 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3051 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3052 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 3053 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3054 | ASM, IndexTypeQuals, |
| 3055 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3058 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3059 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3060 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3061 | return QualType(); |
| 3062 | } |
| 3063 | |
| 3064 | QualType ElementType = GetType(Record[0]); |
| 3065 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3066 | unsigned VecKind = Record[2]; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3067 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3068 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3069 | } |
| 3070 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3071 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3072 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3073 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3074 | return QualType(); |
| 3075 | } |
| 3076 | |
| 3077 | QualType ElementType = GetType(Record[0]); |
| 3078 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3079 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3080 | } |
| 3081 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3082 | case TYPE_FUNCTION_NO_PROTO: { |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3083 | if (Record.size() != 4) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3084 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3085 | return QualType(); |
| 3086 | } |
| 3087 | QualType ResultType = GetType(Record[0]); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3088 | FunctionType::ExtInfo Info(Record[1], Record[2], (CallingConv)Record[3]); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 3089 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3090 | } |
| 3091 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3092 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3093 | QualType ResultType = GetType(Record[0]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3094 | |
| 3095 | FunctionProtoType::ExtProtoInfo EPI; |
| 3096 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
| 3097 | /*regparm*/ Record[2], |
| 3098 | static_cast<CallingConv>(Record[3])); |
| 3099 | |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3100 | unsigned Idx = 4; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3101 | unsigned NumParams = Record[Idx++]; |
| 3102 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 3103 | for (unsigned I = 0; I != NumParams; ++I) |
| 3104 | ParamTypes.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3105 | |
| 3106 | EPI.Variadic = Record[Idx++]; |
| 3107 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3108 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3109 | EPI.HasExceptionSpec = Record[Idx++]; |
| 3110 | EPI.HasAnyExceptionSpec = Record[Idx++]; |
| 3111 | EPI.NumExceptions = Record[Idx++]; |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 3112 | llvm::SmallVector<QualType, 2> Exceptions; |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3113 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 3114 | Exceptions.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3115 | EPI.Exceptions = Exceptions.data(); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 3116 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3117 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3118 | } |
| 3119 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3120 | case TYPE_UNRESOLVED_USING: |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3121 | return Context->getTypeDeclType( |
| 3122 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 3123 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3124 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3125 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3126 | Error("incorrect encoding of typedef type"); |
| 3127 | return QualType(); |
| 3128 | } |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3129 | TypedefDecl *Decl = cast<TypedefDecl>(GetDecl(Record[0])); |
| 3130 | QualType Canonical = GetType(Record[1]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3131 | if (!Canonical.isNull()) |
| 3132 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3133 | return Context->getTypedefType(Decl, Canonical); |
| 3134 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3135 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3136 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3137 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3138 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3139 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3140 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3141 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3142 | return QualType(); |
| 3143 | } |
| 3144 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3145 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3146 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3147 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3148 | case TYPE_DECLTYPE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3149 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3150 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3151 | case TYPE_AUTO: |
| 3152 | return Context->getAutoType(GetType(Record[0])); |
| 3153 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3154 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3155 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3156 | Error("incorrect encoding of record type"); |
| 3157 | return QualType(); |
| 3158 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3159 | bool IsDependent = Record[0]; |
| 3160 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3161 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3162 | return T; |
| 3163 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3164 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3165 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3166 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3167 | Error("incorrect encoding of enum type"); |
| 3168 | return QualType(); |
| 3169 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3170 | bool IsDependent = Record[0]; |
| 3171 | QualType T = Context->getEnumType(cast<EnumDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3172 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3173 | return T; |
| 3174 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3175 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3176 | case TYPE_ATTRIBUTED: { |
| 3177 | if (Record.size() != 3) { |
| 3178 | Error("incorrect encoding of attributed type"); |
| 3179 | return QualType(); |
| 3180 | } |
| 3181 | QualType modifiedType = GetType(Record[0]); |
| 3182 | QualType equivalentType = GetType(Record[1]); |
| 3183 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 3184 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 3185 | } |
| 3186 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3187 | case TYPE_PAREN: { |
| 3188 | if (Record.size() != 1) { |
| 3189 | Error("incorrect encoding of paren type"); |
| 3190 | return QualType(); |
| 3191 | } |
| 3192 | QualType InnerType = GetType(Record[0]); |
| 3193 | return Context->getParenType(InnerType); |
| 3194 | } |
| 3195 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3196 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3197 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3198 | Error("incorrect encoding of pack expansion type"); |
| 3199 | return QualType(); |
| 3200 | } |
| 3201 | QualType Pattern = GetType(Record[0]); |
| 3202 | if (Pattern.isNull()) |
| 3203 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3204 | llvm::Optional<unsigned> NumExpansions; |
| 3205 | if (Record[1]) |
| 3206 | NumExpansions = Record[1] - 1; |
| 3207 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3208 | } |
| 3209 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3210 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3211 | unsigned Idx = 0; |
| 3212 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3213 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3214 | QualType NamedType = GetType(Record[Idx++]); |
| 3215 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3216 | } |
| 3217 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3218 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3219 | unsigned Idx = 0; |
| 3220 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3221 | return Context->getObjCInterfaceType(ItfD); |
| 3222 | } |
| 3223 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3224 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3225 | unsigned Idx = 0; |
| 3226 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3227 | unsigned NumProtos = Record[Idx++]; |
| 3228 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 3229 | for (unsigned I = 0; I != NumProtos; ++I) |
| 3230 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3231 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3232 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3233 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3234 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3235 | unsigned Idx = 0; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3236 | QualType Pointee = GetType(Record[Idx++]); |
| 3237 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3238 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3239 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3240 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3241 | unsigned Idx = 0; |
| 3242 | QualType Parm = GetType(Record[Idx++]); |
| 3243 | QualType Replacement = GetType(Record[Idx++]); |
| 3244 | return |
| 3245 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3246 | Replacement); |
| 3247 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3248 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3249 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3250 | unsigned Idx = 0; |
| 3251 | QualType Parm = GetType(Record[Idx++]); |
| 3252 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3253 | return Context->getSubstTemplateTypeParmPackType( |
| 3254 | cast<TemplateTypeParmType>(Parm), |
| 3255 | ArgPack); |
| 3256 | } |
| 3257 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3258 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3259 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 3260 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3261 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3262 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3263 | return |
| 3264 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3265 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3266 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3267 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3268 | unsigned Idx = 0; |
| 3269 | unsigned Depth = Record[Idx++]; |
| 3270 | unsigned Index = Record[Idx++]; |
| 3271 | bool Pack = Record[Idx++]; |
| 3272 | IdentifierInfo *Name = GetIdentifierInfo(Record, Idx); |
| 3273 | return Context->getTemplateTypeParmType(Depth, Index, Pack, Name); |
| 3274 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3275 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3276 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3277 | unsigned Idx = 0; |
| 3278 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3279 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3280 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3281 | QualType Canon = GetType(Record[Idx++]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3282 | if (!Canon.isNull()) |
| 3283 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3284 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3285 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3286 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3287 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3288 | unsigned Idx = 0; |
| 3289 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3290 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3291 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
| 3292 | unsigned NumArgs = Record[Idx++]; |
| 3293 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 3294 | Args.reserve(NumArgs); |
| 3295 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3296 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3297 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3298 | Args.size(), Args.data()); |
| 3299 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3300 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3301 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3302 | unsigned Idx = 0; |
| 3303 | |
| 3304 | // ArrayType |
| 3305 | QualType ElementType = GetType(Record[Idx++]); |
| 3306 | ArrayType::ArraySizeModifier ASM |
| 3307 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3308 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3309 | |
| 3310 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3311 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3312 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3313 | |
| 3314 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3315 | IndexTypeQuals, Brackets); |
| 3316 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3317 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3318 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3319 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3320 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3321 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3322 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3323 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3324 | QualType Canon = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3325 | QualType T; |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3326 | if (Canon.isNull()) |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3327 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3328 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3329 | else |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3330 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
| 3331 | Args.size(), Canon); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3332 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3333 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3334 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3335 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3336 | // Suppress a GCC warning |
| 3337 | return QualType(); |
| 3338 | } |
| 3339 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3340 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3341 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3342 | ASTReader::PerFileData &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3343 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3344 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3345 | unsigned &Idx; |
| 3346 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3347 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3348 | unsigned &I) { |
| 3349 | return Reader.ReadSourceLocation(F, R, I); |
| 3350 | } |
| 3351 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3352 | public: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3353 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3354 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3355 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3356 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3357 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3358 | // We want compile-time assurance that we've enumerated all of |
| 3359 | // these, so unfortunately we have to declare them first, then |
| 3360 | // define them out-of-line. |
| 3361 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3362 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3363 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3364 | #include "clang/AST/TypeLocNodes.def" |
| 3365 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3366 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3367 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3368 | }; |
| 3369 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3370 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3371 | // nothing to do |
| 3372 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3373 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3374 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3375 | if (TL.needsExtraLocalData()) { |
| 3376 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3377 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3378 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3379 | TL.setModeAttr(Record[Idx++]); |
| 3380 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3381 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3382 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3383 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3384 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3385 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3386 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3387 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3388 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3389 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3390 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3391 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3392 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3393 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3394 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3395 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3396 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3397 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3398 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3399 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3400 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3401 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3402 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3403 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3404 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3405 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3406 | TL.setSizeExpr(0); |
| 3407 | } |
| 3408 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3409 | VisitArrayTypeLoc(TL); |
| 3410 | } |
| 3411 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3412 | VisitArrayTypeLoc(TL); |
| 3413 | } |
| 3414 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3415 | VisitArrayTypeLoc(TL); |
| 3416 | } |
| 3417 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3418 | DependentSizedArrayTypeLoc TL) { |
| 3419 | VisitArrayTypeLoc(TL); |
| 3420 | } |
| 3421 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3422 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3423 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3424 | } |
| 3425 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3426 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3427 | } |
| 3428 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3429 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3430 | } |
| 3431 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3432 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3433 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3434 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3435 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | 86acc2a | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 3436 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3437 | } |
| 3438 | } |
| 3439 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3440 | VisitFunctionTypeLoc(TL); |
| 3441 | } |
| 3442 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3443 | VisitFunctionTypeLoc(TL); |
| 3444 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3445 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3446 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3447 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3448 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3449 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3450 | } |
| 3451 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3452 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3453 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3454 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3455 | } |
| 3456 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3457 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3458 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3459 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3460 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3461 | } |
| 3462 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3463 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3464 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3465 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3466 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3467 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3468 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3469 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3470 | } |
| 3471 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3472 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3473 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3474 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3475 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3476 | if (TL.hasAttrOperand()) { |
| 3477 | SourceRange range; |
| 3478 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3479 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3480 | TL.setAttrOperandParensRange(range); |
| 3481 | } |
| 3482 | if (TL.hasAttrExprOperand()) { |
| 3483 | if (Record[Idx++]) |
| 3484 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3485 | else |
| 3486 | TL.setAttrExprOperand(0); |
| 3487 | } else if (TL.hasAttrEnumOperand()) |
| 3488 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3489 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3490 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3491 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3492 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3493 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3494 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3495 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3496 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3497 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3498 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3499 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3500 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3501 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3502 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3503 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3504 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3505 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3506 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3507 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3508 | Reader.GetTemplateArgumentLocInfo(F, |
| 3509 | TL.getTypePtr()->getArg(i).getKind(), |
| 3510 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3511 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3512 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3513 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3514 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3515 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3516 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3517 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3518 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3519 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3520 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3521 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3522 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3523 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3524 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3525 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3526 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3527 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3528 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3529 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3530 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3531 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3532 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3533 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3534 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3535 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3536 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3537 | Reader.GetTemplateArgumentLocInfo(F, |
| 3538 | TL.getTypePtr()->getArg(I).getKind(), |
| 3539 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3540 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3541 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3542 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3543 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3544 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3545 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3546 | } |
| 3547 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3548 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3549 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3550 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3551 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3552 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3553 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3554 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3555 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3556 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3557 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3558 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3559 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3560 | unsigned &Idx) { |
| 3561 | QualType InfoTy = GetType(Record[Idx++]); |
| 3562 | if (InfoTy.isNull()) |
| 3563 | return 0; |
| 3564 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3565 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3566 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3567 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3568 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3569 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3570 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3571 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3572 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3573 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3574 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3575 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3576 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3577 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3578 | switch ((PredefinedTypeIDs)Index) { |
| 3579 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3580 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3581 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3582 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3583 | case PREDEF_TYPE_CHAR_U_ID: |
| 3584 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3585 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3586 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3587 | break; |
| 3588 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3589 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3590 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3591 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3592 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3593 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3594 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3595 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3596 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3597 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3598 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3599 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3600 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3601 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3602 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3603 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3604 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3605 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
| 3606 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
| 3607 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3608 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3609 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3610 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3611 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3612 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3613 | } |
| 3614 | |
| 3615 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3616 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3617 | } |
| 3618 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3619 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3620 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3621 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3622 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3623 | if (TypesLoaded[Index].isNull()) |
| 3624 | return QualType(); |
| 3625 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3626 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3627 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3628 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3629 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3630 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3631 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3632 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3633 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3634 | } |
| 3635 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3636 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3637 | return MakeTypeID(T, |
| 3638 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3639 | } |
| 3640 | |
| 3641 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3642 | if (T.isNull()) |
| 3643 | return TypeIdx(); |
| 3644 | assert(!T.getLocalFastQualifiers()); |
| 3645 | |
| 3646 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3647 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3648 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3649 | // If the type didn't come from the AST file use a specially marked index |
| 3650 | // so that any hash/key comparison fail since no such index is stored |
| 3651 | // in a AST file. |
| 3652 | if (I == TypeIdxs.end()) |
| 3653 | return TypeIdx(-1); |
| 3654 | return I->second; |
| 3655 | } |
| 3656 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3657 | unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const { |
| 3658 | unsigned Result = 0; |
| 3659 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 3660 | Result += Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3661 | |
| 3662 | return Result; |
| 3663 | } |
| 3664 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3665 | TemplateArgumentLocInfo |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3666 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3667 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3668 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3669 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3670 | switch (Kind) { |
| 3671 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3672 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3673 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3674 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3675 | case TemplateArgument::Template: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3676 | SourceRange QualifierRange = ReadSourceRange(F, Record, Index); |
| 3677 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3678 | return TemplateArgumentLocInfo(QualifierRange, TemplateNameLoc, |
| 3679 | SourceLocation()); |
| 3680 | } |
| 3681 | case TemplateArgument::TemplateExpansion: { |
| 3682 | SourceRange QualifierRange = ReadSourceRange(F, Record, Index); |
| 3683 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3684 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
| 3685 | return TemplateArgumentLocInfo(QualifierRange, TemplateNameLoc, |
| 3686 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3687 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3688 | case TemplateArgument::Null: |
| 3689 | case TemplateArgument::Integral: |
| 3690 | case TemplateArgument::Declaration: |
| 3691 | case TemplateArgument::Pack: |
| 3692 | return TemplateArgumentLocInfo(); |
| 3693 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3694 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3695 | return TemplateArgumentLocInfo(); |
| 3696 | } |
| 3697 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3698 | TemplateArgumentLoc |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3699 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3700 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3701 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3702 | |
| 3703 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3704 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3705 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3706 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3707 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3708 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3709 | } |
| 3710 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3711 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3712 | return GetDecl(ID); |
| 3713 | } |
| 3714 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3715 | uint64_t |
| 3716 | ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) { |
| 3717 | if (ID == 0) |
| 3718 | return 0; |
| 3719 | |
| 3720 | --ID; |
| 3721 | uint64_t Offset = 0; |
| 3722 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3723 | if (ID < Chain[I]->LocalNumCXXBaseSpecifiers) |
| 3724 | return Offset + Chain[I]->CXXBaseSpecifiersOffsets[ID]; |
| 3725 | |
| 3726 | ID -= Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3727 | Offset += Chain[I]->SizeInBits; |
| 3728 | } |
| 3729 | |
| 3730 | assert(false && "CXXBaseSpecifiers not found"); |
| 3731 | return 0; |
| 3732 | } |
| 3733 | |
| 3734 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 3735 | // Figure out which AST file contains this offset. |
| 3736 | PerFileData *F = 0; |
| 3737 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3738 | if (Offset < Chain[I]->SizeInBits) { |
| 3739 | F = Chain[I]; |
| 3740 | break; |
| 3741 | } |
| 3742 | |
| 3743 | Offset -= Chain[I]->SizeInBits; |
| 3744 | } |
| 3745 | |
| 3746 | if (!F) { |
| 3747 | Error("Malformed AST file: C++ base specifiers at impossible offset"); |
| 3748 | return 0; |
| 3749 | } |
| 3750 | |
| 3751 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3752 | SavedStreamPosition SavedPosition(Cursor); |
| 3753 | Cursor.JumpToBit(Offset); |
| 3754 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3755 | RecordData Record; |
| 3756 | unsigned Code = Cursor.ReadCode(); |
| 3757 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 3758 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 3759 | Error("Malformed AST file: missing C++ base specifiers"); |
| 3760 | return 0; |
| 3761 | } |
| 3762 | |
| 3763 | unsigned Idx = 0; |
| 3764 | unsigned NumBases = Record[Idx++]; |
| 3765 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 3766 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 3767 | for (unsigned I = 0; I != NumBases; ++I) |
| 3768 | Bases[I] = ReadCXXBaseSpecifier(*F, Record, Idx); |
| 3769 | return Bases; |
| 3770 | } |
| 3771 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3772 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3773 | if (!DeclsLoaded[0]) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 3774 | ReadDeclRecord(0, 1); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3775 | if (DeserializationListener) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3776 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3777 | } |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 3778 | |
| 3779 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 3780 | } |
| 3781 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3782 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3783 | if (ID == 0) |
| 3784 | return 0; |
| 3785 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3786 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3787 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3788 | return 0; |
| 3789 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3790 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3791 | unsigned Index = ID - 1; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3792 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3793 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3794 | if (DeserializationListener) |
| 3795 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3796 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3797 | |
| 3798 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3799 | } |
| 3800 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3801 | /// \brief Resolve the offset of a statement into a statement. |
| 3802 | /// |
| 3803 | /// This operation will read a new statement from the external |
| 3804 | /// source each time it is called, and is meant to be used via a |
| 3805 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3806 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 3807 | // Switch case IDs are per Decl. |
| 3808 | ClearSwitchCaseIDs(); |
| 3809 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3810 | // Offset here is a global offset across the entire chain. |
| 3811 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3812 | PerFileData &F = *Chain[N - I - 1]; |
| 3813 | if (Offset < F.SizeInBits) { |
| 3814 | // Since we know that this statement is part of a decl, make sure to use |
| 3815 | // the decl cursor to read it. |
| 3816 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3817 | return ReadStmtFromStream(F); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3818 | } |
| 3819 | Offset -= F.SizeInBits; |
| 3820 | } |
| 3821 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 3822 | } |
| 3823 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3824 | bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3825 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3826 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3827 | assert(DC->hasExternalLexicalStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3828 | "DeclContext has no lexical decls in storage"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3829 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3830 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 3831 | // at least. |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3832 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 3833 | // so make a copy of the vector. |
| 3834 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3835 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3836 | I != E; ++I) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3837 | // IDs can be 0 if this context doesn't contain declarations. |
| 3838 | if (!I->LexicalDecls) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3839 | continue; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3840 | |
| 3841 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3842 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 3843 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 3844 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 3845 | continue; |
| 3846 | |
| 3847 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3848 | assert(D && "Null decl in lexical decls"); |
| 3849 | Decls.push_back(D); |
| 3850 | } |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3851 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3852 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3853 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3854 | return false; |
| 3855 | } |
| 3856 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3857 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3858 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3859 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3860 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3861 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3862 | if (!Name) |
| 3863 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 3864 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3865 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3866 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 8b12273 | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 3867 | // 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] | 3868 | // and namespaces. For any given name, the last available results replace |
| 3869 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3870 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3871 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3872 | I != E; ++I) { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3873 | if (!I->NameLookupTableData) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3874 | continue; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3875 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3876 | ASTDeclContextNameLookupTable *LookupTable = |
| 3877 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3878 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 3879 | if (Pos == LookupTable->end()) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3880 | continue; |
| 3881 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3882 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 3883 | for (; Data.first != Data.second; ++Data.first) |
| 3884 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3885 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3886 | } |
| 3887 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3888 | ++NumVisibleDeclContextsRead; |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3889 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3890 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3891 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3892 | } |
| 3893 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 3894 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 3895 | assert(DC->hasExternalVisibleStorage() && |
| 3896 | "DeclContext has no visible decls in storage"); |
| 3897 | |
| 3898 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 3899 | // There might be visible decls in multiple parts of the chain, for the TU |
| 3900 | // and namespaces. |
| 3901 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 3902 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3903 | I != E; ++I) { |
| 3904 | if (!I->NameLookupTableData) |
| 3905 | continue; |
| 3906 | |
| 3907 | ASTDeclContextNameLookupTable *LookupTable = |
| 3908 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3909 | for (ASTDeclContextNameLookupTable::item_iterator |
| 3910 | ItemI = LookupTable->item_begin(), |
| 3911 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 3912 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 3913 | = *ItemI; |
| 3914 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 3915 | Decls.clear(); |
| 3916 | for (; Data.first != Data.second; ++Data.first) |
| 3917 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 3918 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 3919 | } |
| 3920 | } |
| 3921 | } |
| 3922 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3923 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3924 | assert(Consumer); |
| 3925 | while (!InterestingDecls.empty()) { |
| 3926 | DeclGroupRef DG(InterestingDecls.front()); |
| 3927 | InterestingDecls.pop_front(); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3928 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3929 | } |
| 3930 | } |
| 3931 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3932 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 3933 | this->Consumer = Consumer; |
| 3934 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3935 | if (!Consumer) |
| 3936 | return; |
| 3937 | |
| 3938 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3939 | // Force deserialization of this decl, which will cause it to be queued for |
| 3940 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 3941 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3942 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 3943 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3944 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3945 | } |
| 3946 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3947 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3948 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3949 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3950 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3951 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3952 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3953 | unsigned NumDeclsLoaded |
| 3954 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 3955 | (Decl *)0); |
| 3956 | unsigned NumIdentifiersLoaded |
| 3957 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 3958 | IdentifiersLoaded.end(), |
| 3959 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3960 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3961 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 3962 | SelectorsLoaded.end(), |
| 3963 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 3964 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3965 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 3966 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 3967 | if (TotalNumSLocEntries) |
| 3968 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 3969 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 3970 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3971 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3972 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3973 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 3974 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 3975 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3976 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3977 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 3978 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3979 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3980 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3981 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 3982 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3983 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3984 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3985 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 3986 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3987 | if (TotalNumStatements) |
| 3988 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 3989 | NumStatementsRead, TotalNumStatements, |
| 3990 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 3991 | if (TotalNumMacros) |
| 3992 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 3993 | NumMacrosRead, TotalNumMacros, |
| 3994 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 3995 | if (TotalLexicalDeclContexts) |
| 3996 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 3997 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 3998 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 3999 | * 100)); |
| 4000 | if (TotalVisibleDeclContexts) |
| 4001 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4002 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4003 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4004 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4005 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4006 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4007 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4008 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4009 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4010 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4011 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4012 | std::fprintf(stderr, "\n"); |
| 4013 | } |
| 4014 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4015 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4016 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4017 | S.ExternalSource = this; |
| 4018 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4019 | // Makes sure any declarations that were deserialized "too early" |
| 4020 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4021 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4022 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4023 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4024 | |
| 4025 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4026 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4027 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4028 | |
| 4029 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4030 | // them to Sema's list of tentative definitions. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4031 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4032 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4033 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4034 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 4035 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4036 | // If there were any unused file scoped decls, deserialize them and add to |
| 4037 | // Sema's list of unused file scoped decls. |
| 4038 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4039 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4040 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 4041 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4042 | |
| 4043 | // If there were any locally-scoped external declarations, |
| 4044 | // deserialize them and add them to Sema's table of locally-scoped |
| 4045 | // external declarations. |
| 4046 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4047 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4048 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 4049 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4050 | |
| 4051 | // If there were any ext_vector type declarations, deserialize them |
| 4052 | // and add them to Sema's vector of such declarations. |
| 4053 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 4054 | SemaObj->ExtVectorDecls.push_back( |
| 4055 | cast<TypedefDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4056 | |
| 4057 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 4058 | // Can we cut them down before writing them ? |
| 4059 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4060 | // If there were any dynamic classes declarations, deserialize them |
| 4061 | // and add them to Sema's vector of such declarations. |
| 4062 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 4063 | SemaObj->DynamicClasses.push_back( |
| 4064 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4065 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4066 | // Load the offsets of the declarations that Sema references. |
| 4067 | // They will be lazily deserialized when needed. |
| 4068 | if (!SemaDeclRefs.empty()) { |
| 4069 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 4070 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4071 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 4072 | } |
| 4073 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4074 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 4075 | |
| 4076 | // If there are @selector references added them to its pool. This is for |
| 4077 | // implementation of -Wselector. |
| 4078 | if (!F->ReferencedSelectorsData.empty()) { |
| 4079 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 4080 | unsigned I = 0; |
| 4081 | while (I < DataSize) { |
| 4082 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 4083 | SourceLocation SelLoc = ReadSourceLocation( |
| 4084 | *F, F->ReferencedSelectorsData, I); |
| 4085 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 4086 | } |
| 4087 | } |
| 4088 | |
| 4089 | // If there were any pending implicit instantiations, deserialize them |
| 4090 | // and add them to Sema's queue of such instantiations. |
| 4091 | assert(F->PendingInstantiations.size() % 2 == 0 && |
| 4092 | "Expected pairs of entries"); |
| 4093 | for (unsigned Idx = 0, N = F->PendingInstantiations.size(); Idx < N;) { |
| 4094 | ValueDecl *D=cast<ValueDecl>(GetDecl(F->PendingInstantiations[Idx++])); |
| 4095 | SourceLocation Loc = ReadSourceLocation(*F, F->PendingInstantiations,Idx); |
| 4096 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 4097 | } |
| 4098 | } |
| 4099 | |
| 4100 | // The two special data sets below always come from the most recent PCH, |
| 4101 | // which is at the front of the chain. |
| 4102 | PerFileData &F = *Chain.front(); |
| 4103 | |
| 4104 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 4105 | // Sema's list of weak undeclared identifiers. |
| 4106 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 4107 | unsigned Idx = 0; |
| 4108 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 4109 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4110 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4111 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 4112 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 4113 | Sema::WeakInfo WI(AliasId, Loc); |
| 4114 | WI.setUsed(Used); |
| 4115 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 4116 | } |
| 4117 | } |
| 4118 | |
| 4119 | // If there were any VTable uses, deserialize the information and add it |
| 4120 | // to Sema's vector and map of VTable uses. |
| 4121 | if (!VTableUses.empty()) { |
| 4122 | unsigned Idx = 0; |
| 4123 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 4124 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4125 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 4126 | bool DefinitionRequired = VTableUses[Idx++]; |
| 4127 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 4128 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4129 | } |
| 4130 | } |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4131 | |
| 4132 | if (!FPPragmaOptions.empty()) { |
| 4133 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4134 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4135 | } |
| 4136 | |
| 4137 | if (!OpenCLExtensions.empty()) { |
| 4138 | unsigned I = 0; |
| 4139 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4140 | #include "clang/Basic/OpenCLExtensions.def" |
| 4141 | |
| 4142 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4143 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4144 | } |
| 4145 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4146 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4147 | // Try to find this name within our on-disk hash tables. We start with the |
| 4148 | // 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] | 4149 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4150 | ASTIdentifierLookupTable *IdTable |
| 4151 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4152 | if (!IdTable) |
| 4153 | continue; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4154 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4155 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4156 | if (Pos == IdTable->end()) |
| 4157 | continue; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4158 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4159 | // Dereferencing the iterator has the effect of building the |
| 4160 | // IdentifierInfo node and populating it with the various |
| 4161 | // declarations it needs. |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4162 | return *Pos; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4163 | } |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4164 | return 0; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4165 | } |
| 4166 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4167 | namespace clang { |
| 4168 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4169 | /// identifiers stored within a set of AST files. |
| 4170 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4171 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4172 | const ASTReader &Reader; |
| 4173 | |
| 4174 | /// \brief The current index into the chain of AST files stored in |
| 4175 | /// the AST reader. |
| 4176 | unsigned Index; |
| 4177 | |
| 4178 | /// \brief The current position within the identifier lookup table |
| 4179 | /// of the current AST file. |
| 4180 | ASTIdentifierLookupTable::key_iterator Current; |
| 4181 | |
| 4182 | /// \brief The end position within the identifier lookup table of |
| 4183 | /// the current AST file. |
| 4184 | ASTIdentifierLookupTable::key_iterator End; |
| 4185 | |
| 4186 | public: |
| 4187 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4188 | |
| 4189 | virtual llvm::StringRef Next(); |
| 4190 | }; |
| 4191 | } |
| 4192 | |
| 4193 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 4194 | : Reader(Reader), Index(Reader.Chain.size() - 1) { |
| 4195 | ASTIdentifierLookupTable *IdTable |
| 4196 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4197 | Current = IdTable->key_begin(); |
| 4198 | End = IdTable->key_end(); |
| 4199 | } |
| 4200 | |
| 4201 | llvm::StringRef ASTIdentifierIterator::Next() { |
| 4202 | while (Current == End) { |
| 4203 | // If we have exhausted all of our AST files, we're done. |
| 4204 | if (Index == 0) |
| 4205 | return llvm::StringRef(); |
| 4206 | |
| 4207 | --Index; |
| 4208 | ASTIdentifierLookupTable *IdTable |
| 4209 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4210 | Current = IdTable->key_begin(); |
| 4211 | End = IdTable->key_end(); |
| 4212 | } |
| 4213 | |
| 4214 | // We have any identifiers remaining in the current AST file; return |
| 4215 | // the next one. |
| 4216 | std::pair<const char*, unsigned> Key = *Current; |
| 4217 | ++Current; |
| 4218 | return llvm::StringRef(Key.first, Key.second); |
| 4219 | } |
| 4220 | |
| 4221 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4222 | return new ASTIdentifierIterator(*this); |
| 4223 | } |
| 4224 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4225 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4226 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4227 | // Find this selector in a hash table. We want to find the most recent entry. |
| 4228 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4229 | PerFileData &F = *Chain[I]; |
| 4230 | if (!F.SelectorLookupTable) |
| 4231 | continue; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4232 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4233 | ASTSelectorLookupTable *PoolTable |
| 4234 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 4235 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4236 | if (Pos != PoolTable->end()) { |
| 4237 | ++NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4238 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4239 | // disable this tracking when called via LoadSelector. |
| 4240 | // Also, should entries without methods count as misses? |
| 4241 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4242 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4243 | if (DeserializationListener) |
| 4244 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 4245 | return std::make_pair(Data.Instance, Data.Factory); |
| 4246 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4247 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4248 | |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4249 | ++NumMethodPoolMisses; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4250 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4251 | } |
| 4252 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4253 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4254 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4255 | ReadMethodPool(Sel); |
| 4256 | } |
| 4257 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4258 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4259 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4260 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4261 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4262 | if (DeserializationListener) |
| 4263 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4264 | } |
| 4265 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4266 | /// \brief Set the globally-visible declarations associated with the given |
| 4267 | /// identifier. |
| 4268 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4269 | /// 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] | 4270 | /// 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] | 4271 | /// them. |
| 4272 | /// |
| 4273 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4274 | /// declarations. |
| 4275 | /// |
| 4276 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4277 | /// visible at global scope. |
| 4278 | /// |
| 4279 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4280 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4281 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4282 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4283 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4284 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 4285 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4286 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4287 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4288 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4289 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4290 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4291 | return; |
| 4292 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4293 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4294 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4295 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4296 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4297 | if (SemaObj->TUScope) { |
| 4298 | // Introduce this declaration into the translation-unit scope |
| 4299 | // and add it to the declaration chain for this identifier, so |
| 4300 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4301 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4302 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4303 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4304 | } else { |
| 4305 | // Queue this declaration so that it will be added to the |
| 4306 | // translation unit scope and identifier's declaration chain |
| 4307 | // once a Sema object is known. |
| 4308 | PreloadedDecls.push_back(D); |
| 4309 | } |
| 4310 | } |
| 4311 | } |
| 4312 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4313 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4314 | if (ID == 0) |
| 4315 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4316 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4317 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4318 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4319 | return 0; |
| 4320 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4321 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4322 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4323 | ID -= 1; |
| 4324 | if (!IdentifiersLoaded[ID]) { |
| 4325 | unsigned Index = ID; |
| 4326 | const char *Str = 0; |
| 4327 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4328 | PerFileData *F = Chain[N - I - 1]; |
| 4329 | if (Index < F->LocalNumIdentifiers) { |
| 4330 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 4331 | Str = F->IdentifierTableData + Offset; |
| 4332 | break; |
| 4333 | } |
| 4334 | Index -= F->LocalNumIdentifiers; |
| 4335 | } |
| 4336 | assert(Str && "Broken Chain"); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4337 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4338 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4339 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4340 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4341 | // unsigned integers. This is important to avoid integer overflow when |
| 4342 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4343 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4344 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4345 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4346 | IdentifiersLoaded[ID] |
Kovarththanan Rajaratnam | 811f426 | 2010-03-12 10:32:27 +0000 | [diff] [blame] | 4347 | = &PP->getIdentifierTable().get(Str, StrLen); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4348 | if (DeserializationListener) |
| 4349 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4350 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4351 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4352 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4353 | } |
| 4354 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4355 | void ASTReader::ReadSLocEntry(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4356 | ReadSLocEntryRecord(ID); |
| 4357 | } |
| 4358 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4359 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4360 | if (ID == 0) |
| 4361 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4362 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4363 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4364 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4365 | return Selector(); |
| 4366 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4367 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4368 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4369 | // Load this selector from the selector table. |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4370 | unsigned Idx = ID - 1; |
| 4371 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4372 | PerFileData &F = *Chain[N - I - 1]; |
| 4373 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4374 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4375 | SelectorsLoaded[ID - 1] = |
| 4376 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 4377 | if (DeserializationListener) |
| 4378 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 4379 | break; |
| 4380 | } |
| 4381 | Idx -= F.LocalNumSelectors; |
| 4382 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4383 | } |
| 4384 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4385 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4386 | } |
| 4387 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4388 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4389 | return DecodeSelector(ID); |
| 4390 | } |
| 4391 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4392 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4393 | // ID 0 (the null selector) is considered an external selector. |
| 4394 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4395 | } |
| 4396 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4397 | DeclarationName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4398 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4399 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4400 | switch (Kind) { |
| 4401 | case DeclarationName::Identifier: |
| 4402 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 4403 | |
| 4404 | case DeclarationName::ObjCZeroArgSelector: |
| 4405 | case DeclarationName::ObjCOneArgSelector: |
| 4406 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 4407 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4408 | |
| 4409 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4410 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4411 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4412 | |
| 4413 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4414 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4415 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4416 | |
| 4417 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4418 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4419 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4420 | |
| 4421 | case DeclarationName::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4422 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4423 | (OverloadedOperatorKind)Record[Idx++]); |
| 4424 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4425 | case DeclarationName::CXXLiteralOperatorName: |
| 4426 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 4427 | GetIdentifierInfo(Record, Idx)); |
| 4428 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4429 | case DeclarationName::CXXUsingDirective: |
| 4430 | return DeclarationName::getUsingDirectiveName(); |
| 4431 | } |
| 4432 | |
| 4433 | // Required to silence GCC warning |
| 4434 | return DeclarationName(); |
| 4435 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4436 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4437 | void ASTReader::ReadDeclarationNameLoc(PerFileData &F, |
| 4438 | DeclarationNameLoc &DNLoc, |
| 4439 | DeclarationName Name, |
| 4440 | const RecordData &Record, unsigned &Idx) { |
| 4441 | switch (Name.getNameKind()) { |
| 4442 | case DeclarationName::CXXConstructorName: |
| 4443 | case DeclarationName::CXXDestructorName: |
| 4444 | case DeclarationName::CXXConversionFunctionName: |
| 4445 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4446 | break; |
| 4447 | |
| 4448 | case DeclarationName::CXXOperatorName: |
| 4449 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4450 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4451 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4452 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4453 | break; |
| 4454 | |
| 4455 | case DeclarationName::CXXLiteralOperatorName: |
| 4456 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4457 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4458 | break; |
| 4459 | |
| 4460 | case DeclarationName::Identifier: |
| 4461 | case DeclarationName::ObjCZeroArgSelector: |
| 4462 | case DeclarationName::ObjCOneArgSelector: |
| 4463 | case DeclarationName::ObjCMultiArgSelector: |
| 4464 | case DeclarationName::CXXUsingDirective: |
| 4465 | break; |
| 4466 | } |
| 4467 | } |
| 4468 | |
| 4469 | void ASTReader::ReadDeclarationNameInfo(PerFileData &F, |
| 4470 | DeclarationNameInfo &NameInfo, |
| 4471 | const RecordData &Record, unsigned &Idx) { |
| 4472 | NameInfo.setName(ReadDeclarationName(Record, Idx)); |
| 4473 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4474 | DeclarationNameLoc DNLoc; |
| 4475 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4476 | NameInfo.setInfo(DNLoc); |
| 4477 | } |
| 4478 | |
| 4479 | void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info, |
| 4480 | const RecordData &Record, unsigned &Idx) { |
| 4481 | Info.NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4482 | Info.NNSRange = ReadSourceRange(F, Record, Idx); |
| 4483 | unsigned NumTPLists = Record[Idx++]; |
| 4484 | Info.NumTemplParamLists = NumTPLists; |
| 4485 | if (NumTPLists) { |
| 4486 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 4487 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4488 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4489 | } |
| 4490 | } |
| 4491 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4492 | TemplateName |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4493 | ASTReader::ReadTemplateName(PerFileData &F, const RecordData &Record, |
| 4494 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4495 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4496 | switch (Kind) { |
| 4497 | case TemplateName::Template: |
| 4498 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 4499 | |
| 4500 | case TemplateName::OverloadedTemplate: { |
| 4501 | unsigned size = Record[Idx++]; |
| 4502 | UnresolvedSet<8> Decls; |
| 4503 | while (size--) |
| 4504 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 4505 | |
| 4506 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 4507 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4508 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4509 | case TemplateName::QualifiedTemplate: { |
| 4510 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4511 | bool hasTemplKeyword = Record[Idx++]; |
| 4512 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 4513 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 4514 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4515 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4516 | case TemplateName::DependentTemplate: { |
| 4517 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4518 | if (Record[Idx++]) // isIdentifier |
| 4519 | return Context->getDependentTemplateName(NNS, |
| 4520 | GetIdentifierInfo(Record, Idx)); |
| 4521 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4522 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4523 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4524 | |
| 4525 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4526 | TemplateTemplateParmDecl *Param |
| 4527 | = cast_or_null<TemplateTemplateParmDecl>(GetDecl(Record[Idx++])); |
| 4528 | if (!Param) |
| 4529 | return TemplateName(); |
| 4530 | |
| 4531 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 4532 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 4533 | return TemplateName(); |
| 4534 | |
| 4535 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 4536 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4537 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4538 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4539 | assert(0 && "Unhandled template name kind!"); |
| 4540 | return TemplateName(); |
| 4541 | } |
| 4542 | |
| 4543 | TemplateArgument |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4544 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4545 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4546 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 4547 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4548 | case TemplateArgument::Null: |
| 4549 | return TemplateArgument(); |
| 4550 | case TemplateArgument::Type: |
| 4551 | return TemplateArgument(GetType(Record[Idx++])); |
| 4552 | case TemplateArgument::Declaration: |
| 4553 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4554 | case TemplateArgument::Integral: { |
| 4555 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 4556 | QualType T = GetType(Record[Idx++]); |
| 4557 | return TemplateArgument(Value, T); |
| 4558 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4559 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4560 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4561 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4562 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4563 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 4564 | if (unsigned NumExpansions = Record[Idx++]) |
| 4565 | NumTemplateExpansions = NumExpansions - 1; |
| 4566 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4567 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4568 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4569 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4570 | case TemplateArgument::Pack: { |
| 4571 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4572 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 4573 | for (unsigned I = 0; I != NumArgs; ++I) |
| 4574 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 4575 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4576 | } |
| 4577 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4578 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4579 | assert(0 && "Unhandled template argument kind!"); |
| 4580 | return TemplateArgument(); |
| 4581 | } |
| 4582 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4583 | TemplateParameterList * |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4584 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 4585 | const RecordData &Record, unsigned &Idx) { |
| 4586 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 4587 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 4588 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4589 | |
| 4590 | unsigned NumParams = Record[Idx++]; |
| 4591 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 4592 | Params.reserve(NumParams); |
| 4593 | while (NumParams--) |
| 4594 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4595 | |
| 4596 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4597 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 4598 | Params.data(), Params.size(), RAngleLoc); |
| 4599 | return TemplateParams; |
| 4600 | } |
| 4601 | |
| 4602 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4603 | ASTReader:: |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4604 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4605 | PerFileData &F, const RecordData &Record, |
| 4606 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4607 | unsigned NumTemplateArgs = Record[Idx++]; |
| 4608 | TemplArgs.reserve(NumTemplateArgs); |
| 4609 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4610 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4611 | } |
| 4612 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4613 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4614 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4615 | const RecordData &Record, unsigned &Idx) { |
| 4616 | unsigned NumDecls = Record[Idx++]; |
| 4617 | while (NumDecls--) { |
| 4618 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 4619 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 4620 | Set.addDecl(D, AS); |
| 4621 | } |
| 4622 | } |
| 4623 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4624 | CXXBaseSpecifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4625 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4626 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4627 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 4628 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 4629 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4630 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4631 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4632 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4633 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4634 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4635 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4636 | Result.setInheritConstructors(inheritConstructors); |
| 4637 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4638 | } |
| 4639 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4640 | std::pair<CXXCtorInitializer **, unsigned> |
| 4641 | ASTReader::ReadCXXCtorInitializers(PerFileData &F, const RecordData &Record, |
| 4642 | unsigned &Idx) { |
| 4643 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4644 | unsigned NumInitializers = Record[Idx++]; |
| 4645 | if (NumInitializers) { |
| 4646 | ASTContext &C = *getContext(); |
| 4647 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4648 | CtorInitializers |
| 4649 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4650 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 4651 | TypeSourceInfo *BaseClassInfo = 0; |
| 4652 | bool IsBaseVirtual = false; |
| 4653 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4654 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4655 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4656 | bool IsBaseInitializer = Record[Idx++]; |
| 4657 | if (IsBaseInitializer) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4658 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4659 | IsBaseVirtual = Record[Idx++]; |
| 4660 | } else { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4661 | bool IsIndirectMemberInitializer = Record[Idx++]; |
| 4662 | if (IsIndirectMemberInitializer) |
| 4663 | IndirectMember = cast<IndirectFieldDecl>(GetDecl(Record[Idx++])); |
| 4664 | else |
| 4665 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4666 | } |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 4667 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4668 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4669 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 4670 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4671 | bool IsWritten = Record[Idx++]; |
| 4672 | unsigned SourceOrderOrNumArrayIndices; |
| 4673 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 4674 | if (IsWritten) { |
| 4675 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4676 | } else { |
| 4677 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4678 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 4679 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 4680 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 4681 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4682 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4683 | CXXCtorInitializer *BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4684 | if (IsBaseInitializer) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4685 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 4686 | LParenLoc, Init, RParenLoc, |
| 4687 | MemberOrEllipsisLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4688 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4689 | if (Member) |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4690 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 4691 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4692 | else |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4693 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 4694 | MemberOrEllipsisLoc, LParenLoc, |
| 4695 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4696 | } else { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4697 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 4698 | LParenLoc, Init, RParenLoc, |
| 4699 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4700 | } |
| 4701 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 4702 | if (IsWritten) |
| 4703 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4704 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4705 | } |
| 4706 | } |
| 4707 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4708 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4709 | } |
| 4710 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4711 | NestedNameSpecifier * |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4712 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4713 | unsigned N = Record[Idx++]; |
| 4714 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 4715 | for (unsigned I = 0; I != N; ++I) { |
| 4716 | NestedNameSpecifier::SpecifierKind Kind |
| 4717 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4718 | switch (Kind) { |
| 4719 | case NestedNameSpecifier::Identifier: { |
| 4720 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 4721 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 4722 | break; |
| 4723 | } |
| 4724 | |
| 4725 | case NestedNameSpecifier::Namespace: { |
| 4726 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 4727 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 4728 | break; |
| 4729 | } |
| 4730 | |
| 4731 | case NestedNameSpecifier::TypeSpec: |
| 4732 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4733 | const Type *T = GetType(Record[Idx++]).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 4734 | if (!T) |
| 4735 | return 0; |
| 4736 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4737 | bool Template = Record[Idx++]; |
| 4738 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 4739 | break; |
| 4740 | } |
| 4741 | |
| 4742 | case NestedNameSpecifier::Global: { |
| 4743 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4744 | // No associated value, and there can't be a prefix. |
| 4745 | break; |
| 4746 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4747 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 4748 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4749 | } |
| 4750 | return NNS; |
| 4751 | } |
| 4752 | |
| 4753 | SourceRange |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4754 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 4755 | unsigned &Idx) { |
| 4756 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 4757 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 4758 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4759 | } |
| 4760 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4761 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4762 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4763 | unsigned BitWidth = Record[Idx++]; |
| 4764 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 4765 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 4766 | Idx += NumWords; |
| 4767 | return Result; |
| 4768 | } |
| 4769 | |
| 4770 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4771 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4772 | bool isUnsigned = Record[Idx++]; |
| 4773 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 4774 | } |
| 4775 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4776 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4777 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4778 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 4779 | } |
| 4780 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4781 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4782 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4783 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 4784 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4785 | Idx += Len; |
| 4786 | return Result; |
| 4787 | } |
| 4788 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4789 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4790 | unsigned &Idx) { |
| 4791 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 4792 | return CXXTemporary::Create(*Context, Decl); |
| 4793 | } |
| 4794 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4795 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 4796 | return Diag(SourceLocation(), DiagID); |
| 4797 | } |
| 4798 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4799 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4800 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4801 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4802 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4803 | /// \brief Retrieve the identifier table associated with the |
| 4804 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4805 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4806 | assert(PP && "Forgot to set Preprocessor ?"); |
| 4807 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4808 | } |
| 4809 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4810 | /// \brief Record that the given ID maps to the given switch-case |
| 4811 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4812 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4813 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 4814 | SwitchCaseStmts[ID] = SC; |
| 4815 | } |
| 4816 | |
| 4817 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4818 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4819 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 4820 | return SwitchCaseStmts[ID]; |
| 4821 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4822 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4823 | void ASTReader::ClearSwitchCaseIDs() { |
| 4824 | SwitchCaseStmts.clear(); |
| 4825 | } |
| 4826 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4827 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4828 | assert(NumCurrentElementsDeserializing && |
| 4829 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 4830 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4831 | // If any identifiers with corresponding top-level declarations have |
| 4832 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4833 | while (!PendingIdentifierInfos.empty()) { |
| 4834 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 4835 | PendingIdentifierInfos.front().DeclIDs, true); |
| 4836 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4837 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4838 | |
Argyrios Kyrtzidis | 0895d15 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 4839 | // Ready to load previous declarations of Decls that were delayed. |
| 4840 | while (!PendingPreviousDecls.empty()) { |
| 4841 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 4842 | PendingPreviousDecls.front().second); |
| 4843 | PendingPreviousDecls.pop_front(); |
| 4844 | } |
| 4845 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4846 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 4847 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4848 | if (Consumer) |
| 4849 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 4850 | |
| 4851 | assert(PendingForwardRefs.size() == 0 && |
| 4852 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4853 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4854 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4855 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4856 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4857 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4858 | const char *isysroot, bool DisableValidation, |
| 4859 | bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4860 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 4861 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 4862 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
| 4863 | Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4864 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 4865 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), NextSLocOffset(0), |
| 4866 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 4867 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 4868 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 4869 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
| 4870 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 4871 | NumCurrentElementsDeserializing(0) |
| 4872 | { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4873 | RelocatablePCH = false; |
| 4874 | } |
| 4875 | |
| 4876 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 4877 | Diagnostic &Diags, const char *isysroot, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4878 | bool DisableValidation, bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4879 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
| 4880 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4881 | isysroot(isysroot), DisableValidation(DisableValidation), |
| 4882 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 4883 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4884 | NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0), |
| 4885 | NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), |
| 4886 | NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
| 4887 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4888 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4889 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4890 | RelocatablePCH = false; |
| 4891 | } |
| 4892 | |
| 4893 | ASTReader::~ASTReader() { |
| 4894 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 4895 | delete Chain[e - i - 1]; |
| 4896 | // Delete all visible decl lookup tables |
| 4897 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 4898 | E = DeclContextOffsets.end(); |
| 4899 | I != E; ++I) { |
| 4900 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 4901 | J != F; ++J) { |
| 4902 | if (J->NameLookupTableData) |
| 4903 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 4904 | J->NameLookupTableData); |
| 4905 | } |
| 4906 | } |
| 4907 | for (DeclContextVisibleUpdatesPending::iterator |
| 4908 | I = PendingVisibleUpdates.begin(), |
| 4909 | E = PendingVisibleUpdates.end(); |
| 4910 | I != E; ++I) { |
| 4911 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 4912 | F = I->second.end(); |
| 4913 | J != F; ++J) |
| 4914 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 4915 | } |
| 4916 | } |
| 4917 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 4918 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
| 4919 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 4920 | LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), |
| 4921 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4922 | MacroDefinitionOffsets(0), |
| 4923 | LocalNumHeaderFileInfos(0), HeaderFileInfoTableData(0), |
| 4924 | HeaderFileInfoTable(0), |
| 4925 | LocalNumSelectors(0), SelectorOffsets(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 4926 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4927 | DeclOffsets(0), LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
| 4928 | LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 4929 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4930 | {} |
| 4931 | |
| 4932 | ASTReader::PerFileData::~PerFileData() { |
| 4933 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4934 | delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4935 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 4936 | } |
| 4937 | |