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 | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 26 | #include "clang/AST/NestedNameSpecifier.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 27 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 28 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 29 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 30 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 31 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 32 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 33 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 34 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 35 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 36 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 37 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 38 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 39 | #include "clang/Basic/Version.h" |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 40 | #include "clang/Basic/VersionTuple.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 41 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 42 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 43 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 44 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 45 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 46 | #include "llvm/Support/Path.h" |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 47 | #include "llvm/Support/system_error.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 48 | #include <algorithm> |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 49 | #include <iterator> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 50 | #include <cstdio> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 51 | #include <sys/stat.h> |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 52 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 53 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 54 | using namespace clang::serialization; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 55 | |
| 56 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 57 | // PCH validator implementation |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 58 | //===----------------------------------------------------------------------===// |
| 59 | |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 60 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 61 | |
| 62 | bool |
| 63 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 64 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 65 | #define PARSE_LANGOPT_BENIGN(Option) |
| 66 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 67 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 68 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 69 | return true; \ |
| 70 | } |
| 71 | |
| 72 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 73 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 74 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 75 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 76 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 77 | PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 78 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 79 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 80 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 81 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
| 82 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 83 | PARSE_LANGOPT_BENIGN(MSCVersion); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 84 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 85 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 86 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 87 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 88 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 89 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 90 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 91 | PARSE_LANGOPT_IMPORTANT(AppleKext, diag::warn_pch_apple_kext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 92 | PARSE_LANGOPT_IMPORTANT(ObjCDefaultSynthProperties, |
| 93 | diag::warn_pch_objc_auto_properties); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 94 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 95 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 96 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 97 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 98 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 99 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 100 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 101 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 102 | PARSE_LANGOPT_IMPORTANT(ObjCExceptions, diag::warn_pch_objc_exceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 103 | PARSE_LANGOPT_IMPORTANT(CXXExceptions, diag::warn_pch_cxx_exceptions); |
| 104 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 105 | PARSE_LANGOPT_IMPORTANT(MSBitfields, diag::warn_pch_ms_bitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 106 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 107 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 108 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 109 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 110 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 111 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 112 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 113 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 114 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 115 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 116 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 117 | diag::warn_pch_heinous_extensions); |
| 118 | // FIXME: Most of the options below are benign if the macro wasn't |
| 119 | // used. Unfortunately, this means that a PCH compiled without |
| 120 | // optimization can't be used with optimization turned on, even |
| 121 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 122 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 123 | // doesn't matter. We could consider making this some special kind |
| 124 | // of check. |
| 125 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 126 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 127 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 128 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 129 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 130 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
| 131 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 132 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 133 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 134 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 135 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 136 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 137 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 138 | return true; |
| 139 | } |
| 140 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 141 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 142 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 143 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 144 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 145 | PARSE_LANGOPT_IMPORTANT(CUDA, diag::warn_pch_cuda); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 146 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 147 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 148 | PARSE_LANGOPT_BENIGN(SpellChecking); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 149 | PARSE_LANGOPT_BENIGN(DefaultFPContract); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 150 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 151 | #undef PARSE_LANGOPT_BENIGN |
| 152 | |
| 153 | return false; |
| 154 | } |
| 155 | |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 156 | bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) { |
| 157 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 158 | return false; |
| 159 | |
| 160 | Reader.Diag(diag::warn_pch_target_triple) |
| 161 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 162 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 165 | namespace { |
| 166 | struct EmptyStringRef { |
| 167 | bool operator ()(llvm::StringRef r) const { return r.empty(); } |
| 168 | }; |
| 169 | struct EmptyBlock { |
| 170 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 171 | }; |
| 172 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 173 | |
| 174 | static bool EqualConcatenations(llvm::SmallVector<llvm::StringRef, 2> L, |
| 175 | PCHPredefinesBlocks R) { |
| 176 | // First, sum up the lengths. |
| 177 | unsigned LL = 0, RL = 0; |
| 178 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 179 | LL += L[I].size(); |
| 180 | } |
| 181 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 182 | RL += R[I].Data.size(); |
| 183 | } |
| 184 | if (LL != RL) |
| 185 | return false; |
| 186 | if (LL == 0 && RL == 0) |
| 187 | return true; |
| 188 | |
| 189 | // Kick out empty parts, they confuse the algorithm below. |
| 190 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 191 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 192 | |
| 193 | // Do it the hard way. At this point, both vectors must be non-empty. |
| 194 | llvm::StringRef LR = L[0], RR = R[0].Data; |
| 195 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 196 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 197 | for (;;) { |
| 198 | // Compare the current pieces. |
| 199 | if (LR.size() == RR.size()) { |
| 200 | // If they're the same length, it's pretty easy. |
| 201 | if (LR != RR) |
| 202 | return false; |
| 203 | // Both pieces are done, advance. |
| 204 | ++LI; |
| 205 | ++RI; |
| 206 | // If either string is done, they're both done, since they're the same |
| 207 | // length. |
| 208 | if (LI == LN) { |
| 209 | assert(RI == RN && "Strings not the same length after all?"); |
| 210 | return true; |
| 211 | } |
| 212 | LR = L[LI]; |
| 213 | RR = R[RI].Data; |
| 214 | } else if (LR.size() < RR.size()) { |
| 215 | // Right piece is longer. |
| 216 | if (!RR.startswith(LR)) |
| 217 | return false; |
| 218 | ++LI; |
| 219 | assert(LI != LN && "Strings not the same length after all?"); |
| 220 | RR = RR.substr(LR.size()); |
| 221 | LR = L[LI]; |
| 222 | } else { |
| 223 | // Left piece is longer. |
| 224 | if (!LR.startswith(RR)) |
| 225 | return false; |
| 226 | ++RI; |
| 227 | assert(RI != RN && "Strings not the same length after all?"); |
| 228 | LR = LR.substr(RR.size()); |
| 229 | RR = R[RI].Data; |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | static std::pair<FileID, llvm::StringRef::size_type> |
| 235 | FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) { |
| 236 | std::pair<FileID, llvm::StringRef::size_type> Res; |
| 237 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 238 | Res.second = Buffers[I].Data.find(MacroDef); |
| 239 | if (Res.second != llvm::StringRef::npos) { |
| 240 | Res.first = Buffers[I].BufferID; |
| 241 | break; |
| 242 | } |
| 243 | } |
| 244 | return Res; |
| 245 | } |
| 246 | |
| 247 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 248 | llvm::StringRef OriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 249 | std::string &SuggestedPredefines, |
| 250 | FileManager &FileMgr) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 251 | // We are in the context of an implicit include, so the predefines buffer will |
| 252 | // have a #include entry for the PCH file itself (as normalized by the |
| 253 | // preprocessor initialization). Find it and skip over it in the checking |
| 254 | // below. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 255 | llvm::SmallString<256> PCHInclude; |
| 256 | PCHInclude += "#include \""; |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 257 | PCHInclude += NormalizeDashIncludePath(OriginalFileName, FileMgr); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 258 | PCHInclude += "\"\n"; |
| 259 | std::pair<llvm::StringRef,llvm::StringRef> Split = |
| 260 | llvm::StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 261 | llvm::StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 262 | if (Left == PP.getPredefines()) { |
| 263 | Error("Missing PCH include entry!"); |
| 264 | return true; |
| 265 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 266 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 267 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 268 | // command line, we're done. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 269 | llvm::SmallVector<llvm::StringRef, 2> CommandLine; |
| 270 | CommandLine.push_back(Left); |
| 271 | CommandLine.push_back(Right); |
| 272 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 273 | return false; |
| 274 | |
| 275 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 276 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 277 | // The predefines buffers are different. Determine what the differences are, |
| 278 | // and whether they require us to reject the PCH file. |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 279 | llvm::SmallVector<llvm::StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 280 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 281 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 282 | |
| 283 | llvm::SmallVector<llvm::StringRef, 8> CmdLineLines; |
| 284 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 285 | |
| 286 | // Pick out implicit #includes after the PCH and don't consider them for |
| 287 | // validation; we will insert them into SuggestedPredefines so that the |
| 288 | // preprocessor includes them. |
| 289 | std::string IncludesAfterPCH; |
| 290 | llvm::SmallVector<llvm::StringRef, 8> AfterPCHLines; |
| 291 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 292 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 293 | if (AfterPCHLines[i].startswith("#include ")) { |
| 294 | IncludesAfterPCH += AfterPCHLines[i]; |
| 295 | IncludesAfterPCH += '\n'; |
| 296 | } else { |
| 297 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | // Make sure we add the includes last into SuggestedPredefines before we |
| 302 | // exit this function. |
| 303 | struct AddIncludesRAII { |
| 304 | std::string &SuggestedPredefines; |
| 305 | std::string &IncludesAfterPCH; |
| 306 | |
| 307 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 308 | std::string &IncludesAfterPCH) |
| 309 | : SuggestedPredefines(SuggestedPredefines), |
| 310 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 311 | ~AddIncludesRAII() { |
| 312 | SuggestedPredefines += IncludesAfterPCH; |
| 313 | } |
| 314 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 315 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 316 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 317 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 318 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 319 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 320 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 321 | // Determine which predefines that were used to build the PCH file are missing |
| 322 | // from the command line. |
| 323 | std::vector<llvm::StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 324 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 325 | CmdLineLines.begin(), CmdLineLines.end(), |
| 326 | std::back_inserter(MissingPredefines)); |
| 327 | |
| 328 | bool MissingDefines = false; |
| 329 | bool ConflictingDefines = false; |
| 330 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 331 | llvm::StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 332 | if (Missing.startswith("#include ")) { |
| 333 | // An -include was specified when generating the PCH; it is included in |
| 334 | // the PCH, just ignore it. |
| 335 | continue; |
| 336 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 337 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 338 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 339 | return true; |
| 340 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 341 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 342 | // This is a macro definition. Determine the name of the macro we're |
| 343 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 344 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 345 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 346 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 347 | assert(EndOfMacroName != std::string::npos && |
| 348 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 349 | llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 350 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 351 | // Determine whether this macro was given a different definition on the |
| 352 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 353 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 354 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 355 | llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 356 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 357 | MacroDefStart); |
| 358 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 359 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 360 | // Different macro; we're done. |
| 361 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 362 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 363 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | |
| 365 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 366 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 367 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 368 | (*ConflictPos)[MacroDefLen] != '(') |
| 369 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 370 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 371 | // We found a conflicting macro definition. |
| 372 | break; |
| 373 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 374 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 375 | if (ConflictPos != CmdLineLines.end()) { |
| 376 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 377 | << MacroName; |
| 378 | |
| 379 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 380 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 381 | FindMacro(Buffers, Missing); |
| 382 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 383 | SourceLocation PCHMissingLoc = |
| 384 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 385 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 386 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 387 | |
| 388 | ConflictingDefines = true; |
| 389 | continue; |
| 390 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 391 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 392 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 393 | // 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] | 394 | if (ConflictingDefines) |
| 395 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 396 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 397 | if (!MissingDefines) { |
| 398 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 399 | MissingDefines = true; |
| 400 | } |
| 401 | |
| 402 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 403 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 404 | FindMacro(Buffers, Missing); |
| 405 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 406 | SourceLocation PCHMissingLoc = |
| 407 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 408 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 409 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 410 | } |
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 | if (ConflictingDefines) |
| 413 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 414 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 415 | // Determine what predefines were introduced based on command-line |
| 416 | // parameters that were not present when building the PCH |
| 417 | // file. Extra #defines are okay, so long as the identifiers being |
| 418 | // defined were not used within the precompiled header. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 419 | std::vector<llvm::StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 420 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 421 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 423 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 424 | llvm::StringRef &Extra = ExtraPredefines[I]; |
| 425 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 426 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 427 | return true; |
| 428 | } |
| 429 | |
| 430 | // This is an extra macro definition. Determine the name of the |
| 431 | // macro we're defining. |
| 432 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 434 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 435 | assert(EndOfMacroName != std::string::npos && |
| 436 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 437 | llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 438 | |
| 439 | // Check whether this name was used somewhere in the PCH file. If |
| 440 | // so, defining it as a macro could change behavior, so we reject |
| 441 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 442 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 443 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 444 | return true; |
| 445 | } |
| 446 | |
| 447 | // Add this definition to the suggested predefines buffer. |
| 448 | SuggestedPredefines += Extra; |
| 449 | SuggestedPredefines += '\n'; |
| 450 | } |
| 451 | |
| 452 | // If we get here, it's because the predefines buffer had compatible |
| 453 | // contents. Accept the PCH file. |
| 454 | return false; |
| 455 | } |
| 456 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 457 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 458 | unsigned ID) { |
| 459 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 460 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | void PCHValidator::ReadCounter(unsigned Value) { |
| 464 | PP.setCounterValue(Value); |
| 465 | } |
| 466 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 467 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 468 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 469 | //===----------------------------------------------------------------------===// |
| 470 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 471 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 472 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 473 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 474 | } |
| 475 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 476 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 477 | namespace { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 478 | class ASTSelectorLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 479 | ASTReader &Reader; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 480 | |
| 481 | public: |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 482 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 483 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 484 | ObjCMethodList Instance, Factory; |
| 485 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 486 | |
| 487 | typedef Selector external_key_type; |
| 488 | typedef external_key_type internal_key_type; |
| 489 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 490 | explicit ASTSelectorLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 491 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 492 | static bool EqualKey(const internal_key_type& a, |
| 493 | const internal_key_type& b) { |
| 494 | return a == b; |
| 495 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 496 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 497 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 498 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 499 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 500 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 501 | // This hopefully will just get inlined and removed by the optimizer. |
| 502 | static const internal_key_type& |
| 503 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 504 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 505 | static std::pair<unsigned, unsigned> |
| 506 | ReadKeyDataLength(const unsigned char*& d) { |
| 507 | using namespace clang::io; |
| 508 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 509 | unsigned DataLen = ReadUnalignedLE16(d); |
| 510 | return std::make_pair(KeyLen, DataLen); |
| 511 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 512 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 513 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 514 | using namespace clang::io; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 515 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 516 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 517 | IdentifierInfo *FirstII |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 518 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 519 | if (N == 0) |
| 520 | return SelTable.getNullarySelector(FirstII); |
| 521 | else if (N == 1) |
| 522 | return SelTable.getUnarySelector(FirstII); |
| 523 | |
| 524 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 525 | Args.push_back(FirstII); |
| 526 | for (unsigned I = 1; I != N; ++I) |
| 527 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 528 | |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 529 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 530 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 531 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 532 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 533 | using namespace clang::io; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 534 | |
| 535 | data_type Result; |
| 536 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 537 | Result.ID = ReadUnalignedLE32(d); |
| 538 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 539 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 540 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 541 | // Load instance methods |
| 542 | ObjCMethodList *Prev = 0; |
| 543 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 545 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 546 | if (!Result.Instance.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 547 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 548 | Result.Instance.Method = Method; |
| 549 | Prev = &Result.Instance; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 550 | continue; |
| 551 | } |
| 552 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 553 | ObjCMethodList *Mem = |
| 554 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 555 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 556 | Prev = Prev->Next; |
| 557 | } |
| 558 | |
| 559 | // Load factory methods |
| 560 | Prev = 0; |
| 561 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 562 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 563 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 564 | if (!Result.Factory.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 565 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 566 | Result.Factory.Method = Method; |
| 567 | Prev = &Result.Factory; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 568 | continue; |
| 569 | } |
| 570 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 571 | ObjCMethodList *Mem = |
| 572 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 573 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 574 | Prev = Prev->Next; |
| 575 | } |
| 576 | |
| 577 | return Result; |
| 578 | } |
| 579 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 580 | |
| 581 | } // end anonymous namespace |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 582 | |
| 583 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 584 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 585 | ASTSelectorLookupTable; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 586 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 587 | namespace clang { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 588 | class ASTIdentifierLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 589 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 590 | ASTReader::PerFileData &F; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 591 | |
| 592 | // If we know the IdentifierInfo in advance, it is here and we will |
| 593 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 594 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 595 | IdentifierInfo *KnownII; |
| 596 | |
| 597 | public: |
| 598 | typedef IdentifierInfo * data_type; |
| 599 | |
| 600 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 601 | |
| 602 | typedef external_key_type internal_key_type; |
| 603 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 604 | ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 605 | IdentifierInfo *II = 0) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 606 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 607 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 608 | static bool EqualKey(const internal_key_type& a, |
| 609 | const internal_key_type& b) { |
| 610 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 611 | : false; |
| 612 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 613 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 614 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 615 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 616 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 617 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 618 | // This hopefully will just get inlined and removed by the optimizer. |
| 619 | static const internal_key_type& |
| 620 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 621 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 622 | // This hopefully will just get inlined and removed by the optimizer. |
| 623 | static const external_key_type& |
| 624 | GetExternalKey(const internal_key_type& x) { return x; } |
| 625 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 626 | static std::pair<unsigned, unsigned> |
| 627 | ReadKeyDataLength(const unsigned char*& d) { |
| 628 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 629 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 630 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 631 | return std::make_pair(KeyLen, DataLen); |
| 632 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 633 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 634 | static std::pair<const char*, unsigned> |
| 635 | ReadKey(const unsigned char* d, unsigned n) { |
| 636 | assert(n >= 2 && d[n-1] == '\0'); |
| 637 | return std::make_pair((const char*) d, n-1); |
| 638 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 639 | |
| 640 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 641 | const unsigned char* d, |
| 642 | unsigned DataLen) { |
| 643 | using namespace clang::io; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 644 | IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 645 | bool IsInteresting = ID & 0x01; |
| 646 | |
| 647 | // Wipe out the "is interesting" bit. |
| 648 | ID = ID >> 1; |
| 649 | |
| 650 | if (!IsInteresting) { |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 651 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 652 | // and associate it with the persistent ID. |
| 653 | IdentifierInfo *II = KnownII; |
| 654 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 655 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 656 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 657 | II->setIsFromAST(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 658 | return II; |
| 659 | } |
| 660 | |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 661 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 662 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 663 | Bits >>= 1; |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 664 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 665 | Bits >>= 1; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 666 | bool Poisoned = Bits & 0x01; |
| 667 | Bits >>= 1; |
| 668 | bool ExtensionToken = Bits & 0x01; |
| 669 | Bits >>= 1; |
| 670 | bool hasMacroDefinition = Bits & 0x01; |
| 671 | Bits >>= 1; |
| 672 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 673 | Bits >>= 10; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 674 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 675 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 676 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 677 | |
| 678 | // Build the IdentifierInfo itself and link the identifier ID with |
| 679 | // the new IdentifierInfo. |
| 680 | IdentifierInfo *II = KnownII; |
| 681 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 682 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 683 | Reader.SetIdentifierInfo(ID, II); |
| 684 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 685 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 686 | // Token IDs are read-only. |
| 687 | if (HasRevertedTokenIDToIdentifier) |
| 688 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 689 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 690 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 691 | "Incorrect extension token flag"); |
| 692 | (void)ExtensionToken; |
| 693 | II->setIsPoisoned(Poisoned); |
| 694 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 695 | "Incorrect C++ operator keyword flag"); |
| 696 | (void)CPlusPlusOperatorKeyword; |
| 697 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 698 | // If this identifier is a macro, deserialize the macro |
| 699 | // definition. |
| 700 | if (hasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 701 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 702 | Reader.SetIdentifierIsMacro(II, F, Offset); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 703 | DataLen -= 4; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 704 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 705 | |
| 706 | // Read all of the declarations visible at global scope with this |
| 707 | // name. |
Chris Lattner | 6bf690f | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 708 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 709 | if (DataLen > 0) { |
| 710 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 711 | for (; DataLen > 0; DataLen -= 4) |
| 712 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 713 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 714 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 715 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 716 | II->setIsFromAST(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 717 | return II; |
| 718 | } |
| 719 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 720 | |
| 721 | } // end anonymous namespace |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 722 | |
| 723 | /// \brief The on-disk hash table used to contain information about |
| 724 | /// all of the identifiers in the program. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 725 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 726 | ASTIdentifierLookupTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 727 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 728 | namespace { |
| 729 | class ASTDeclContextNameLookupTrait { |
| 730 | ASTReader &Reader; |
| 731 | |
| 732 | public: |
| 733 | /// \brief Pair of begin/end iterators for DeclIDs. |
| 734 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 735 | |
| 736 | /// \brief Special internal key for declaration names. |
| 737 | /// The hash table creates keys for comparison; we do not create |
| 738 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 739 | struct DeclNameKey { |
| 740 | DeclarationName::NameKind Kind; |
| 741 | uint64_t Data; |
| 742 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 743 | }; |
| 744 | |
| 745 | typedef DeclarationName external_key_type; |
| 746 | typedef DeclNameKey internal_key_type; |
| 747 | |
| 748 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
| 749 | |
| 750 | static bool EqualKey(const internal_key_type& a, |
| 751 | const internal_key_type& b) { |
| 752 | return a.Kind == b.Kind && a.Data == b.Data; |
| 753 | } |
| 754 | |
| 755 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 756 | llvm::FoldingSetNodeID ID; |
| 757 | ID.AddInteger(Key.Kind); |
| 758 | |
| 759 | switch (Key.Kind) { |
| 760 | case DeclarationName::Identifier: |
| 761 | case DeclarationName::CXXLiteralOperatorName: |
| 762 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 763 | break; |
| 764 | case DeclarationName::ObjCZeroArgSelector: |
| 765 | case DeclarationName::ObjCOneArgSelector: |
| 766 | case DeclarationName::ObjCMultiArgSelector: |
| 767 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 768 | break; |
| 769 | case DeclarationName::CXXConstructorName: |
| 770 | case DeclarationName::CXXDestructorName: |
| 771 | case DeclarationName::CXXConversionFunctionName: |
| 772 | ID.AddInteger((TypeID)Key.Data); |
| 773 | break; |
| 774 | case DeclarationName::CXXOperatorName: |
| 775 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 776 | break; |
| 777 | case DeclarationName::CXXUsingDirective: |
| 778 | break; |
| 779 | } |
| 780 | |
| 781 | return ID.ComputeHash(); |
| 782 | } |
| 783 | |
| 784 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 785 | DeclNameKey Key; |
| 786 | Key.Kind = Name.getNameKind(); |
| 787 | switch (Name.getNameKind()) { |
| 788 | case DeclarationName::Identifier: |
| 789 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 790 | break; |
| 791 | case DeclarationName::ObjCZeroArgSelector: |
| 792 | case DeclarationName::ObjCOneArgSelector: |
| 793 | case DeclarationName::ObjCMultiArgSelector: |
| 794 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 795 | break; |
| 796 | case DeclarationName::CXXConstructorName: |
| 797 | case DeclarationName::CXXDestructorName: |
| 798 | case DeclarationName::CXXConversionFunctionName: |
| 799 | Key.Data = Reader.GetTypeID(Name.getCXXNameType()); |
| 800 | break; |
| 801 | case DeclarationName::CXXOperatorName: |
| 802 | Key.Data = Name.getCXXOverloadedOperator(); |
| 803 | break; |
| 804 | case DeclarationName::CXXLiteralOperatorName: |
| 805 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 806 | break; |
| 807 | case DeclarationName::CXXUsingDirective: |
| 808 | break; |
| 809 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 810 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 811 | return Key; |
| 812 | } |
| 813 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 814 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 815 | ASTContext *Context = Reader.getContext(); |
| 816 | switch (Key.Kind) { |
| 817 | case DeclarationName::Identifier: |
| 818 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 819 | |
| 820 | case DeclarationName::ObjCZeroArgSelector: |
| 821 | case DeclarationName::ObjCOneArgSelector: |
| 822 | case DeclarationName::ObjCMultiArgSelector: |
| 823 | return DeclarationName(Selector(Key.Data)); |
| 824 | |
| 825 | case DeclarationName::CXXConstructorName: |
| 826 | return Context->DeclarationNames.getCXXConstructorName( |
| 827 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 828 | |
| 829 | case DeclarationName::CXXDestructorName: |
| 830 | return Context->DeclarationNames.getCXXDestructorName( |
| 831 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 832 | |
| 833 | case DeclarationName::CXXConversionFunctionName: |
| 834 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 835 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 836 | |
| 837 | case DeclarationName::CXXOperatorName: |
| 838 | return Context->DeclarationNames.getCXXOperatorName( |
| 839 | (OverloadedOperatorKind)Key.Data); |
| 840 | |
| 841 | case DeclarationName::CXXLiteralOperatorName: |
| 842 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 843 | (IdentifierInfo*)Key.Data); |
| 844 | |
| 845 | case DeclarationName::CXXUsingDirective: |
| 846 | return DeclarationName::getUsingDirectiveName(); |
| 847 | } |
| 848 | |
| 849 | llvm_unreachable("Invalid Name Kind ?"); |
| 850 | } |
| 851 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 852 | static std::pair<unsigned, unsigned> |
| 853 | ReadKeyDataLength(const unsigned char*& d) { |
| 854 | using namespace clang::io; |
| 855 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 856 | unsigned DataLen = ReadUnalignedLE16(d); |
| 857 | return std::make_pair(KeyLen, DataLen); |
| 858 | } |
| 859 | |
| 860 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 861 | using namespace clang::io; |
| 862 | |
| 863 | DeclNameKey Key; |
| 864 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 865 | switch (Key.Kind) { |
| 866 | case DeclarationName::Identifier: |
| 867 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 868 | break; |
| 869 | case DeclarationName::ObjCZeroArgSelector: |
| 870 | case DeclarationName::ObjCOneArgSelector: |
| 871 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 872 | Key.Data = |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 873 | (uint64_t)Reader.DecodeSelector(ReadUnalignedLE32(d)).getAsOpaquePtr(); |
| 874 | break; |
| 875 | case DeclarationName::CXXConstructorName: |
| 876 | case DeclarationName::CXXDestructorName: |
| 877 | case DeclarationName::CXXConversionFunctionName: |
| 878 | Key.Data = ReadUnalignedLE32(d); // TypeID |
| 879 | break; |
| 880 | case DeclarationName::CXXOperatorName: |
| 881 | Key.Data = *d++; // OverloadedOperatorKind |
| 882 | break; |
| 883 | case DeclarationName::CXXLiteralOperatorName: |
| 884 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 885 | break; |
| 886 | case DeclarationName::CXXUsingDirective: |
| 887 | break; |
| 888 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 889 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 890 | return Key; |
| 891 | } |
| 892 | |
| 893 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 894 | unsigned DataLen) { |
| 895 | using namespace clang::io; |
| 896 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 897 | DeclID *Start = (DeclID *)d; |
| 898 | return std::make_pair(Start, Start + NumDecls); |
| 899 | } |
| 900 | }; |
| 901 | |
| 902 | } // end anonymous namespace |
| 903 | |
| 904 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 905 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 906 | ASTDeclContextNameLookupTable; |
| 907 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 908 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 909 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 910 | DeclContextInfo &Info) { |
| 911 | SavedStreamPosition SavedPosition(Cursor); |
| 912 | // First the lexical decls. |
| 913 | if (Offsets.first != 0) { |
| 914 | Cursor.JumpToBit(Offsets.first); |
| 915 | |
| 916 | RecordData Record; |
| 917 | const char *Blob; |
| 918 | unsigned BlobLen; |
| 919 | unsigned Code = Cursor.ReadCode(); |
| 920 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 921 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 922 | Error("Expected lexical block"); |
| 923 | return true; |
| 924 | } |
| 925 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 926 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 927 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 928 | } else { |
| 929 | Info.LexicalDecls = 0; |
| 930 | Info.NumLexicalDecls = 0; |
| 931 | } |
| 932 | |
| 933 | // Now the lookup table. |
| 934 | if (Offsets.second != 0) { |
| 935 | Cursor.JumpToBit(Offsets.second); |
| 936 | |
| 937 | RecordData Record; |
| 938 | const char *Blob; |
| 939 | unsigned BlobLen; |
| 940 | unsigned Code = Cursor.ReadCode(); |
| 941 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 942 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 943 | Error("Expected visible lookup table block"); |
| 944 | return true; |
| 945 | } |
| 946 | Info.NameLookupTableData |
| 947 | = ASTDeclContextNameLookupTable::Create( |
| 948 | (const unsigned char *)Blob + Record[0], |
| 949 | (const unsigned char *)Blob, |
| 950 | ASTDeclContextNameLookupTrait(*this)); |
Sebastian Redl | 0ea8f7f | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 951 | } else { |
| 952 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | return false; |
| 956 | } |
| 957 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 958 | void ASTReader::Error(const char *Msg) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 959 | Diag(diag::err_fe_pch_malformed) << Msg; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 962 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 963 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 964 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 965 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 966 | ActualOriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 967 | SuggestedPredefines, |
| 968 | FileMgr); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 969 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 972 | //===----------------------------------------------------------------------===// |
| 973 | // Source Manager Deserialization |
| 974 | //===----------------------------------------------------------------------===// |
| 975 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 976 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 977 | /// \returns true if there was an error. |
| 978 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 979 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 980 | unsigned Idx = 0; |
| 981 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 982 | |
| 983 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 984 | std::map<int, int> FileIDs; |
| 985 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 986 | // Extract the file name |
| 987 | unsigned FilenameLen = Record[Idx++]; |
| 988 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 989 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 990 | MaybeAddSystemRootToFilename(Filename); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 992 | Filename.size()); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | // Parse the line entries |
| 996 | std::vector<LineEntry> Entries; |
| 997 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 998 | int FID = Record[Idx++]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 999 | |
| 1000 | // Extract the line entries |
| 1001 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1002 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1003 | Entries.clear(); |
| 1004 | Entries.reserve(NumEntries); |
| 1005 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1006 | unsigned FileOffset = Record[Idx++]; |
| 1007 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1008 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1009 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1010 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1011 | unsigned IncludeOffset = Record[Idx++]; |
| 1012 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1013 | FileKind, IncludeOffset)); |
| 1014 | } |
| 1015 | LineTable.AddEntry(FID, Entries); |
| 1016 | } |
| 1017 | |
| 1018 | return false; |
| 1019 | } |
| 1020 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1021 | namespace { |
| 1022 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1023 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1024 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1025 | const ino_t ino; |
| 1026 | const dev_t dev; |
| 1027 | const mode_t mode; |
| 1028 | const time_t mtime; |
| 1029 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1030 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1031 | 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] | 1032 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1033 | }; |
| 1034 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1035 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1036 | public: |
| 1037 | typedef const char *external_key_type; |
| 1038 | typedef const char *internal_key_type; |
| 1039 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1040 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1041 | |
| 1042 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1043 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1047 | |
| 1048 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1049 | return strcmp(a, b) == 0; |
| 1050 | } |
| 1051 | |
| 1052 | static std::pair<unsigned, unsigned> |
| 1053 | ReadKeyDataLength(const unsigned char*& d) { |
| 1054 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1055 | unsigned DataLen = (unsigned) *d++; |
| 1056 | return std::make_pair(KeyLen + 1, DataLen); |
| 1057 | } |
| 1058 | |
| 1059 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1060 | return (const char *)d; |
| 1061 | } |
| 1062 | |
| 1063 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1064 | unsigned /*DataLen*/) { |
| 1065 | using namespace clang::io; |
| 1066 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1067 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1068 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1069 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1070 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1071 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1072 | return data_type(ino, dev, mode, mtime, size); |
| 1073 | } |
| 1074 | }; |
| 1075 | |
| 1076 | /// \brief stat() cache for precompiled headers. |
| 1077 | /// |
| 1078 | /// This cache is very similar to the stat cache used by pretokenized |
| 1079 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1080 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1081 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1082 | CacheTy *Cache; |
| 1083 | |
| 1084 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1085 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1086 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1087 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1088 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1089 | Cache = CacheTy::Create(Buckets, Base); |
| 1090 | } |
| 1091 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1092 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1093 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1094 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1095 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1096 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1097 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1098 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1099 | // 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] | 1100 | if (I == Cache->end()) { |
| 1101 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1102 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1103 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1104 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1105 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1106 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1107 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1108 | StatBuf.st_ino = Data.ino; |
| 1109 | StatBuf.st_dev = Data.dev; |
| 1110 | StatBuf.st_mtime = Data.mtime; |
| 1111 | StatBuf.st_mode = Data.mode; |
| 1112 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1113 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1114 | } |
| 1115 | }; |
| 1116 | } // end anonymous namespace |
| 1117 | |
| 1118 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1119 | /// \brief Read a source manager block |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1120 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1121 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1122 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1123 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1124 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1125 | // Set the source-location entry cursor to the current position in |
| 1126 | // the stream. This cursor will be used to read the contents of the |
| 1127 | // source manager block initially, and then lazily read |
| 1128 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1129 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1130 | |
| 1131 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1132 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1133 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1134 | return Failure; |
| 1135 | } |
| 1136 | |
| 1137 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1138 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1139 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1140 | return Failure; |
| 1141 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1142 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1143 | RecordData Record; |
| 1144 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1145 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1146 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1147 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1148 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1149 | return Failure; |
| 1150 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1151 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1152 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1153 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1154 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1155 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1156 | SLocEntryCursor.ReadSubBlockID(); |
| 1157 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1158 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1159 | return Failure; |
| 1160 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1161 | continue; |
| 1162 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1163 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1164 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1165 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1166 | continue; |
| 1167 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1168 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1169 | // Read a record. |
| 1170 | const char *BlobStart; |
| 1171 | unsigned BlobLen; |
| 1172 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1173 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1174 | default: // Default behavior: ignore. |
| 1175 | break; |
| 1176 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1177 | case SM_LINE_TABLE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1178 | if (ParseLineTable(F, Record)) |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1179 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1180 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1181 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1182 | case SM_SLOC_FILE_ENTRY: |
| 1183 | case SM_SLOC_BUFFER_ENTRY: |
| 1184 | case SM_SLOC_INSTANTIATION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1185 | // Once we hit one of the source location entries, we're done. |
| 1186 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1187 | } |
| 1188 | } |
| 1189 | } |
| 1190 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1191 | /// \brief If a header file is not found at the path that we expect it to be |
| 1192 | /// and the PCH file was moved from its original location, try to resolve the |
| 1193 | /// file by assuming that header+PCH were moved together and the header is in |
| 1194 | /// the same place relative to the PCH. |
| 1195 | static std::string |
| 1196 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1197 | const std::string &OriginalDir, |
| 1198 | const std::string &CurrDir) { |
| 1199 | assert(OriginalDir != CurrDir && |
| 1200 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1201 | using namespace llvm::sys; |
| 1202 | llvm::SmallString<128> filePath(Filename); |
| 1203 | fs::make_absolute(filePath); |
| 1204 | assert(path::is_absolute(OriginalDir)); |
| 1205 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1206 | |
| 1207 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1208 | fileDirE = path::end(path::parent_path(filePath)); |
| 1209 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1210 | origDirE = path::end(OriginalDir); |
| 1211 | // Skip the common path components from filePath and OriginalDir. |
| 1212 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1213 | *fileDirI == *origDirI) { |
| 1214 | ++fileDirI; |
| 1215 | ++origDirI; |
| 1216 | } |
| 1217 | for (; origDirI != origDirE; ++origDirI) |
| 1218 | path::append(currPCHPath, ".."); |
| 1219 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1220 | path::append(currPCHPath, path::filename(Filename)); |
| 1221 | return currPCHPath.str(); |
| 1222 | } |
| 1223 | |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1224 | /// \brief Get a cursor that's correctly positioned for reading the source |
| 1225 | /// location entry with the given ID. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1226 | ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1227 | assert(ID != 0 && ID <= TotalNumSLocEntries && |
| 1228 | "SLocCursorForID should only be called for real IDs."); |
| 1229 | |
| 1230 | ID -= 1; |
| 1231 | PerFileData *F = 0; |
| 1232 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1233 | F = Chain[N - I - 1]; |
| 1234 | if (ID < F->LocalNumSLocEntries) |
| 1235 | break; |
| 1236 | ID -= F->LocalNumSLocEntries; |
| 1237 | } |
| 1238 | assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); |
| 1239 | |
| 1240 | F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1241 | return F; |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1244 | /// \brief Read in the source location entry with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1245 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1246 | if (ID == 0) |
| 1247 | return Success; |
| 1248 | |
| 1249 | if (ID > TotalNumSLocEntries) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1250 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1251 | return Failure; |
| 1252 | } |
| 1253 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1254 | PerFileData *F = SLocCursorForID(ID); |
| 1255 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1256 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1257 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1258 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1259 | if (Code == llvm::bitc::END_BLOCK || |
| 1260 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1261 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1262 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1263 | return Failure; |
| 1264 | } |
| 1265 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1266 | RecordData Record; |
| 1267 | const char *BlobStart; |
| 1268 | unsigned BlobLen; |
| 1269 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1270 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1271 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1272 | return Failure; |
| 1273 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1274 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1275 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1276 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1277 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1278 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1279 | OriginalDir != CurrentDir) { |
| 1280 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1281 | OriginalDir, |
| 1282 | CurrentDir); |
| 1283 | if (!resolved.empty()) |
| 1284 | File = FileMgr.getFile(resolved); |
| 1285 | } |
Axel Naumann | 0433116 | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1286 | if (File == 0) |
| 1287 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1288 | (time_t)Record[5]); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1289 | if (File == 0) { |
| 1290 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1291 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1292 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1293 | Error(ErrorStr.c_str()); |
| 1294 | return Failure; |
| 1295 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1296 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1297 | if (Record.size() < 6) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1298 | Error("source location entry is incorrect"); |
| 1299 | return Failure; |
| 1300 | } |
| 1301 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1302 | if (!DisableValidation && |
| 1303 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1304 | #if !defined(LLVM_ON_WIN32) |
| 1305 | // In our regression testing, the Windows file system seems to |
| 1306 | // have inconsistent modification times that sometimes |
| 1307 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1308 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1309 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1310 | )) { |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1311 | Diag(diag::err_fe_pch_file_modified) |
| 1312 | << Filename; |
| 1313 | return Failure; |
| 1314 | } |
| 1315 | |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1316 | FileID FID = SourceMgr.createFileID(File, ReadSourceLocation(*F, Record[1]), |
| 1317 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1318 | ID, Record[0]); |
| 1319 | if (Record[3]) |
| 1320 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1321 | .setHasLineDirectives(); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1322 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1323 | break; |
| 1324 | } |
| 1325 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1326 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1327 | const char *Name = BlobStart; |
| 1328 | unsigned Offset = Record[0]; |
| 1329 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1330 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1331 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1332 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1333 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1334 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1335 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1336 | return Failure; |
| 1337 | } |
| 1338 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1339 | llvm::MemoryBuffer *Buffer |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1340 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1341 | Name); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1342 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1343 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1344 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1345 | PCHPredefinesBlock Block = { |
| 1346 | BufferID, |
| 1347 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1348 | }; |
| 1349 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1350 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1351 | |
| 1352 | break; |
| 1353 | } |
| 1354 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1355 | case SM_SLOC_INSTANTIATION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1356 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1357 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1358 | ReadSourceLocation(*F, Record[2]), |
| 1359 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1360 | Record[4], |
| 1361 | ID, |
| 1362 | Record[0]); |
| 1363 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1364 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | return Success; |
| 1368 | } |
| 1369 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1370 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1371 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1372 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1373 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1374 | unsigned BlockID) { |
| 1375 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1376 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1377 | return Failure; |
| 1378 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1379 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1380 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1381 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1382 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1383 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1384 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1385 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1386 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1387 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1388 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1389 | Cursor.ReadAbbrevRecord(); |
| 1390 | } |
| 1391 | } |
| 1392 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1393 | PreprocessedEntity *ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1394 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1395 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1396 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1397 | // Keep track of where we are in the stream, then jump back there |
| 1398 | // after reading this macro. |
| 1399 | SavedStreamPosition SavedPosition(Stream); |
| 1400 | |
| 1401 | Stream.JumpToBit(Offset); |
| 1402 | RecordData Record; |
| 1403 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1404 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1405 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1406 | while (true) { |
| 1407 | unsigned Code = Stream.ReadCode(); |
| 1408 | switch (Code) { |
| 1409 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1410 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1411 | |
| 1412 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1413 | // No known subblocks, always skip them. |
| 1414 | Stream.ReadSubBlockID(); |
| 1415 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1416 | Error("malformed block record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1417 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1418 | } |
| 1419 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1420 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1421 | case llvm::bitc::DEFINE_ABBREV: |
| 1422 | Stream.ReadAbbrevRecord(); |
| 1423 | continue; |
| 1424 | default: break; |
| 1425 | } |
| 1426 | |
| 1427 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1428 | const char *BlobStart = 0; |
| 1429 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1430 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1431 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1432 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1433 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1434 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1435 | case PP_MACRO_OBJECT_LIKE: |
| 1436 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1437 | // If we already have a macro, that means that we've hit the end |
| 1438 | // of the definition of the macro we were looking for. We're |
| 1439 | // done. |
| 1440 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1441 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1442 | |
| 1443 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1444 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1445 | Error("macro must have a name in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1446 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1447 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1448 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1449 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1450 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1451 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1452 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1453 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1454 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1455 | unsigned NextIndex = 3; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1456 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1457 | // Decode function-like macro info. |
| 1458 | bool isC99VarArgs = Record[3]; |
| 1459 | bool isGNUVarArgs = Record[4]; |
| 1460 | MacroArgs.clear(); |
| 1461 | unsigned NumArgs = Record[5]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1462 | NextIndex = 6 + NumArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1463 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1464 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1465 | |
| 1466 | // Install function-like macro info. |
| 1467 | MI->setIsFunctionLike(); |
| 1468 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1469 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1470 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1471 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1475 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1476 | |
| 1477 | // Remember that we saw this macro last so that we add the tokens that |
| 1478 | // form its body to it. |
| 1479 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1480 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1481 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1482 | // We have a macro definition. Load it now. |
| 1483 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1484 | getMacroDefinition(Record[NextIndex])); |
| 1485 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1486 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1487 | ++NumMacrosRead; |
| 1488 | break; |
| 1489 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1490 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1491 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1492 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1493 | // erroneous, just pretend we didn't see this. |
| 1494 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1495 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1496 | Token Tok; |
| 1497 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1498 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1499 | Tok.setLength(Record[1]); |
| 1500 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1501 | Tok.setIdentifierInfo(II); |
| 1502 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1503 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1504 | Macro->AddTokenToBody(Tok); |
| 1505 | break; |
| 1506 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1507 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1508 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1509 | |
| 1510 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1513 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(PerFileData &F) { |
| 1514 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1515 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1516 | switch (Code) { |
| 1517 | case llvm::bitc::END_BLOCK: |
| 1518 | return 0; |
| 1519 | |
| 1520 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1521 | Error("unexpected subblock record in preprocessor detail block"); |
| 1522 | return 0; |
| 1523 | |
| 1524 | case llvm::bitc::DEFINE_ABBREV: |
| 1525 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1526 | return 0; |
| 1527 | |
| 1528 | default: |
| 1529 | break; |
| 1530 | } |
| 1531 | |
| 1532 | if (!PP->getPreprocessingRecord()) { |
| 1533 | Error("no preprocessing record"); |
| 1534 | return 0; |
| 1535 | } |
| 1536 | |
| 1537 | // Read the record. |
| 1538 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1539 | const char *BlobStart = 0; |
| 1540 | unsigned BlobLen = 0; |
| 1541 | RecordData Record; |
| 1542 | PreprocessorDetailRecordTypes RecType = |
| 1543 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1544 | Code, Record, BlobStart, BlobLen); |
| 1545 | switch (RecType) { |
| 1546 | case PPD_MACRO_INSTANTIATION: { |
| 1547 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1548 | return PE; |
| 1549 | |
| 1550 | MacroInstantiation *MI |
| 1551 | = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), |
| 1552 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1553 | ReadSourceLocation(F, Record[2])), |
| 1554 | getMacroDefinition(Record[4])); |
| 1555 | PPRec.SetPreallocatedEntity(Record[0], MI); |
| 1556 | return MI; |
| 1557 | } |
| 1558 | |
| 1559 | case PPD_MACRO_DEFINITION: { |
| 1560 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1561 | return PE; |
| 1562 | |
| 1563 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
| 1564 | Error("out-of-bounds macro definition record"); |
| 1565 | return 0; |
| 1566 | } |
| 1567 | |
| 1568 | // Decode the identifier info and then check again; if the macro is |
| 1569 | // still defined and associated with the identifier, |
| 1570 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1571 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1572 | MacroDefinition *MD |
| 1573 | = new (PPRec) MacroDefinition(II, |
| 1574 | ReadSourceLocation(F, Record[5]), |
| 1575 | SourceRange( |
| 1576 | ReadSourceLocation(F, Record[2]), |
| 1577 | ReadSourceLocation(F, Record[3]))); |
| 1578 | |
| 1579 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1580 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
| 1581 | |
| 1582 | if (DeserializationListener) |
| 1583 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1584 | } |
| 1585 | |
| 1586 | return MacroDefinitionsLoaded[Record[1] - 1]; |
| 1587 | } |
| 1588 | |
| 1589 | case PPD_INCLUSION_DIRECTIVE: { |
| 1590 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1591 | return PE; |
| 1592 | |
| 1593 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1594 | const FileEntry *File |
| 1595 | = PP->getFileManager().getFile(llvm::StringRef(FullFileNameStart, |
| 1596 | BlobLen - Record[3])); |
| 1597 | |
| 1598 | // FIXME: Stable encoding |
| 1599 | InclusionDirective::InclusionKind Kind |
| 1600 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1601 | InclusionDirective *ID |
| 1602 | = new (PPRec) InclusionDirective(PPRec, Kind, |
| 1603 | llvm::StringRef(BlobStart, Record[3]), |
| 1604 | Record[4], |
| 1605 | File, |
| 1606 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1607 | ReadSourceLocation(F, Record[2]))); |
| 1608 | PPRec.SetPreallocatedEntity(Record[0], ID); |
| 1609 | return ID; |
| 1610 | } |
| 1611 | } |
| 1612 | |
| 1613 | Error("invalid offset in preprocessor detail block"); |
| 1614 | return 0; |
| 1615 | } |
| 1616 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1617 | namespace { |
| 1618 | /// \brief Trait class used to search the on-disk hash table containing all of |
| 1619 | /// the header search information. |
| 1620 | /// |
| 1621 | /// The on-disk hash table contains a mapping from each header path to |
| 1622 | /// information about that header (how many times it has been included, its |
| 1623 | /// controlling macro, etc.). Note that we actually hash based on the |
| 1624 | /// filename, and support "deep" comparisons of file names based on current |
| 1625 | /// inode numbers, so that the search can cope with non-normalized path names |
| 1626 | /// and symlinks. |
| 1627 | class HeaderFileInfoTrait { |
| 1628 | const char *SearchPath; |
| 1629 | struct stat SearchPathStatBuf; |
| 1630 | llvm::Optional<int> SearchPathStatResult; |
| 1631 | |
| 1632 | int StatSimpleCache(const char *Path, struct stat *StatBuf) { |
| 1633 | if (Path == SearchPath) { |
| 1634 | if (!SearchPathStatResult) |
| 1635 | SearchPathStatResult = stat(Path, &SearchPathStatBuf); |
| 1636 | |
| 1637 | *StatBuf = SearchPathStatBuf; |
| 1638 | return *SearchPathStatResult; |
| 1639 | } |
| 1640 | |
| 1641 | return stat(Path, StatBuf); |
| 1642 | } |
| 1643 | |
| 1644 | public: |
| 1645 | typedef const char *external_key_type; |
| 1646 | typedef const char *internal_key_type; |
| 1647 | |
| 1648 | typedef HeaderFileInfo data_type; |
| 1649 | |
| 1650 | HeaderFileInfoTrait(const char *SearchPath = 0) : SearchPath(SearchPath) { } |
| 1651 | |
| 1652 | static unsigned ComputeHash(const char *path) { |
| 1653 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1654 | } |
| 1655 | |
| 1656 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1657 | |
| 1658 | bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1659 | if (strcmp(a, b) == 0) |
| 1660 | return true; |
| 1661 | |
| 1662 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1663 | return false; |
| 1664 | |
| 1665 | // The file names match, but the path names don't. stat() the files to |
| 1666 | // see if they are the same. |
| 1667 | struct stat StatBufA, StatBufB; |
| 1668 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1669 | return false; |
| 1670 | |
| 1671 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1672 | } |
| 1673 | |
| 1674 | static std::pair<unsigned, unsigned> |
| 1675 | ReadKeyDataLength(const unsigned char*& d) { |
| 1676 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1677 | unsigned DataLen = (unsigned) *d++; |
| 1678 | return std::make_pair(KeyLen + 1, DataLen); |
| 1679 | } |
| 1680 | |
| 1681 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1682 | return (const char *)d; |
| 1683 | } |
| 1684 | |
| 1685 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1686 | unsigned DataLen) { |
| 1687 | const unsigned char *End = d + DataLen; |
| 1688 | using namespace clang::io; |
| 1689 | HeaderFileInfo HFI; |
| 1690 | unsigned Flags = *d++; |
| 1691 | HFI.isImport = (Flags >> 3) & 0x01; |
| 1692 | HFI.DirInfo = (Flags >> 1) & 0x03; |
| 1693 | HFI.Resolved = Flags & 0x01; |
| 1694 | HFI.NumIncludes = ReadUnalignedLE16(d); |
| 1695 | HFI.ControllingMacroID = ReadUnalignedLE32(d); |
| 1696 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1697 | (void)End; |
| 1698 | |
| 1699 | // This HeaderFileInfo was externally loaded. |
| 1700 | HFI.External = true; |
| 1701 | return HFI; |
| 1702 | } |
| 1703 | }; |
| 1704 | } |
| 1705 | |
| 1706 | /// \brief The on-disk hash table used for the global method pool. |
| 1707 | typedef OnDiskChainedHashTable<HeaderFileInfoTrait> |
| 1708 | HeaderFileInfoLookupTable; |
| 1709 | |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1710 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F, |
| 1711 | uint64_t Offset) { |
| 1712 | // Note that this identifier has a macro definition. |
| 1713 | II->setHasMacroDefinition(true); |
| 1714 | |
| 1715 | // Adjust the offset based on our position in the chain. |
| 1716 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1717 | if (Chain[I] == &F) |
| 1718 | break; |
| 1719 | |
| 1720 | Offset += Chain[I]->SizeInBits; |
| 1721 | } |
| 1722 | |
| 1723 | UnreadMacroRecordOffsets[II] = Offset; |
| 1724 | } |
| 1725 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1726 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1727 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1728 | PerFileData &F = *Chain[N - I - 1]; |
| 1729 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1730 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1731 | // If there was no preprocessor block, skip this file. |
| 1732 | if (!MacroCursor.getBitStreamReader()) |
| 1733 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1734 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1735 | llvm::BitstreamCursor Cursor = MacroCursor; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1736 | Cursor.JumpToBit(F.MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1737 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1738 | RecordData Record; |
| 1739 | while (true) { |
| 1740 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1741 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1742 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1743 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1744 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1745 | // No known subblocks, always skip them. |
| 1746 | Cursor.ReadSubBlockID(); |
| 1747 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1748 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1749 | return; |
| 1750 | } |
| 1751 | continue; |
| 1752 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1753 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1754 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1755 | Cursor.ReadAbbrevRecord(); |
| 1756 | continue; |
| 1757 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1758 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1759 | // Read a record. |
| 1760 | const char *BlobStart; |
| 1761 | unsigned BlobLen; |
| 1762 | Record.clear(); |
| 1763 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1764 | default: // Default behavior: ignore. |
| 1765 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1766 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1767 | case PP_MACRO_OBJECT_LIKE: |
| 1768 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1769 | DecodeIdentifierInfo(Record[0]); |
| 1770 | break; |
| 1771 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1772 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1773 | // Ignore tokens. |
| 1774 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1775 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1776 | } |
| 1777 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1778 | |
| 1779 | // Drain the unread macro-record offsets map. |
| 1780 | while (!UnreadMacroRecordOffsets.empty()) |
| 1781 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1782 | } |
| 1783 | |
| 1784 | void ASTReader::LoadMacroDefinition( |
| 1785 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1786 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
| 1787 | PerFileData *F = 0; |
| 1788 | uint64_t Offset = Pos->second; |
| 1789 | UnreadMacroRecordOffsets.erase(Pos); |
| 1790 | |
| 1791 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1792 | if (Offset < Chain[I]->SizeInBits) { |
| 1793 | F = Chain[I]; |
| 1794 | break; |
| 1795 | } |
| 1796 | |
| 1797 | Offset -= Chain[I]->SizeInBits; |
| 1798 | } |
| 1799 | if (!F) { |
| 1800 | Error("Malformed macro record offset"); |
| 1801 | return; |
| 1802 | } |
| 1803 | |
| 1804 | ReadMacroRecord(*F, Offset); |
| 1805 | } |
| 1806 | |
| 1807 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1808 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1809 | = UnreadMacroRecordOffsets.find(II); |
| 1810 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1813 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1814 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1815 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1816 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1817 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1818 | unsigned Index = ID - 1; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1819 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1820 | PerFileData &F = *Chain[N - I - 1]; |
| 1821 | if (Index < F.LocalNumMacroDefinitions) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1822 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 1823 | F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]); |
| 1824 | LoadPreprocessedEntity(F); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1825 | break; |
| 1826 | } |
| 1827 | Index -= F.LocalNumMacroDefinitions; |
| 1828 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1829 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1832 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1835 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1836 | /// not an absolute path, add the system root to the beginning of the file |
| 1837 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1838 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1839 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1840 | if (!RelocatablePCH) |
| 1841 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1842 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1843 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1844 | return; |
| 1845 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1846 | if (isysroot == 0) { |
| 1847 | // If no system root was given, default to '/' |
| 1848 | Filename.insert(Filename.begin(), '/'); |
| 1849 | return; |
| 1850 | } |
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 | unsigned Length = strlen(isysroot); |
| 1853 | if (isysroot[Length - 1] != '/') |
| 1854 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1855 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1856 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1857 | } |
| 1858 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1859 | ASTReader::ASTReadResult |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1860 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1861 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1862 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1863 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1864 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1865 | return Failure; |
| 1866 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1867 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1868 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1869 | RecordData Record; |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1870 | bool First = true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1871 | while (!Stream.AtEndOfStream()) { |
| 1872 | unsigned Code = Stream.ReadCode(); |
| 1873 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1874 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1875 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1876 | return Failure; |
| 1877 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1878 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1879 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1883 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1884 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1885 | // We lazily load the decls block, but we want to set up the |
| 1886 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1887 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1888 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1889 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1890 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1891 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1892 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1893 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1894 | return Failure; |
| 1895 | } |
| 1896 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1897 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1898 | case DECL_UPDATES_BLOCK_ID: |
| 1899 | if (Stream.SkipBlock()) { |
| 1900 | Error("malformed block record in AST file"); |
| 1901 | return Failure; |
| 1902 | } |
| 1903 | break; |
| 1904 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1905 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1906 | F.MacroCursor = Stream; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1907 | if (PP) |
| 1908 | PP->setExternalSource(this); |
| 1909 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1910 | if (Stream.SkipBlock() || |
| 1911 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1912 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1913 | return Failure; |
| 1914 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1915 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1916 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1917 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1918 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1919 | F.PreprocessorDetailCursor = Stream; |
| 1920 | if (Stream.SkipBlock() || |
| 1921 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1922 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1923 | Error("malformed preprocessor detail record in AST file"); |
| 1924 | return Failure; |
| 1925 | } |
| 1926 | F.PreprocessorDetailStartOffset |
| 1927 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 1928 | break; |
| 1929 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1930 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1931 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1932 | case Success: |
| 1933 | break; |
| 1934 | |
| 1935 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1936 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1937 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1938 | |
| 1939 | case IgnorePCH: |
| 1940 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1941 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1942 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1943 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1944 | First = false; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1945 | continue; |
| 1946 | } |
| 1947 | |
| 1948 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1949 | Stream.ReadAbbrevRecord(); |
| 1950 | continue; |
| 1951 | } |
| 1952 | |
| 1953 | // Read and process a record. |
| 1954 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1955 | const char *BlobStart = 0; |
| 1956 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1957 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1958 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1959 | default: // Default behavior: ignore. |
| 1960 | break; |
| 1961 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1962 | case METADATA: { |
| 1963 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1964 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1965 | : diag::warn_pch_version_too_new); |
| 1966 | return IgnorePCH; |
| 1967 | } |
| 1968 | |
| 1969 | RelocatablePCH = Record[4]; |
| 1970 | if (Listener) { |
| 1971 | std::string TargetTriple(BlobStart, BlobLen); |
| 1972 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1973 | return IgnorePCH; |
| 1974 | } |
| 1975 | break; |
| 1976 | } |
| 1977 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1978 | case CHAINED_METADATA: { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1979 | if (!First) { |
| 1980 | Error("CHAINED_METADATA is not first record in block"); |
| 1981 | return Failure; |
| 1982 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1983 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1984 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1985 | : diag::warn_pch_version_too_new); |
| 1986 | return IgnorePCH; |
| 1987 | } |
| 1988 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 1989 | // Load the chained file, which is always a PCH file. |
| 1990 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1991 | case Failure: return Failure; |
| 1992 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1993 | case IgnorePCH: return IgnorePCH; |
| 1994 | case Success: break; |
| 1995 | } |
| 1996 | break; |
| 1997 | } |
| 1998 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1999 | case TYPE_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2000 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2001 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2002 | return Failure; |
| 2003 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2004 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 2005 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2006 | break; |
| 2007 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2008 | case DECL_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2009 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2010 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2011 | return Failure; |
| 2012 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2013 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 2014 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2015 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2016 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2017 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2018 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2019 | /* No visible information */ 0, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2020 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 2021 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2022 | }; |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2023 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 2024 | .push_back(Info); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2025 | break; |
| 2026 | } |
| 2027 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2028 | case UPDATE_VISIBLE: { |
| 2029 | serialization::DeclID ID = Record[0]; |
| 2030 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 2031 | (const unsigned char *)BlobStart + Record[1], |
| 2032 | (const unsigned char *)BlobStart, |
| 2033 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2034 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2035 | DeclContextInfo Info = { |
| 2036 | Table, /* No lexical inforamtion */ 0, 0 |
| 2037 | }; |
| 2038 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 2039 | } else |
| 2040 | PendingVisibleUpdates[ID].push_back(Table); |
| 2041 | break; |
| 2042 | } |
| 2043 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2044 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2045 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 2046 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2047 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2048 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 2049 | Latest > FirstLatestDeclIDs[First]) && |
| 2050 | "The new latest is supposed to come after the previous latest"); |
| 2051 | FirstLatestDeclIDs[First] = Latest; |
| 2052 | } |
| 2053 | break; |
| 2054 | } |
| 2055 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2056 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2057 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2058 | return IgnorePCH; |
| 2059 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2060 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2061 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2062 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2063 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2064 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2065 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2066 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2067 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2068 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2069 | if (PP) |
| 2070 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2071 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2072 | break; |
| 2073 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2074 | case IDENTIFIER_OFFSET: |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2075 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2076 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2077 | return Failure; |
| 2078 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2079 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2080 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2081 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2082 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2083 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2084 | // Optimization for the first block. |
| 2085 | if (ExternalDefinitions.empty()) |
| 2086 | ExternalDefinitions.swap(Record); |
| 2087 | else |
| 2088 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 2089 | Record.begin(), Record.end()); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2090 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2091 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2092 | case SPECIAL_TYPES: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2093 | // Optimization for the first block |
| 2094 | if (SpecialTypes.empty()) |
| 2095 | SpecialTypes.swap(Record); |
| 2096 | else |
| 2097 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2098 | break; |
| 2099 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2100 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2101 | TotalNumStatements += Record[0]; |
| 2102 | TotalNumMacros += Record[1]; |
| 2103 | TotalLexicalDeclContexts += Record[2]; |
| 2104 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2105 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2106 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2107 | case TENTATIVE_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2108 | // Optimization for the first block. |
| 2109 | if (TentativeDefinitions.empty()) |
| 2110 | TentativeDefinitions.swap(Record); |
| 2111 | else |
| 2112 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 2113 | Record.begin(), Record.end()); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2114 | break; |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2115 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2116 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2117 | // Optimization for the first block. |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2118 | if (UnusedFileScopedDecls.empty()) |
| 2119 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2120 | else |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2121 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 2122 | Record.begin(), Record.end()); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2123 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2124 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2125 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2126 | // Later blocks overwrite earlier ones. |
| 2127 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2128 | break; |
| 2129 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2130 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2131 | // Optimization for the first block. |
| 2132 | if (LocallyScopedExternalDecls.empty()) |
| 2133 | LocallyScopedExternalDecls.swap(Record); |
| 2134 | else |
| 2135 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 2136 | Record.begin(), Record.end()); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2137 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2138 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2139 | case SELECTOR_OFFSETS: |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2140 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2141 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2142 | break; |
| 2143 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2144 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2145 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2146 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2147 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2148 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2149 | F.SelectorLookupTableData + Record[0], |
| 2150 | F.SelectorLookupTableData, |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2151 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2152 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2153 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2154 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2155 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2156 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2157 | break; |
| 2158 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2159 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2160 | if (!Record.empty() && Listener) |
| 2161 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2162 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2163 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2164 | case SOURCE_LOCATION_OFFSETS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2165 | F.SLocOffsets = (const uint32_t *)BlobStart; |
| 2166 | F.LocalNumSLocEntries = Record[0]; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2167 | F.LocalSLocSize = Record[1]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2168 | break; |
| 2169 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2170 | case SOURCE_LOCATION_PRELOADS: |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2171 | if (PreloadSLocEntries.empty()) |
| 2172 | PreloadSLocEntries.swap(Record); |
| 2173 | else |
| 2174 | PreloadSLocEntries.insert(PreloadSLocEntries.end(), |
| 2175 | Record.begin(), Record.end()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2176 | break; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2177 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2178 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2179 | if (!DisableStatCache) { |
| 2180 | ASTStatCache *MyStatCache = |
| 2181 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2182 | (const unsigned char *)BlobStart, |
| 2183 | NumStatHits, NumStatMisses); |
| 2184 | FileMgr.addStatCache(MyStatCache); |
| 2185 | F.StatCache = MyStatCache; |
| 2186 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2187 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2188 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2189 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2190 | case EXT_VECTOR_DECLS: |
Sebastian Redl | a9f2368 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 2191 | // Optimization for the first block. |
| 2192 | if (ExtVectorDecls.empty()) |
| 2193 | ExtVectorDecls.swap(Record); |
| 2194 | else |
| 2195 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 2196 | Record.begin(), Record.end()); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2197 | break; |
| 2198 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2199 | case VTABLE_USES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2200 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2201 | VTableUses.swap(Record); |
| 2202 | break; |
| 2203 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2204 | case DYNAMIC_CLASSES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2205 | // Optimization for the first block. |
| 2206 | if (DynamicClasses.empty()) |
| 2207 | DynamicClasses.swap(Record); |
| 2208 | else |
| 2209 | DynamicClasses.insert(DynamicClasses.end(), |
| 2210 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2211 | break; |
| 2212 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2213 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2214 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2215 | break; |
| 2216 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2217 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2218 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2219 | SemaDeclRefs.swap(Record); |
| 2220 | break; |
| 2221 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2222 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2223 | // 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] | 2224 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2225 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2226 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2227 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2228 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2229 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2230 | case ORIGINAL_PCH_DIR: |
| 2231 | // The primary AST will be the last to get here, so it will be the one |
| 2232 | // that's used. |
| 2233 | OriginalDir.assign(BlobStart, BlobLen); |
| 2234 | break; |
| 2235 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2236 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2237 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2238 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 2239 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2240 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2241 | return IgnorePCH; |
| 2242 | } |
| 2243 | break; |
| 2244 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2245 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2246 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2247 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2248 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2249 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2250 | break; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2251 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2252 | case DECL_UPDATE_OFFSETS: { |
| 2253 | if (Record.size() % 2 != 0) { |
| 2254 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2255 | return Failure; |
| 2256 | } |
| 2257 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
| 2258 | DeclUpdateOffsets[static_cast<DeclID>(Record[I])] |
| 2259 | .push_back(std::make_pair(&F, Record[I+1])); |
| 2260 | break; |
| 2261 | } |
| 2262 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2263 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2264 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2265 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2266 | return Failure; |
| 2267 | } |
| 2268 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2269 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2270 | std::make_pair(&F, Record[I+1]); |
| 2271 | break; |
| 2272 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2273 | |
| 2274 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2275 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2276 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2277 | return Failure; |
| 2278 | } |
| 2279 | |
| 2280 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2281 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
| 2282 | break; |
| 2283 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2284 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2285 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2286 | if (Record.size() % 2 != 0) { |
| 2287 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2288 | return Failure; |
| 2289 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2290 | if (PragmaDiagMappings.empty()) |
| 2291 | PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2292 | else |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2293 | PragmaDiagMappings.insert(PragmaDiagMappings.end(), |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2294 | Record.begin(), Record.end()); |
| 2295 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2296 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2297 | case CUDA_SPECIAL_DECL_REFS: |
| 2298 | // Later tables overwrite earlier ones. |
| 2299 | CUDASpecialDeclRefs.swap(Record); |
| 2300 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2301 | |
| 2302 | case HEADER_SEARCH_TABLE: |
| 2303 | F.HeaderFileInfoTableData = BlobStart; |
| 2304 | F.LocalNumHeaderFileInfos = Record[1]; |
| 2305 | if (Record[0]) { |
| 2306 | F.HeaderFileInfoTable |
| 2307 | = HeaderFileInfoLookupTable::Create( |
| 2308 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 2309 | (const unsigned char *)F.HeaderFileInfoTableData); |
| 2310 | if (PP) |
| 2311 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2312 | } |
| 2313 | break; |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2314 | |
| 2315 | case FP_PRAGMA_OPTIONS: |
| 2316 | // Later tables overwrite earlier ones. |
| 2317 | FPPragmaOptions.swap(Record); |
| 2318 | break; |
| 2319 | |
| 2320 | case OPENCL_EXTENSIONS: |
| 2321 | // Later tables overwrite earlier ones. |
| 2322 | OpenCLExtensions.swap(Record); |
| 2323 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2324 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2325 | First = false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2326 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2327 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2328 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2331 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2332 | ASTFileType Type) { |
| 2333 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2334 | case Failure: return Failure; |
| 2335 | case IgnorePCH: return IgnorePCH; |
| 2336 | case Success: break; |
| 2337 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2338 | |
| 2339 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2340 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2341 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2342 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2343 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2344 | TotalNumSelectors = 0; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2345 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2346 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2347 | NextSLocOffset += Chain[I]->LocalSLocSize; |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2348 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2349 | TotalNumTypes += Chain[I]->LocalNumTypes; |
| 2350 | TotalNumDecls += Chain[I]->LocalNumDecls; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2351 | TotalNumPreallocatedPreprocessingEntities += |
| 2352 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2353 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2354 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2355 | } |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2356 | SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset); |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2357 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2358 | TypesLoaded.resize(TotalNumTypes); |
| 2359 | DeclsLoaded.resize(TotalNumDecls); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2360 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2361 | if (PP) { |
| 2362 | if (TotalNumIdentifiers > 0) |
| 2363 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2364 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2365 | if (!PP->getPreprocessingRecord()) |
| 2366 | PP->createPreprocessingRecord(); |
| 2367 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2368 | TotalNumPreallocatedPreprocessingEntities); |
| 2369 | } |
| 2370 | } |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2371 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2372 | // Preload SLocEntries. |
| 2373 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2374 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2375 | if (Result != Success) |
| 2376 | return Result; |
| 2377 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2378 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2379 | // Check the predefines buffers. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2380 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2381 | return IgnorePCH; |
| 2382 | |
| 2383 | if (PP) { |
| 2384 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2385 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2386 | // loaded into the IdentifierTable before we intercepted the |
| 2387 | // creation of identifiers. Iterate through the list of known |
| 2388 | // identifiers and determine whether we have to establish |
| 2389 | // preprocessor definitions or top-level identifier declaration |
| 2390 | // chains for those identifiers. |
| 2391 | // |
| 2392 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2393 | // since de-serializing declarations or macro definitions can add |
| 2394 | // new entries into the identifier table, invalidating the |
| 2395 | // iterators. |
| 2396 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2397 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2398 | IdEnd = PP->getIdentifierTable().end(); |
| 2399 | Id != IdEnd; ++Id) |
| 2400 | Identifiers.push_back(Id->second); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2401 | // We need to search the tables in all files. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2402 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2403 | ASTIdentifierLookupTable *IdTable |
| 2404 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2405 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2406 | // ones. |
| 2407 | if (!IdTable) |
| 2408 | continue; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2409 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2410 | IdentifierInfo *II = Identifiers[I]; |
| 2411 | // 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] | 2412 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2413 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2414 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2415 | if (Pos == IdTable->end()) |
| 2416 | continue; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2417 | |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2418 | // Dereferencing the iterator has the effect of populating the |
| 2419 | // IdentifierInfo node with the various declarations it needs. |
| 2420 | (void)*Pos; |
| 2421 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2422 | } |
| 2423 | } |
| 2424 | |
| 2425 | if (Context) |
| 2426 | InitializeContext(*Context); |
| 2427 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2428 | if (DeserializationListener) |
| 2429 | DeserializationListener->ReaderInitialized(this); |
| 2430 | |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2431 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2432 | // the source manager to the file source file from which the preamble was |
| 2433 | // built. This is the only valid way to use a precompiled preamble. |
| 2434 | if (Type == Preamble) { |
| 2435 | SourceLocation Loc |
| 2436 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2437 | if (Loc.isValid()) { |
| 2438 | std::pair<FileID, unsigned> Decomposed = SourceMgr.getDecomposedLoc(Loc); |
| 2439 | SourceMgr.SetPreambleFileID(Decomposed.first); |
| 2440 | } |
| 2441 | } |
| 2442 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2443 | return Success; |
| 2444 | } |
| 2445 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2446 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2447 | ASTFileType Type) { |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2448 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2449 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2450 | PerFileData &F = *Chain.back(); |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2451 | if (Prev) |
| 2452 | Prev->NextInSource = &F; |
| 2453 | else |
| 2454 | FirstInSource = &F; |
| 2455 | F.Loaders.push_back(Prev); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2456 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2457 | // Set the AST file name. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2458 | F.FileName = FileName; |
| 2459 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2460 | if (FileName != "-") { |
| 2461 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2462 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2463 | } |
| 2464 | |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 2465 | if (!ASTBuffers.empty()) { |
| 2466 | F.Buffer.reset(ASTBuffers.front()); |
| 2467 | ASTBuffers.pop_front(); |
| 2468 | assert(F.Buffer && "Passed null buffer"); |
| 2469 | } else { |
| 2470 | // Open the AST file. |
| 2471 | // |
| 2472 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2473 | std::string ErrStr; |
| 2474 | llvm::error_code ec; |
| 2475 | if (FileName == "-") { |
| 2476 | ec = llvm::MemoryBuffer::getSTDIN(F.Buffer); |
| 2477 | if (ec) |
| 2478 | ErrStr = ec.message(); |
| 2479 | } else |
| 2480 | F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr)); |
| 2481 | if (!F.Buffer) { |
| 2482 | Error(ErrStr.c_str()); |
| 2483 | return IgnorePCH; |
| 2484 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | // Initialize the stream |
| 2488 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2489 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2490 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2491 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2492 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2493 | |
| 2494 | // Sniff for the signature. |
| 2495 | if (Stream.Read(8) != 'C' || |
| 2496 | Stream.Read(8) != 'P' || |
| 2497 | Stream.Read(8) != 'C' || |
| 2498 | Stream.Read(8) != 'H') { |
| 2499 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2500 | return Failure; |
| 2501 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2502 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2503 | while (!Stream.AtEndOfStream()) { |
| 2504 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2505 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2506 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2507 | Error("invalid record at top-level of 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 | |
| 2511 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2512 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2513 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2514 | switch (BlockID) { |
| 2515 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2516 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2517 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2518 | return Failure; |
| 2519 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2520 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2521 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2522 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2523 | case Success: |
| 2524 | break; |
| 2525 | |
| 2526 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2527 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2528 | |
| 2529 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2530 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2531 | // AST block, skipping subblocks, to see if there are other |
| 2532 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2533 | |
| 2534 | // Clear out any preallocated source location entries, so that |
| 2535 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2536 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2537 | |
| 2538 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2539 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2540 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2541 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2542 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2543 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2544 | break; |
| 2545 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2546 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2547 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2548 | return Failure; |
| 2549 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2550 | break; |
| 2551 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2552 | } |
| 2553 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2554 | return Success; |
| 2555 | } |
| 2556 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2557 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2558 | PP = &pp; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2559 | |
| 2560 | unsigned TotalNum = 0; |
| 2561 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2562 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2563 | if (TotalNum) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2564 | if (!PP->getPreprocessingRecord()) |
| 2565 | PP->createPreprocessingRecord(); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2566 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2567 | } |
| 2568 | } |
| 2569 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2570 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2571 | Context = &Ctx; |
| 2572 | assert(Context && "Passed null context!"); |
| 2573 | |
| 2574 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2575 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2576 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2577 | PP->setExternalSource(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2578 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2579 | |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2580 | // If we have an update block for the TU waiting, we have to add it before |
| 2581 | // deserializing the decl. |
| 2582 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2583 | if (DCU != DeclContextOffsets.end()) { |
| 2584 | // Insertion could invalidate map, so grab vector. |
| 2585 | DeclContextInfos T; |
| 2586 | T.swap(DCU->second); |
| 2587 | DeclContextOffsets.erase(DCU); |
| 2588 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2589 | } |
| 2590 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2591 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2592 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2593 | |
| 2594 | // Load the special types. |
| 2595 | Context->setBuiltinVaListType( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2596 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2597 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2598 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2599 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2600 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2601 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2602 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2603 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2604 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2605 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2606 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2607 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2608 | if (unsigned FastEnum |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2609 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2610 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2611 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2612 | QualType FileType = GetType(File); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2613 | if (FileType.isNull()) { |
| 2614 | Error("FILE type is NULL"); |
| 2615 | return; |
| 2616 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2617 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2618 | Context->setFILEDecl(Typedef->getDecl()); |
| 2619 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2620 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2621 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2622 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2623 | return; |
| 2624 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2625 | Context->setFILEDecl(Tag->getDecl()); |
| 2626 | } |
| 2627 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2628 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2629 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2630 | if (Jmp_bufType.isNull()) { |
| 2631 | Error("jmp_bug type is NULL"); |
| 2632 | return; |
| 2633 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2634 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2635 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2636 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2637 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2638 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2639 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2640 | return; |
| 2641 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2642 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2643 | } |
| 2644 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2645 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2646 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2647 | if (Sigjmp_bufType.isNull()) { |
| 2648 | Error("sigjmp_buf type is NULL"); |
| 2649 | return; |
| 2650 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2651 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2652 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2653 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2654 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2655 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2656 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2657 | } |
| 2658 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2659 | if (unsigned ObjCIdRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2660 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2661 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2662 | if (unsigned ObjCClassRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2663 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2664 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2665 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2666 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2667 | if (unsigned String |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2668 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2669 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2670 | if (unsigned ObjCSelRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2671 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2672 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2673 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2674 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2675 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2676 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2677 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2678 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2679 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2680 | |
| 2681 | // If there were any CUDA special declarations, deserialize them. |
| 2682 | if (!CUDASpecialDeclRefs.empty()) { |
| 2683 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 2684 | Context->setcudaConfigureCallDecl( |
| 2685 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2686 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2687 | } |
| 2688 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2689 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2690 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2691 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2692 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2693 | FileManager &FileMgr, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2694 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2695 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2696 | std::string ErrStr; |
| 2697 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2698 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2699 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2700 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2701 | return std::string(); |
| 2702 | } |
| 2703 | |
| 2704 | // Initialize the stream |
| 2705 | llvm::BitstreamReader StreamFile; |
| 2706 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2707 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2708 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2709 | Stream.init(StreamFile); |
| 2710 | |
| 2711 | // Sniff for the signature. |
| 2712 | if (Stream.Read(8) != 'C' || |
| 2713 | Stream.Read(8) != 'P' || |
| 2714 | Stream.Read(8) != 'C' || |
| 2715 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2716 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2717 | return std::string(); |
| 2718 | } |
| 2719 | |
| 2720 | RecordData Record; |
| 2721 | while (!Stream.AtEndOfStream()) { |
| 2722 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2723 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2724 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2725 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2726 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2727 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2728 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2729 | case AST_BLOCK_ID: |
| 2730 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2731 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2732 | return std::string(); |
| 2733 | } |
| 2734 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2735 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2736 | default: |
| 2737 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2738 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2739 | return std::string(); |
| 2740 | } |
| 2741 | break; |
| 2742 | } |
| 2743 | continue; |
| 2744 | } |
| 2745 | |
| 2746 | if (Code == llvm::bitc::END_BLOCK) { |
| 2747 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2748 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2749 | return std::string(); |
| 2750 | } |
| 2751 | continue; |
| 2752 | } |
| 2753 | |
| 2754 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2755 | Stream.ReadAbbrevRecord(); |
| 2756 | continue; |
| 2757 | } |
| 2758 | |
| 2759 | Record.clear(); |
| 2760 | const char *BlobStart = 0; |
| 2761 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2762 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2763 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2764 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2765 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2766 | |
| 2767 | return std::string(); |
| 2768 | } |
| 2769 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2770 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2771 | /// structure. |
| 2772 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2773 | /// This routine parses the language options from the AST file and then gives |
| 2774 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2775 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2776 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2777 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2778 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2779 | if (Listener) { |
| 2780 | LangOptions LangOpts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2781 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2782 | #define PARSE_LANGOPT(Option) \ |
| 2783 | LangOpts.Option = Record[Idx]; \ |
| 2784 | ++Idx |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2785 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2786 | unsigned Idx = 0; |
| 2787 | PARSE_LANGOPT(Trigraphs); |
| 2788 | PARSE_LANGOPT(BCPLComment); |
| 2789 | PARSE_LANGOPT(DollarIdents); |
| 2790 | PARSE_LANGOPT(AsmPreprocessor); |
| 2791 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2792 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2793 | PARSE_LANGOPT(ImplicitInt); |
| 2794 | PARSE_LANGOPT(Digraphs); |
| 2795 | PARSE_LANGOPT(HexFloats); |
| 2796 | PARSE_LANGOPT(C99); |
| 2797 | PARSE_LANGOPT(Microsoft); |
| 2798 | PARSE_LANGOPT(CPlusPlus); |
| 2799 | PARSE_LANGOPT(CPlusPlus0x); |
| 2800 | PARSE_LANGOPT(CXXOperatorNames); |
| 2801 | PARSE_LANGOPT(ObjC1); |
| 2802 | PARSE_LANGOPT(ObjC2); |
| 2803 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 2804 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 2805 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 2806 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 2807 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2808 | PARSE_LANGOPT(PascalStrings); |
| 2809 | PARSE_LANGOPT(WritableStrings); |
| 2810 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2811 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2812 | PARSE_LANGOPT(Exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 2813 | PARSE_LANGOPT(ObjCExceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 2814 | PARSE_LANGOPT(CXXExceptions); |
| 2815 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 2816 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2817 | PARSE_LANGOPT(NeXTRuntime); |
| 2818 | PARSE_LANGOPT(Freestanding); |
| 2819 | PARSE_LANGOPT(NoBuiltin); |
| 2820 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 2821 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2822 | PARSE_LANGOPT(Blocks); |
| 2823 | PARSE_LANGOPT(EmitAllDecls); |
| 2824 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2825 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 2826 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2827 | PARSE_LANGOPT(HeinousExtensions); |
| 2828 | PARSE_LANGOPT(Optimize); |
| 2829 | PARSE_LANGOPT(OptimizeSize); |
| 2830 | PARSE_LANGOPT(Static); |
| 2831 | PARSE_LANGOPT(PICLevel); |
| 2832 | PARSE_LANGOPT(GNUInline); |
| 2833 | PARSE_LANGOPT(NoInline); |
| 2834 | PARSE_LANGOPT(AccessControl); |
| 2835 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2836 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | b1bdced | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 2837 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2838 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2839 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 2840 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2841 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2842 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2843 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 2844 | PARSE_LANGOPT(CUDA); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2845 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2846 | PARSE_LANGOPT(DefaultFPContract); |
Roman Divacky | 1c51b1c | 2011-03-01 17:36:40 +0000 | [diff] [blame] | 2847 | PARSE_LANGOPT(ElideConstructors); |
| 2848 | PARSE_LANGOPT(SpellChecking); |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 2849 | PARSE_LANGOPT(MRTD); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2850 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2851 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2852 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2853 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2854 | |
| 2855 | return false; |
| 2856 | } |
| 2857 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2858 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2859 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2860 | PerFileData &F = *Chain[I]; |
| 2861 | if (!F.PreprocessorDetailCursor.getBitStreamReader()) |
| 2862 | continue; |
| 2863 | |
| 2864 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 2865 | F.PreprocessorDetailCursor.JumpToBit(F.PreprocessorDetailStartOffset); |
| 2866 | while (LoadPreprocessedEntity(F)) { } |
| 2867 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
Douglas Gregor | 0a48029 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 2870 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2871 | PerFileData *F = 0; |
| 2872 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2873 | if (Offset < Chain[I]->SizeInBits) { |
| 2874 | F = Chain[I]; |
| 2875 | break; |
| 2876 | } |
| 2877 | |
| 2878 | Offset -= Chain[I]->SizeInBits; |
| 2879 | } |
| 2880 | |
| 2881 | if (!F) { |
| 2882 | Error("Malformed preprocessed entity offset"); |
| 2883 | return 0; |
| 2884 | } |
| 2885 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2886 | // Keep track of where we are in the stream, then jump back there |
| 2887 | // after reading this entity. |
| 2888 | SavedStreamPosition SavedPosition(F->PreprocessorDetailCursor); |
| 2889 | F->PreprocessorDetailCursor.JumpToBit(Offset); |
| 2890 | return LoadPreprocessedEntity(*F); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2891 | } |
| 2892 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2893 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
| 2894 | HeaderFileInfoTrait Trait(FE->getName()); |
| 2895 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2896 | PerFileData &F = *Chain[I]; |
| 2897 | HeaderFileInfoLookupTable *Table |
| 2898 | = static_cast<HeaderFileInfoLookupTable *>(F.HeaderFileInfoTable); |
| 2899 | if (!Table) |
| 2900 | continue; |
| 2901 | |
| 2902 | // Look in the on-disk hash table for an entry for this file name. |
| 2903 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE->getName(), |
| 2904 | &Trait); |
| 2905 | if (Pos == Table->end()) |
| 2906 | continue; |
| 2907 | |
| 2908 | HeaderFileInfo HFI = *Pos; |
| 2909 | if (Listener) |
| 2910 | Listener->ReadHeaderFileInfo(HFI, FE->getUID()); |
| 2911 | |
| 2912 | return HFI; |
| 2913 | } |
| 2914 | |
| 2915 | return HeaderFileInfo(); |
| 2916 | } |
| 2917 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2918 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2919 | unsigned Idx = 0; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2920 | while (Idx < PragmaDiagMappings.size()) { |
| 2921 | SourceLocation |
| 2922 | Loc = SourceLocation::getFromRawEncoding(PragmaDiagMappings[Idx++]); |
| 2923 | while (1) { |
| 2924 | assert(Idx < PragmaDiagMappings.size() && |
| 2925 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 2926 | if (Idx >= PragmaDiagMappings.size()) |
| 2927 | break; // Something is messed up but at least avoid infinite loop in |
| 2928 | // release build. |
| 2929 | unsigned DiagID = PragmaDiagMappings[Idx++]; |
| 2930 | if (DiagID == (unsigned)-1) |
| 2931 | break; // no more diag/map pairs for this location. |
| 2932 | diag::Mapping Map = (diag::Mapping)PragmaDiagMappings[Idx++]; |
| 2933 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 2934 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2935 | } |
| 2936 | } |
| 2937 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2938 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2939 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2940 | PerFileData *F = 0; |
| 2941 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2942 | F = Chain[N - I - 1]; |
| 2943 | if (Index < F->LocalNumTypes) |
| 2944 | break; |
| 2945 | Index -= F->LocalNumTypes; |
| 2946 | } |
| 2947 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2948 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2949 | } |
| 2950 | |
| 2951 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2952 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2953 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 2954 | /// routine actually reads the record corresponding to the type at the given |
| 2955 | /// location. It is a helper routine for GetType, which deals with reading type |
| 2956 | /// IDs. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2957 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2958 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2959 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2960 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2961 | // Keep track of where we are in the stream, then jump back there |
| 2962 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2963 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2964 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 2965 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 2966 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2967 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 2968 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2969 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2970 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2971 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2972 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2973 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 2974 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2975 | if (Record.size() != 2) { |
| 2976 | Error("Incorrect encoding of extended qualifier type"); |
| 2977 | return QualType(); |
| 2978 | } |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2979 | QualType Base = GetType(Record[0]); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2980 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 2981 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2982 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2983 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2984 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2985 | if (Record.size() != 1) { |
| 2986 | Error("Incorrect encoding of complex type"); |
| 2987 | return QualType(); |
| 2988 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2989 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2990 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2991 | } |
| 2992 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2993 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2994 | if (Record.size() != 1) { |
| 2995 | Error("Incorrect encoding of pointer type"); |
| 2996 | return QualType(); |
| 2997 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2998 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2999 | return Context->getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3000 | } |
| 3001 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3002 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3003 | if (Record.size() != 1) { |
| 3004 | Error("Incorrect encoding of block pointer type"); |
| 3005 | return QualType(); |
| 3006 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3007 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3008 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3011 | case TYPE_LVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3012 | if (Record.size() != 1) { |
| 3013 | Error("Incorrect encoding of lvalue reference type"); |
| 3014 | return QualType(); |
| 3015 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3016 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3017 | return Context->getLValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3018 | } |
| 3019 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3020 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3021 | if (Record.size() != 1) { |
| 3022 | Error("Incorrect encoding of rvalue reference type"); |
| 3023 | return QualType(); |
| 3024 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3025 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3026 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3029 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3030 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3031 | Error("Incorrect encoding of member pointer type"); |
| 3032 | return QualType(); |
| 3033 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3034 | QualType PointeeType = GetType(Record[0]); |
| 3035 | QualType ClassType = GetType(Record[1]); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3036 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3037 | return QualType(); |
| 3038 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3039 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3040 | } |
| 3041 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3042 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3043 | QualType ElementType = GetType(Record[0]); |
| 3044 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3045 | unsigned IndexTypeQuals = Record[2]; |
| 3046 | unsigned Idx = 3; |
| 3047 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3048 | return Context->getConstantArrayType(ElementType, Size, |
| 3049 | ASM, IndexTypeQuals); |
| 3050 | } |
| 3051 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3052 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3053 | QualType ElementType = GetType(Record[0]); |
| 3054 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3055 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3056 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3057 | } |
| 3058 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3059 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3060 | QualType ElementType = GetType(Record[0]); |
| 3061 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3062 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3063 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3064 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 3065 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3066 | ASM, IndexTypeQuals, |
| 3067 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3068 | } |
| 3069 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3070 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3071 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3072 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3073 | return QualType(); |
| 3074 | } |
| 3075 | |
| 3076 | QualType ElementType = GetType(Record[0]); |
| 3077 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3078 | unsigned VecKind = Record[2]; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3079 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3080 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3081 | } |
| 3082 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3083 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3084 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3085 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3086 | return QualType(); |
| 3087 | } |
| 3088 | |
| 3089 | QualType ElementType = GetType(Record[0]); |
| 3090 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3091 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3092 | } |
| 3093 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3094 | case TYPE_FUNCTION_NO_PROTO: { |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3095 | if (Record.size() != 4) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3096 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3097 | return QualType(); |
| 3098 | } |
| 3099 | QualType ResultType = GetType(Record[0]); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3100 | FunctionType::ExtInfo Info(Record[1], Record[2], (CallingConv)Record[3]); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 3101 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3102 | } |
| 3103 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3104 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3105 | QualType ResultType = GetType(Record[0]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3106 | |
| 3107 | FunctionProtoType::ExtProtoInfo EPI; |
| 3108 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
| 3109 | /*regparm*/ Record[2], |
| 3110 | static_cast<CallingConv>(Record[3])); |
| 3111 | |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3112 | unsigned Idx = 4; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3113 | unsigned NumParams = Record[Idx++]; |
| 3114 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 3115 | for (unsigned I = 0; I != NumParams; ++I) |
| 3116 | ParamTypes.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3117 | |
| 3118 | EPI.Variadic = Record[Idx++]; |
| 3119 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3120 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3121 | ExceptionSpecificationType EST = |
| 3122 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3123 | EPI.ExceptionSpecType = EST; |
| 3124 | if (EST == EST_Dynamic) { |
| 3125 | EPI.NumExceptions = Record[Idx++]; |
| 3126 | llvm::SmallVector<QualType, 2> Exceptions; |
| 3127 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
| 3128 | Exceptions.push_back(GetType(Record[Idx++])); |
| 3129 | EPI.Exceptions = Exceptions.data(); |
| 3130 | } else if (EST == EST_ComputedNoexcept) { |
| 3131 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
| 3132 | } |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 3133 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3134 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3135 | } |
| 3136 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3137 | case TYPE_UNRESOLVED_USING: |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3138 | return Context->getTypeDeclType( |
| 3139 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 3140 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3141 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3142 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3143 | Error("incorrect encoding of typedef type"); |
| 3144 | return QualType(); |
| 3145 | } |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3146 | TypedefDecl *Decl = cast<TypedefDecl>(GetDecl(Record[0])); |
| 3147 | QualType Canonical = GetType(Record[1]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3148 | if (!Canonical.isNull()) |
| 3149 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3150 | return Context->getTypedefType(Decl, Canonical); |
| 3151 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3152 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3153 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3154 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3155 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3156 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3157 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3158 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3159 | return QualType(); |
| 3160 | } |
| 3161 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3162 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3163 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3164 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3165 | case TYPE_DECLTYPE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3166 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3167 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3168 | case TYPE_AUTO: |
| 3169 | return Context->getAutoType(GetType(Record[0])); |
| 3170 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3171 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3172 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3173 | Error("incorrect encoding of record type"); |
| 3174 | return QualType(); |
| 3175 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3176 | bool IsDependent = Record[0]; |
| 3177 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3178 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3179 | return T; |
| 3180 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3181 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3182 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3183 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3184 | Error("incorrect encoding of enum type"); |
| 3185 | return QualType(); |
| 3186 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3187 | bool IsDependent = Record[0]; |
| 3188 | QualType T = Context->getEnumType(cast<EnumDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3189 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3190 | return T; |
| 3191 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3192 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3193 | case TYPE_ATTRIBUTED: { |
| 3194 | if (Record.size() != 3) { |
| 3195 | Error("incorrect encoding of attributed type"); |
| 3196 | return QualType(); |
| 3197 | } |
| 3198 | QualType modifiedType = GetType(Record[0]); |
| 3199 | QualType equivalentType = GetType(Record[1]); |
| 3200 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 3201 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 3202 | } |
| 3203 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3204 | case TYPE_PAREN: { |
| 3205 | if (Record.size() != 1) { |
| 3206 | Error("incorrect encoding of paren type"); |
| 3207 | return QualType(); |
| 3208 | } |
| 3209 | QualType InnerType = GetType(Record[0]); |
| 3210 | return Context->getParenType(InnerType); |
| 3211 | } |
| 3212 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3213 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3214 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3215 | Error("incorrect encoding of pack expansion type"); |
| 3216 | return QualType(); |
| 3217 | } |
| 3218 | QualType Pattern = GetType(Record[0]); |
| 3219 | if (Pattern.isNull()) |
| 3220 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3221 | llvm::Optional<unsigned> NumExpansions; |
| 3222 | if (Record[1]) |
| 3223 | NumExpansions = Record[1] - 1; |
| 3224 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3225 | } |
| 3226 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3227 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3228 | unsigned Idx = 0; |
| 3229 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3230 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3231 | QualType NamedType = GetType(Record[Idx++]); |
| 3232 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3233 | } |
| 3234 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3235 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3236 | unsigned Idx = 0; |
| 3237 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3238 | return Context->getObjCInterfaceType(ItfD); |
| 3239 | } |
| 3240 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3241 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3242 | unsigned Idx = 0; |
| 3243 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3244 | unsigned NumProtos = Record[Idx++]; |
| 3245 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 3246 | for (unsigned I = 0; I != NumProtos; ++I) |
| 3247 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3248 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3249 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3250 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3251 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3252 | unsigned Idx = 0; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3253 | QualType Pointee = GetType(Record[Idx++]); |
| 3254 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3255 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3256 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3257 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3258 | unsigned Idx = 0; |
| 3259 | QualType Parm = GetType(Record[Idx++]); |
| 3260 | QualType Replacement = GetType(Record[Idx++]); |
| 3261 | return |
| 3262 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3263 | Replacement); |
| 3264 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3265 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3266 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3267 | unsigned Idx = 0; |
| 3268 | QualType Parm = GetType(Record[Idx++]); |
| 3269 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3270 | return Context->getSubstTemplateTypeParmPackType( |
| 3271 | cast<TemplateTypeParmType>(Parm), |
| 3272 | ArgPack); |
| 3273 | } |
| 3274 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3275 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3276 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 3277 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3278 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3279 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3280 | return |
| 3281 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3282 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3283 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3284 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3285 | unsigned Idx = 0; |
| 3286 | unsigned Depth = Record[Idx++]; |
| 3287 | unsigned Index = Record[Idx++]; |
| 3288 | bool Pack = Record[Idx++]; |
| 3289 | IdentifierInfo *Name = GetIdentifierInfo(Record, Idx); |
| 3290 | return Context->getTemplateTypeParmType(Depth, Index, Pack, Name); |
| 3291 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3292 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3293 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3294 | unsigned Idx = 0; |
| 3295 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3296 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3297 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3298 | QualType Canon = GetType(Record[Idx++]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3299 | if (!Canon.isNull()) |
| 3300 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3301 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3302 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3303 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3304 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3305 | unsigned Idx = 0; |
| 3306 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3307 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3308 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
| 3309 | unsigned NumArgs = Record[Idx++]; |
| 3310 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 3311 | Args.reserve(NumArgs); |
| 3312 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3313 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3314 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3315 | Args.size(), Args.data()); |
| 3316 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3317 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3318 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3319 | unsigned Idx = 0; |
| 3320 | |
| 3321 | // ArrayType |
| 3322 | QualType ElementType = GetType(Record[Idx++]); |
| 3323 | ArrayType::ArraySizeModifier ASM |
| 3324 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3325 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3326 | |
| 3327 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3328 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3329 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3330 | |
| 3331 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3332 | IndexTypeQuals, Brackets); |
| 3333 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3334 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3335 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3336 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3337 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3338 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3339 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3340 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3341 | QualType Canon = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3342 | QualType T; |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3343 | if (Canon.isNull()) |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3344 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3345 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3346 | else |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3347 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
| 3348 | Args.size(), Canon); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3349 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3350 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3351 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3352 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3353 | // Suppress a GCC warning |
| 3354 | return QualType(); |
| 3355 | } |
| 3356 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3357 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3358 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3359 | ASTReader::PerFileData &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3360 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3361 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3362 | unsigned &Idx; |
| 3363 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3364 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3365 | unsigned &I) { |
| 3366 | return Reader.ReadSourceLocation(F, R, I); |
| 3367 | } |
| 3368 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3369 | public: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3370 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3371 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3372 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3373 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3374 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3375 | // We want compile-time assurance that we've enumerated all of |
| 3376 | // these, so unfortunately we have to declare them first, then |
| 3377 | // define them out-of-line. |
| 3378 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3379 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3380 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3381 | #include "clang/AST/TypeLocNodes.def" |
| 3382 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3383 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3384 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3385 | }; |
| 3386 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3387 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3388 | // nothing to do |
| 3389 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3390 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3391 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3392 | if (TL.needsExtraLocalData()) { |
| 3393 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3394 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3395 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3396 | TL.setModeAttr(Record[Idx++]); |
| 3397 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3398 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3399 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3400 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3401 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3402 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3403 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3404 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3405 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3406 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3407 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3408 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3409 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3410 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3411 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3412 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3413 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3414 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3415 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3416 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3417 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3418 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3419 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3420 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3421 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3422 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3423 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3424 | TL.setSizeExpr(0); |
| 3425 | } |
| 3426 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3427 | VisitArrayTypeLoc(TL); |
| 3428 | } |
| 3429 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3430 | VisitArrayTypeLoc(TL); |
| 3431 | } |
| 3432 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3433 | VisitArrayTypeLoc(TL); |
| 3434 | } |
| 3435 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3436 | DependentSizedArrayTypeLoc TL) { |
| 3437 | VisitArrayTypeLoc(TL); |
| 3438 | } |
| 3439 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3440 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3441 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3442 | } |
| 3443 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3444 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3445 | } |
| 3446 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3447 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3448 | } |
| 3449 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3450 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 3451 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3452 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3453 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | 86acc2a | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 3454 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3455 | } |
| 3456 | } |
| 3457 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3458 | VisitFunctionTypeLoc(TL); |
| 3459 | } |
| 3460 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3461 | VisitFunctionTypeLoc(TL); |
| 3462 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3463 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3464 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3465 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3466 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3467 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3468 | } |
| 3469 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3470 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3471 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3472 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3473 | } |
| 3474 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3475 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3476 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3477 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3478 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3479 | } |
| 3480 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3481 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3482 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3483 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3484 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3485 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3486 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3487 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3488 | } |
| 3489 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3490 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3491 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3492 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3493 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3494 | if (TL.hasAttrOperand()) { |
| 3495 | SourceRange range; |
| 3496 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3497 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3498 | TL.setAttrOperandParensRange(range); |
| 3499 | } |
| 3500 | if (TL.hasAttrExprOperand()) { |
| 3501 | if (Record[Idx++]) |
| 3502 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3503 | else |
| 3504 | TL.setAttrExprOperand(0); |
| 3505 | } else if (TL.hasAttrEnumOperand()) |
| 3506 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3507 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3508 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3509 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3510 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3511 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3512 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3513 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3514 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3515 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3516 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3517 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3518 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3519 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3520 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3521 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3522 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3523 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3524 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3525 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3526 | Reader.GetTemplateArgumentLocInfo(F, |
| 3527 | TL.getTypePtr()->getArg(i).getKind(), |
| 3528 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3529 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3530 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3531 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3532 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3533 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3534 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3535 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3536 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3537 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3538 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3539 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3540 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3541 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3542 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3543 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3544 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3545 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3546 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3547 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3548 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3549 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3550 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3551 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3552 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3553 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3554 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3555 | Reader.GetTemplateArgumentLocInfo(F, |
| 3556 | TL.getTypePtr()->getArg(I).getKind(), |
| 3557 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3558 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3559 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3560 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3561 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3562 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3563 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3564 | } |
| 3565 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3566 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3567 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3568 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3569 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3570 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3571 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3572 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3573 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3574 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3575 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3576 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3577 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3578 | unsigned &Idx) { |
| 3579 | QualType InfoTy = GetType(Record[Idx++]); |
| 3580 | if (InfoTy.isNull()) |
| 3581 | return 0; |
| 3582 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3583 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3584 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3585 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3586 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3587 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3588 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3589 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3590 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3591 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3592 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3593 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3594 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3595 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3596 | switch ((PredefinedTypeIDs)Index) { |
| 3597 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3598 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3599 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3600 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3601 | case PREDEF_TYPE_CHAR_U_ID: |
| 3602 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3603 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3604 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3605 | break; |
| 3606 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3607 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3608 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3609 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3610 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3611 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3612 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3613 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3614 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3615 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3616 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3617 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3618 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3619 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3620 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3621 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3622 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3623 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
| 3624 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
| 3625 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3626 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3627 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3628 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3629 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3630 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3631 | } |
| 3632 | |
| 3633 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3634 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3635 | } |
| 3636 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3637 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3638 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3639 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3640 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3641 | if (TypesLoaded[Index].isNull()) |
| 3642 | return QualType(); |
| 3643 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3644 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3645 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3646 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3647 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3648 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3649 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3650 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3651 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3652 | } |
| 3653 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3654 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3655 | return MakeTypeID(T, |
| 3656 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3657 | } |
| 3658 | |
| 3659 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3660 | if (T.isNull()) |
| 3661 | return TypeIdx(); |
| 3662 | assert(!T.getLocalFastQualifiers()); |
| 3663 | |
| 3664 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3665 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3666 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3667 | // If the type didn't come from the AST file use a specially marked index |
| 3668 | // so that any hash/key comparison fail since no such index is stored |
| 3669 | // in a AST file. |
| 3670 | if (I == TypeIdxs.end()) |
| 3671 | return TypeIdx(-1); |
| 3672 | return I->second; |
| 3673 | } |
| 3674 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3675 | unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const { |
| 3676 | unsigned Result = 0; |
| 3677 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 3678 | Result += Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3679 | |
| 3680 | return Result; |
| 3681 | } |
| 3682 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3683 | TemplateArgumentLocInfo |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3684 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3685 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3686 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3687 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3688 | switch (Kind) { |
| 3689 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3690 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3691 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3692 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3693 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3694 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3695 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3696 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3697 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3698 | SourceLocation()); |
| 3699 | } |
| 3700 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3701 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3702 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3703 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3704 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3705 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3706 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3707 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3708 | case TemplateArgument::Null: |
| 3709 | case TemplateArgument::Integral: |
| 3710 | case TemplateArgument::Declaration: |
| 3711 | case TemplateArgument::Pack: |
| 3712 | return TemplateArgumentLocInfo(); |
| 3713 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3714 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3715 | return TemplateArgumentLocInfo(); |
| 3716 | } |
| 3717 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3718 | TemplateArgumentLoc |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3719 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3720 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3721 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3722 | |
| 3723 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3724 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3725 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3726 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3727 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3728 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3729 | } |
| 3730 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3731 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3732 | return GetDecl(ID); |
| 3733 | } |
| 3734 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3735 | uint64_t |
| 3736 | ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) { |
| 3737 | if (ID == 0) |
| 3738 | return 0; |
| 3739 | |
| 3740 | --ID; |
| 3741 | uint64_t Offset = 0; |
| 3742 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3743 | PerFileData &F = *Chain[N - I - 1]; |
| 3744 | |
| 3745 | if (ID < F.LocalNumCXXBaseSpecifiers) |
| 3746 | return Offset + F.CXXBaseSpecifiersOffsets[ID]; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3747 | |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3748 | ID -= F.LocalNumCXXBaseSpecifiers; |
| 3749 | Offset += F.SizeInBits; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | assert(false && "CXXBaseSpecifiers not found"); |
| 3753 | return 0; |
| 3754 | } |
| 3755 | |
| 3756 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 3757 | // Figure out which AST file contains this offset. |
| 3758 | PerFileData *F = 0; |
| 3759 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3760 | if (Offset < Chain[N - I - 1]->SizeInBits) { |
| 3761 | F = Chain[N - I - 1]; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3762 | break; |
| 3763 | } |
| 3764 | |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3765 | Offset -= Chain[N - I - 1]->SizeInBits; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3766 | } |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3767 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3768 | if (!F) { |
| 3769 | Error("Malformed AST file: C++ base specifiers at impossible offset"); |
| 3770 | return 0; |
| 3771 | } |
| 3772 | |
| 3773 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3774 | SavedStreamPosition SavedPosition(Cursor); |
| 3775 | Cursor.JumpToBit(Offset); |
| 3776 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3777 | RecordData Record; |
| 3778 | unsigned Code = Cursor.ReadCode(); |
| 3779 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 3780 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 3781 | Error("Malformed AST file: missing C++ base specifiers"); |
| 3782 | return 0; |
| 3783 | } |
| 3784 | |
| 3785 | unsigned Idx = 0; |
| 3786 | unsigned NumBases = Record[Idx++]; |
| 3787 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 3788 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 3789 | for (unsigned I = 0; I != NumBases; ++I) |
| 3790 | Bases[I] = ReadCXXBaseSpecifier(*F, Record, Idx); |
| 3791 | return Bases; |
| 3792 | } |
| 3793 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3794 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3795 | if (!DeclsLoaded[0]) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 3796 | ReadDeclRecord(0, 1); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3797 | if (DeserializationListener) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3798 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3799 | } |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 3800 | |
| 3801 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 3802 | } |
| 3803 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3804 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3805 | if (ID == 0) |
| 3806 | return 0; |
| 3807 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3808 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3809 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3810 | return 0; |
| 3811 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3812 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3813 | unsigned Index = ID - 1; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3814 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3815 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3816 | if (DeserializationListener) |
| 3817 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3818 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3819 | |
| 3820 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3821 | } |
| 3822 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3823 | /// \brief Resolve the offset of a statement into a statement. |
| 3824 | /// |
| 3825 | /// This operation will read a new statement from the external |
| 3826 | /// source each time it is called, and is meant to be used via a |
| 3827 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3828 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 3829 | // Switch case IDs are per Decl. |
| 3830 | ClearSwitchCaseIDs(); |
| 3831 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3832 | // Offset here is a global offset across the entire chain. |
| 3833 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3834 | PerFileData &F = *Chain[N - I - 1]; |
| 3835 | if (Offset < F.SizeInBits) { |
| 3836 | // Since we know that this statement is part of a decl, make sure to use |
| 3837 | // the decl cursor to read it. |
| 3838 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3839 | return ReadStmtFromStream(F); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3840 | } |
| 3841 | Offset -= F.SizeInBits; |
| 3842 | } |
| 3843 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 3844 | } |
| 3845 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3846 | bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3847 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3848 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3849 | assert(DC->hasExternalLexicalStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3850 | "DeclContext has no lexical decls in storage"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3851 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3852 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 3853 | // at least. |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3854 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 3855 | // so make a copy of the vector. |
| 3856 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3857 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3858 | I != E; ++I) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3859 | // IDs can be 0 if this context doesn't contain declarations. |
| 3860 | if (!I->LexicalDecls) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3861 | continue; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3862 | |
| 3863 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3864 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 3865 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 3866 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 3867 | continue; |
| 3868 | |
| 3869 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3870 | assert(D && "Null decl in lexical decls"); |
| 3871 | Decls.push_back(D); |
| 3872 | } |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3873 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3874 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3875 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3876 | return false; |
| 3877 | } |
| 3878 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3879 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3880 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3881 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3882 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3883 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3884 | if (!Name) |
| 3885 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 3886 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3887 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3888 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 8b12273 | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 3889 | // 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] | 3890 | // and namespaces. For any given name, the last available results replace |
| 3891 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3892 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3893 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3894 | I != E; ++I) { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3895 | if (!I->NameLookupTableData) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3896 | continue; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3897 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3898 | ASTDeclContextNameLookupTable *LookupTable = |
| 3899 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3900 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 3901 | if (Pos == LookupTable->end()) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3902 | continue; |
| 3903 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3904 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 3905 | for (; Data.first != Data.second; ++Data.first) |
| 3906 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3907 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3908 | } |
| 3909 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3910 | ++NumVisibleDeclContextsRead; |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3911 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3912 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3913 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3914 | } |
| 3915 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 3916 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 3917 | assert(DC->hasExternalVisibleStorage() && |
| 3918 | "DeclContext has no visible decls in storage"); |
| 3919 | |
| 3920 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 3921 | // There might be visible decls in multiple parts of the chain, for the TU |
| 3922 | // and namespaces. |
| 3923 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 3924 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3925 | I != E; ++I) { |
| 3926 | if (!I->NameLookupTableData) |
| 3927 | continue; |
| 3928 | |
| 3929 | ASTDeclContextNameLookupTable *LookupTable = |
| 3930 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3931 | for (ASTDeclContextNameLookupTable::item_iterator |
| 3932 | ItemI = LookupTable->item_begin(), |
| 3933 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 3934 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 3935 | = *ItemI; |
| 3936 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 3937 | Decls.clear(); |
| 3938 | for (; Data.first != Data.second; ++Data.first) |
| 3939 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 3940 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 3941 | } |
| 3942 | } |
| 3943 | } |
| 3944 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3945 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3946 | assert(Consumer); |
| 3947 | while (!InterestingDecls.empty()) { |
| 3948 | DeclGroupRef DG(InterestingDecls.front()); |
| 3949 | InterestingDecls.pop_front(); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3950 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3951 | } |
| 3952 | } |
| 3953 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3954 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 3955 | this->Consumer = Consumer; |
| 3956 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3957 | if (!Consumer) |
| 3958 | return; |
| 3959 | |
| 3960 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3961 | // Force deserialization of this decl, which will cause it to be queued for |
| 3962 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 3963 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3964 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 3965 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3966 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3967 | } |
| 3968 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3969 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3970 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3971 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3973 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3974 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3975 | unsigned NumDeclsLoaded |
| 3976 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 3977 | (Decl *)0); |
| 3978 | unsigned NumIdentifiersLoaded |
| 3979 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 3980 | IdentifiersLoaded.end(), |
| 3981 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3982 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3983 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 3984 | SelectorsLoaded.end(), |
| 3985 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 3986 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3987 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 3988 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 3989 | if (TotalNumSLocEntries) |
| 3990 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 3991 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 3992 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3993 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3994 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3995 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 3996 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 3997 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3998 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3999 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 4000 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4001 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4002 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4003 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4004 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4005 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4006 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4007 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4008 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4009 | if (TotalNumStatements) |
| 4010 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4011 | NumStatementsRead, TotalNumStatements, |
| 4012 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4013 | if (TotalNumMacros) |
| 4014 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4015 | NumMacrosRead, TotalNumMacros, |
| 4016 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4017 | if (TotalLexicalDeclContexts) |
| 4018 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4019 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4020 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4021 | * 100)); |
| 4022 | if (TotalVisibleDeclContexts) |
| 4023 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4024 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4025 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4026 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4027 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4028 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4029 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4030 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4031 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4032 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4033 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4034 | std::fprintf(stderr, "\n"); |
| 4035 | } |
| 4036 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4037 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4038 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4039 | S.ExternalSource = this; |
| 4040 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4041 | // Makes sure any declarations that were deserialized "too early" |
| 4042 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4043 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4044 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4045 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4046 | |
| 4047 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4048 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4049 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4050 | |
| 4051 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4052 | // them to Sema's list of tentative definitions. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4053 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4054 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4055 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4056 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 4057 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4058 | // If there were any unused file scoped decls, deserialize them and add to |
| 4059 | // Sema's list of unused file scoped decls. |
| 4060 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4061 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4062 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 4063 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4064 | |
| 4065 | // If there were any locally-scoped external declarations, |
| 4066 | // deserialize them and add them to Sema's table of locally-scoped |
| 4067 | // external declarations. |
| 4068 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4069 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4070 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 4071 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4072 | |
| 4073 | // If there were any ext_vector type declarations, deserialize them |
| 4074 | // and add them to Sema's vector of such declarations. |
| 4075 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 4076 | SemaObj->ExtVectorDecls.push_back( |
| 4077 | cast<TypedefDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4078 | |
| 4079 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 4080 | // Can we cut them down before writing them ? |
| 4081 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4082 | // If there were any dynamic classes declarations, deserialize them |
| 4083 | // and add them to Sema's vector of such declarations. |
| 4084 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 4085 | SemaObj->DynamicClasses.push_back( |
| 4086 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4087 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4088 | // Load the offsets of the declarations that Sema references. |
| 4089 | // They will be lazily deserialized when needed. |
| 4090 | if (!SemaDeclRefs.empty()) { |
| 4091 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 4092 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4093 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 4094 | } |
| 4095 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4096 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 4097 | |
| 4098 | // If there are @selector references added them to its pool. This is for |
| 4099 | // implementation of -Wselector. |
| 4100 | if (!F->ReferencedSelectorsData.empty()) { |
| 4101 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 4102 | unsigned I = 0; |
| 4103 | while (I < DataSize) { |
| 4104 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 4105 | SourceLocation SelLoc = ReadSourceLocation( |
| 4106 | *F, F->ReferencedSelectorsData, I); |
| 4107 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | // If there were any pending implicit instantiations, deserialize them |
| 4112 | // and add them to Sema's queue of such instantiations. |
| 4113 | assert(F->PendingInstantiations.size() % 2 == 0 && |
| 4114 | "Expected pairs of entries"); |
| 4115 | for (unsigned Idx = 0, N = F->PendingInstantiations.size(); Idx < N;) { |
| 4116 | ValueDecl *D=cast<ValueDecl>(GetDecl(F->PendingInstantiations[Idx++])); |
| 4117 | SourceLocation Loc = ReadSourceLocation(*F, F->PendingInstantiations,Idx); |
| 4118 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 4119 | } |
| 4120 | } |
| 4121 | |
| 4122 | // The two special data sets below always come from the most recent PCH, |
| 4123 | // which is at the front of the chain. |
| 4124 | PerFileData &F = *Chain.front(); |
| 4125 | |
| 4126 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 4127 | // Sema's list of weak undeclared identifiers. |
| 4128 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 4129 | unsigned Idx = 0; |
| 4130 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 4131 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4132 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4133 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 4134 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 4135 | Sema::WeakInfo WI(AliasId, Loc); |
| 4136 | WI.setUsed(Used); |
| 4137 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | // If there were any VTable uses, deserialize the information and add it |
| 4142 | // to Sema's vector and map of VTable uses. |
| 4143 | if (!VTableUses.empty()) { |
| 4144 | unsigned Idx = 0; |
| 4145 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 4146 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4147 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 4148 | bool DefinitionRequired = VTableUses[Idx++]; |
| 4149 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 4150 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4151 | } |
| 4152 | } |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4153 | |
| 4154 | if (!FPPragmaOptions.empty()) { |
| 4155 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4156 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4157 | } |
| 4158 | |
| 4159 | if (!OpenCLExtensions.empty()) { |
| 4160 | unsigned I = 0; |
| 4161 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4162 | #include "clang/Basic/OpenCLExtensions.def" |
| 4163 | |
| 4164 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4165 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4166 | } |
| 4167 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4168 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4169 | // Try to find this name within our on-disk hash tables. We start with the |
| 4170 | // 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] | 4171 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4172 | ASTIdentifierLookupTable *IdTable |
| 4173 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4174 | if (!IdTable) |
| 4175 | continue; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4176 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4177 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4178 | if (Pos == IdTable->end()) |
| 4179 | continue; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4180 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4181 | // Dereferencing the iterator has the effect of building the |
| 4182 | // IdentifierInfo node and populating it with the various |
| 4183 | // declarations it needs. |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4184 | return *Pos; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4185 | } |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4186 | return 0; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4187 | } |
| 4188 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4189 | namespace clang { |
| 4190 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4191 | /// identifiers stored within a set of AST files. |
| 4192 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4193 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4194 | const ASTReader &Reader; |
| 4195 | |
| 4196 | /// \brief The current index into the chain of AST files stored in |
| 4197 | /// the AST reader. |
| 4198 | unsigned Index; |
| 4199 | |
| 4200 | /// \brief The current position within the identifier lookup table |
| 4201 | /// of the current AST file. |
| 4202 | ASTIdentifierLookupTable::key_iterator Current; |
| 4203 | |
| 4204 | /// \brief The end position within the identifier lookup table of |
| 4205 | /// the current AST file. |
| 4206 | ASTIdentifierLookupTable::key_iterator End; |
| 4207 | |
| 4208 | public: |
| 4209 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4210 | |
| 4211 | virtual llvm::StringRef Next(); |
| 4212 | }; |
| 4213 | } |
| 4214 | |
| 4215 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 4216 | : Reader(Reader), Index(Reader.Chain.size() - 1) { |
| 4217 | ASTIdentifierLookupTable *IdTable |
| 4218 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4219 | Current = IdTable->key_begin(); |
| 4220 | End = IdTable->key_end(); |
| 4221 | } |
| 4222 | |
| 4223 | llvm::StringRef ASTIdentifierIterator::Next() { |
| 4224 | while (Current == End) { |
| 4225 | // If we have exhausted all of our AST files, we're done. |
| 4226 | if (Index == 0) |
| 4227 | return llvm::StringRef(); |
| 4228 | |
| 4229 | --Index; |
| 4230 | ASTIdentifierLookupTable *IdTable |
| 4231 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4232 | Current = IdTable->key_begin(); |
| 4233 | End = IdTable->key_end(); |
| 4234 | } |
| 4235 | |
| 4236 | // We have any identifiers remaining in the current AST file; return |
| 4237 | // the next one. |
| 4238 | std::pair<const char*, unsigned> Key = *Current; |
| 4239 | ++Current; |
| 4240 | return llvm::StringRef(Key.first, Key.second); |
| 4241 | } |
| 4242 | |
| 4243 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4244 | return new ASTIdentifierIterator(*this); |
| 4245 | } |
| 4246 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4247 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4248 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4249 | // Find this selector in a hash table. We want to find the most recent entry. |
| 4250 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4251 | PerFileData &F = *Chain[I]; |
| 4252 | if (!F.SelectorLookupTable) |
| 4253 | continue; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4254 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4255 | ASTSelectorLookupTable *PoolTable |
| 4256 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 4257 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4258 | if (Pos != PoolTable->end()) { |
| 4259 | ++NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4260 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4261 | // disable this tracking when called via LoadSelector. |
| 4262 | // Also, should entries without methods count as misses? |
| 4263 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4264 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4265 | if (DeserializationListener) |
| 4266 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 4267 | return std::make_pair(Data.Instance, Data.Factory); |
| 4268 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4269 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4270 | |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4271 | ++NumMethodPoolMisses; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4272 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4273 | } |
| 4274 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4275 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4276 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4277 | ReadMethodPool(Sel); |
| 4278 | } |
| 4279 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4280 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4281 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4282 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4283 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4284 | if (DeserializationListener) |
| 4285 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4286 | } |
| 4287 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4288 | /// \brief Set the globally-visible declarations associated with the given |
| 4289 | /// identifier. |
| 4290 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4291 | /// 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] | 4292 | /// 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] | 4293 | /// them. |
| 4294 | /// |
| 4295 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4296 | /// declarations. |
| 4297 | /// |
| 4298 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4299 | /// visible at global scope. |
| 4300 | /// |
| 4301 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4302 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4303 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4304 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4305 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4306 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 4307 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4308 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4309 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4310 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4311 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4312 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4313 | return; |
| 4314 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4315 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4316 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4317 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4318 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4319 | if (SemaObj->TUScope) { |
| 4320 | // Introduce this declaration into the translation-unit scope |
| 4321 | // and add it to the declaration chain for this identifier, so |
| 4322 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4323 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4324 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4325 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4326 | } else { |
| 4327 | // Queue this declaration so that it will be added to the |
| 4328 | // translation unit scope and identifier's declaration chain |
| 4329 | // once a Sema object is known. |
| 4330 | PreloadedDecls.push_back(D); |
| 4331 | } |
| 4332 | } |
| 4333 | } |
| 4334 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4335 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4336 | if (ID == 0) |
| 4337 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4338 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4339 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4340 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4341 | return 0; |
| 4342 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4343 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4344 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4345 | ID -= 1; |
| 4346 | if (!IdentifiersLoaded[ID]) { |
| 4347 | unsigned Index = ID; |
| 4348 | const char *Str = 0; |
| 4349 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4350 | PerFileData *F = Chain[N - I - 1]; |
| 4351 | if (Index < F->LocalNumIdentifiers) { |
| 4352 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 4353 | Str = F->IdentifierTableData + Offset; |
| 4354 | break; |
| 4355 | } |
| 4356 | Index -= F->LocalNumIdentifiers; |
| 4357 | } |
| 4358 | assert(Str && "Broken Chain"); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4359 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4360 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4361 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4362 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4363 | // unsigned integers. This is important to avoid integer overflow when |
| 4364 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4365 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4366 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4367 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4368 | IdentifiersLoaded[ID] |
Kovarththanan Rajaratnam | 811f426 | 2010-03-12 10:32:27 +0000 | [diff] [blame] | 4369 | = &PP->getIdentifierTable().get(Str, StrLen); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4370 | if (DeserializationListener) |
| 4371 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4372 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4373 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4374 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4375 | } |
| 4376 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4377 | void ASTReader::ReadSLocEntry(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4378 | ReadSLocEntryRecord(ID); |
| 4379 | } |
| 4380 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4381 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4382 | if (ID == 0) |
| 4383 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4384 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4385 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4386 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4387 | return Selector(); |
| 4388 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4389 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4390 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4391 | // Load this selector from the selector table. |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4392 | unsigned Idx = ID - 1; |
| 4393 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4394 | PerFileData &F = *Chain[N - I - 1]; |
| 4395 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4396 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4397 | SelectorsLoaded[ID - 1] = |
| 4398 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 4399 | if (DeserializationListener) |
| 4400 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 4401 | break; |
| 4402 | } |
| 4403 | Idx -= F.LocalNumSelectors; |
| 4404 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4405 | } |
| 4406 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4407 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4408 | } |
| 4409 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4410 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4411 | return DecodeSelector(ID); |
| 4412 | } |
| 4413 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4414 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4415 | // ID 0 (the null selector) is considered an external selector. |
| 4416 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4417 | } |
| 4418 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4419 | DeclarationName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4420 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4421 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4422 | switch (Kind) { |
| 4423 | case DeclarationName::Identifier: |
| 4424 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 4425 | |
| 4426 | case DeclarationName::ObjCZeroArgSelector: |
| 4427 | case DeclarationName::ObjCOneArgSelector: |
| 4428 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 4429 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4430 | |
| 4431 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4432 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4433 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4434 | |
| 4435 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4436 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4437 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4438 | |
| 4439 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4440 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4441 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4442 | |
| 4443 | case DeclarationName::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4444 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4445 | (OverloadedOperatorKind)Record[Idx++]); |
| 4446 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4447 | case DeclarationName::CXXLiteralOperatorName: |
| 4448 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 4449 | GetIdentifierInfo(Record, Idx)); |
| 4450 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4451 | case DeclarationName::CXXUsingDirective: |
| 4452 | return DeclarationName::getUsingDirectiveName(); |
| 4453 | } |
| 4454 | |
| 4455 | // Required to silence GCC warning |
| 4456 | return DeclarationName(); |
| 4457 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4458 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4459 | void ASTReader::ReadDeclarationNameLoc(PerFileData &F, |
| 4460 | DeclarationNameLoc &DNLoc, |
| 4461 | DeclarationName Name, |
| 4462 | const RecordData &Record, unsigned &Idx) { |
| 4463 | switch (Name.getNameKind()) { |
| 4464 | case DeclarationName::CXXConstructorName: |
| 4465 | case DeclarationName::CXXDestructorName: |
| 4466 | case DeclarationName::CXXConversionFunctionName: |
| 4467 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4468 | break; |
| 4469 | |
| 4470 | case DeclarationName::CXXOperatorName: |
| 4471 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4472 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4473 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4474 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4475 | break; |
| 4476 | |
| 4477 | case DeclarationName::CXXLiteralOperatorName: |
| 4478 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4479 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4480 | break; |
| 4481 | |
| 4482 | case DeclarationName::Identifier: |
| 4483 | case DeclarationName::ObjCZeroArgSelector: |
| 4484 | case DeclarationName::ObjCOneArgSelector: |
| 4485 | case DeclarationName::ObjCMultiArgSelector: |
| 4486 | case DeclarationName::CXXUsingDirective: |
| 4487 | break; |
| 4488 | } |
| 4489 | } |
| 4490 | |
| 4491 | void ASTReader::ReadDeclarationNameInfo(PerFileData &F, |
| 4492 | DeclarationNameInfo &NameInfo, |
| 4493 | const RecordData &Record, unsigned &Idx) { |
| 4494 | NameInfo.setName(ReadDeclarationName(Record, Idx)); |
| 4495 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4496 | DeclarationNameLoc DNLoc; |
| 4497 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4498 | NameInfo.setInfo(DNLoc); |
| 4499 | } |
| 4500 | |
| 4501 | void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info, |
| 4502 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4503 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4504 | unsigned NumTPLists = Record[Idx++]; |
| 4505 | Info.NumTemplParamLists = NumTPLists; |
| 4506 | if (NumTPLists) { |
| 4507 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 4508 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4509 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4510 | } |
| 4511 | } |
| 4512 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4513 | TemplateName |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4514 | ASTReader::ReadTemplateName(PerFileData &F, const RecordData &Record, |
| 4515 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4516 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4517 | switch (Kind) { |
| 4518 | case TemplateName::Template: |
| 4519 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 4520 | |
| 4521 | case TemplateName::OverloadedTemplate: { |
| 4522 | unsigned size = Record[Idx++]; |
| 4523 | UnresolvedSet<8> Decls; |
| 4524 | while (size--) |
| 4525 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 4526 | |
| 4527 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 4528 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4529 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4530 | case TemplateName::QualifiedTemplate: { |
| 4531 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4532 | bool hasTemplKeyword = Record[Idx++]; |
| 4533 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 4534 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 4535 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4536 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4537 | case TemplateName::DependentTemplate: { |
| 4538 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4539 | if (Record[Idx++]) // isIdentifier |
| 4540 | return Context->getDependentTemplateName(NNS, |
| 4541 | GetIdentifierInfo(Record, Idx)); |
| 4542 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4543 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4544 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4545 | |
| 4546 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4547 | TemplateTemplateParmDecl *Param |
| 4548 | = cast_or_null<TemplateTemplateParmDecl>(GetDecl(Record[Idx++])); |
| 4549 | if (!Param) |
| 4550 | return TemplateName(); |
| 4551 | |
| 4552 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 4553 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 4554 | return TemplateName(); |
| 4555 | |
| 4556 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 4557 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4558 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4559 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4560 | assert(0 && "Unhandled template name kind!"); |
| 4561 | return TemplateName(); |
| 4562 | } |
| 4563 | |
| 4564 | TemplateArgument |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4565 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4566 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4567 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 4568 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4569 | case TemplateArgument::Null: |
| 4570 | return TemplateArgument(); |
| 4571 | case TemplateArgument::Type: |
| 4572 | return TemplateArgument(GetType(Record[Idx++])); |
| 4573 | case TemplateArgument::Declaration: |
| 4574 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4575 | case TemplateArgument::Integral: { |
| 4576 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 4577 | QualType T = GetType(Record[Idx++]); |
| 4578 | return TemplateArgument(Value, T); |
| 4579 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4580 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4581 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4582 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4583 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4584 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 4585 | if (unsigned NumExpansions = Record[Idx++]) |
| 4586 | NumTemplateExpansions = NumExpansions - 1; |
| 4587 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4588 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4589 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4590 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4591 | case TemplateArgument::Pack: { |
| 4592 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4593 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 4594 | for (unsigned I = 0; I != NumArgs; ++I) |
| 4595 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 4596 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4597 | } |
| 4598 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4599 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4600 | assert(0 && "Unhandled template argument kind!"); |
| 4601 | return TemplateArgument(); |
| 4602 | } |
| 4603 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4604 | TemplateParameterList * |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4605 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 4606 | const RecordData &Record, unsigned &Idx) { |
| 4607 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 4608 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 4609 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4610 | |
| 4611 | unsigned NumParams = Record[Idx++]; |
| 4612 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 4613 | Params.reserve(NumParams); |
| 4614 | while (NumParams--) |
| 4615 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4616 | |
| 4617 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4618 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 4619 | Params.data(), Params.size(), RAngleLoc); |
| 4620 | return TemplateParams; |
| 4621 | } |
| 4622 | |
| 4623 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4624 | ASTReader:: |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4625 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4626 | PerFileData &F, const RecordData &Record, |
| 4627 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4628 | unsigned NumTemplateArgs = Record[Idx++]; |
| 4629 | TemplArgs.reserve(NumTemplateArgs); |
| 4630 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4631 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4632 | } |
| 4633 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4634 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4635 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4636 | const RecordData &Record, unsigned &Idx) { |
| 4637 | unsigned NumDecls = Record[Idx++]; |
| 4638 | while (NumDecls--) { |
| 4639 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 4640 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 4641 | Set.addDecl(D, AS); |
| 4642 | } |
| 4643 | } |
| 4644 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4645 | CXXBaseSpecifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4646 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4647 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4648 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 4649 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 4650 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4651 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4652 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4653 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4654 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4655 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4656 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4657 | Result.setInheritConstructors(inheritConstructors); |
| 4658 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4659 | } |
| 4660 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4661 | std::pair<CXXCtorInitializer **, unsigned> |
| 4662 | ASTReader::ReadCXXCtorInitializers(PerFileData &F, const RecordData &Record, |
| 4663 | unsigned &Idx) { |
| 4664 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4665 | unsigned NumInitializers = Record[Idx++]; |
| 4666 | if (NumInitializers) { |
| 4667 | ASTContext &C = *getContext(); |
| 4668 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4669 | CtorInitializers |
| 4670 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4671 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 4672 | TypeSourceInfo *BaseClassInfo = 0; |
| 4673 | bool IsBaseVirtual = false; |
| 4674 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4675 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4676 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4677 | bool IsBaseInitializer = Record[Idx++]; |
| 4678 | if (IsBaseInitializer) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4679 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4680 | IsBaseVirtual = Record[Idx++]; |
| 4681 | } else { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4682 | bool IsIndirectMemberInitializer = Record[Idx++]; |
| 4683 | if (IsIndirectMemberInitializer) |
| 4684 | IndirectMember = cast<IndirectFieldDecl>(GetDecl(Record[Idx++])); |
| 4685 | else |
| 4686 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4687 | } |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 4688 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4689 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4690 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 4691 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4692 | bool IsWritten = Record[Idx++]; |
| 4693 | unsigned SourceOrderOrNumArrayIndices; |
| 4694 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 4695 | if (IsWritten) { |
| 4696 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4697 | } else { |
| 4698 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4699 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 4700 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 4701 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 4702 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4703 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4704 | CXXCtorInitializer *BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4705 | if (IsBaseInitializer) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4706 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 4707 | LParenLoc, Init, RParenLoc, |
| 4708 | MemberOrEllipsisLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4709 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4710 | if (Member) |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4711 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 4712 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4713 | else |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4714 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 4715 | MemberOrEllipsisLoc, LParenLoc, |
| 4716 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4717 | } else { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4718 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 4719 | LParenLoc, Init, RParenLoc, |
| 4720 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4721 | } |
| 4722 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 4723 | if (IsWritten) |
| 4724 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4725 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4726 | } |
| 4727 | } |
| 4728 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4729 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4730 | } |
| 4731 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4732 | NestedNameSpecifier * |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4733 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4734 | unsigned N = Record[Idx++]; |
| 4735 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 4736 | for (unsigned I = 0; I != N; ++I) { |
| 4737 | NestedNameSpecifier::SpecifierKind Kind |
| 4738 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4739 | switch (Kind) { |
| 4740 | case NestedNameSpecifier::Identifier: { |
| 4741 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 4742 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 4743 | break; |
| 4744 | } |
| 4745 | |
| 4746 | case NestedNameSpecifier::Namespace: { |
| 4747 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 4748 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 4749 | break; |
| 4750 | } |
| 4751 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 4752 | case NestedNameSpecifier::NamespaceAlias: { |
| 4753 | NamespaceAliasDecl *Alias |
| 4754 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
| 4755 | NNS = NestedNameSpecifier::Create(*Context, Prev, Alias); |
| 4756 | break; |
| 4757 | } |
| 4758 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4759 | case NestedNameSpecifier::TypeSpec: |
| 4760 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4761 | const Type *T = GetType(Record[Idx++]).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 4762 | if (!T) |
| 4763 | return 0; |
| 4764 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4765 | bool Template = Record[Idx++]; |
| 4766 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 4767 | break; |
| 4768 | } |
| 4769 | |
| 4770 | case NestedNameSpecifier::Global: { |
| 4771 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4772 | // No associated value, and there can't be a prefix. |
| 4773 | break; |
| 4774 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4775 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 4776 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4777 | } |
| 4778 | return NNS; |
| 4779 | } |
| 4780 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4781 | NestedNameSpecifierLoc |
| 4782 | ASTReader::ReadNestedNameSpecifierLoc(PerFileData &F, const RecordData &Record, |
| 4783 | unsigned &Idx) { |
| 4784 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4785 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4786 | for (unsigned I = 0; I != N; ++I) { |
| 4787 | NestedNameSpecifier::SpecifierKind Kind |
| 4788 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4789 | switch (Kind) { |
| 4790 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4791 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4792 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4793 | Builder.Extend(*Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4794 | break; |
| 4795 | } |
| 4796 | |
| 4797 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4798 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4799 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4800 | Builder.Extend(*Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4801 | break; |
| 4802 | } |
| 4803 | |
| 4804 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4805 | NamespaceAliasDecl *Alias |
| 4806 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4807 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4808 | Builder.Extend(*Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4809 | break; |
| 4810 | } |
| 4811 | |
| 4812 | case NestedNameSpecifier::TypeSpec: |
| 4813 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4814 | bool Template = Record[Idx++]; |
| 4815 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 4816 | if (!T) |
| 4817 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4818 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4819 | |
| 4820 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
| 4821 | Builder.Extend(*Context, |
| 4822 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 4823 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4824 | break; |
| 4825 | } |
| 4826 | |
| 4827 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4828 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4829 | Builder.MakeGlobal(*Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4830 | break; |
| 4831 | } |
| 4832 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4833 | } |
| 4834 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4835 | return Builder.getWithLocInContext(*Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4836 | } |
| 4837 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4838 | SourceRange |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4839 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 4840 | unsigned &Idx) { |
| 4841 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 4842 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 4843 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4844 | } |
| 4845 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4846 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4847 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4848 | unsigned BitWidth = Record[Idx++]; |
| 4849 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 4850 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 4851 | Idx += NumWords; |
| 4852 | return Result; |
| 4853 | } |
| 4854 | |
| 4855 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4856 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4857 | bool isUnsigned = Record[Idx++]; |
| 4858 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 4859 | } |
| 4860 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4861 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4862 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4863 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 4864 | } |
| 4865 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4866 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4867 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4868 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 4869 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4870 | Idx += Len; |
| 4871 | return Result; |
| 4872 | } |
| 4873 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4874 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 4875 | unsigned &Idx) { |
| 4876 | unsigned Major = Record[Idx++]; |
| 4877 | unsigned Minor = Record[Idx++]; |
| 4878 | unsigned Subminor = Record[Idx++]; |
| 4879 | if (Minor == 0) |
| 4880 | return VersionTuple(Major); |
| 4881 | if (Subminor == 0) |
| 4882 | return VersionTuple(Major, Minor - 1); |
| 4883 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 4884 | } |
| 4885 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4886 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4887 | unsigned &Idx) { |
| 4888 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 4889 | return CXXTemporary::Create(*Context, Decl); |
| 4890 | } |
| 4891 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4892 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 4893 | return Diag(SourceLocation(), DiagID); |
| 4894 | } |
| 4895 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4896 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4897 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4898 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4899 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4900 | /// \brief Retrieve the identifier table associated with the |
| 4901 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4902 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4903 | assert(PP && "Forgot to set Preprocessor ?"); |
| 4904 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4905 | } |
| 4906 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4907 | /// \brief Record that the given ID maps to the given switch-case |
| 4908 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4909 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4910 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 4911 | SwitchCaseStmts[ID] = SC; |
| 4912 | } |
| 4913 | |
| 4914 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4915 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4916 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 4917 | return SwitchCaseStmts[ID]; |
| 4918 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4919 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4920 | void ASTReader::ClearSwitchCaseIDs() { |
| 4921 | SwitchCaseStmts.clear(); |
| 4922 | } |
| 4923 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4924 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4925 | assert(NumCurrentElementsDeserializing && |
| 4926 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 4927 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4928 | // If any identifiers with corresponding top-level declarations have |
| 4929 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4930 | while (!PendingIdentifierInfos.empty()) { |
| 4931 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 4932 | PendingIdentifierInfos.front().DeclIDs, true); |
| 4933 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4934 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4935 | |
Argyrios Kyrtzidis | 0895d15 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 4936 | // Ready to load previous declarations of Decls that were delayed. |
| 4937 | while (!PendingPreviousDecls.empty()) { |
| 4938 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 4939 | PendingPreviousDecls.front().second); |
| 4940 | PendingPreviousDecls.pop_front(); |
| 4941 | } |
| 4942 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4943 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 4944 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4945 | if (Consumer) |
| 4946 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 4947 | |
| 4948 | assert(PendingForwardRefs.size() == 0 && |
| 4949 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4950 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4951 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4952 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4953 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4954 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4955 | const char *isysroot, bool DisableValidation, |
| 4956 | bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4957 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 4958 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 4959 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
| 4960 | Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4961 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 4962 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), NextSLocOffset(0), |
| 4963 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 4964 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 4965 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 4966 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
| 4967 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 4968 | NumCurrentElementsDeserializing(0) |
| 4969 | { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4970 | RelocatablePCH = false; |
| 4971 | } |
| 4972 | |
| 4973 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 4974 | Diagnostic &Diags, const char *isysroot, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4975 | bool DisableValidation, bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4976 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
| 4977 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4978 | isysroot(isysroot), DisableValidation(DisableValidation), |
| 4979 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 4980 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4981 | NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0), |
| 4982 | NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), |
| 4983 | NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
| 4984 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4985 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4986 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4987 | RelocatablePCH = false; |
| 4988 | } |
| 4989 | |
| 4990 | ASTReader::~ASTReader() { |
| 4991 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 4992 | delete Chain[e - i - 1]; |
| 4993 | // Delete all visible decl lookup tables |
| 4994 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 4995 | E = DeclContextOffsets.end(); |
| 4996 | I != E; ++I) { |
| 4997 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 4998 | J != F; ++J) { |
| 4999 | if (J->NameLookupTableData) |
| 5000 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 5001 | J->NameLookupTableData); |
| 5002 | } |
| 5003 | } |
| 5004 | for (DeclContextVisibleUpdatesPending::iterator |
| 5005 | I = PendingVisibleUpdates.begin(), |
| 5006 | E = PendingVisibleUpdates.end(); |
| 5007 | I != E; ++I) { |
| 5008 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5009 | F = I->second.end(); |
| 5010 | J != F; ++J) |
| 5011 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 5012 | } |
| 5013 | } |
| 5014 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 5015 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
| 5016 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5017 | LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), |
| 5018 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5019 | MacroDefinitionOffsets(0), |
| 5020 | LocalNumHeaderFileInfos(0), HeaderFileInfoTableData(0), |
| 5021 | HeaderFileInfoTable(0), |
| 5022 | LocalNumSelectors(0), SelectorOffsets(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5023 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5024 | DeclOffsets(0), LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
| 5025 | LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 5026 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5027 | {} |
| 5028 | |
| 5029 | ASTReader::PerFileData::~PerFileData() { |
| 5030 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5031 | delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5032 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 5033 | } |