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" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 40 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 41 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 42 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 43 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 44 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 45 | #include "llvm/Support/Path.h" |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 46 | #include "llvm/Support/system_error.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 47 | #include <algorithm> |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 48 | #include <iterator> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 49 | #include <cstdio> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 50 | #include <sys/stat.h> |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 51 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 52 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 53 | using namespace clang::serialization; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 54 | |
| 55 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 56 | // PCH validator implementation |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 57 | //===----------------------------------------------------------------------===// |
| 58 | |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 59 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 60 | |
| 61 | bool |
| 62 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 63 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 64 | #define PARSE_LANGOPT_BENIGN(Option) |
| 65 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 66 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 67 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 68 | return true; \ |
| 69 | } |
| 70 | |
| 71 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 72 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 73 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 74 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 75 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 76 | PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 77 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 78 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 79 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 80 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
| 81 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 82 | PARSE_LANGOPT_BENIGN(MSCVersion); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 83 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 84 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 85 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 86 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 87 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 88 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 89 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 90 | PARSE_LANGOPT_IMPORTANT(AppleKext, diag::warn_pch_apple_kext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 91 | PARSE_LANGOPT_IMPORTANT(ObjCDefaultSynthProperties, |
| 92 | diag::warn_pch_objc_auto_properties); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 93 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 94 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 95 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 96 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 97 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 98 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 99 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 100 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 101 | PARSE_LANGOPT_IMPORTANT(ObjCExceptions, diag::warn_pch_objc_exceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 102 | PARSE_LANGOPT_IMPORTANT(CXXExceptions, diag::warn_pch_cxx_exceptions); |
| 103 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 104 | PARSE_LANGOPT_IMPORTANT(MSBitfields, diag::warn_pch_ms_bitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 105 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 106 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 107 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 108 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 109 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 110 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 111 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 112 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 113 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 114 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 115 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 116 | diag::warn_pch_heinous_extensions); |
| 117 | // FIXME: Most of the options below are benign if the macro wasn't |
| 118 | // used. Unfortunately, this means that a PCH compiled without |
| 119 | // optimization can't be used with optimization turned on, even |
| 120 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 121 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 122 | // doesn't matter. We could consider making this some special kind |
| 123 | // of check. |
| 124 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 125 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 126 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 127 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 128 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 129 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
| 130 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 131 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 132 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 133 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 134 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 135 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 136 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 137 | return true; |
| 138 | } |
| 139 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 140 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 141 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 142 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 143 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 144 | PARSE_LANGOPT_IMPORTANT(CUDA, diag::warn_pch_cuda); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 145 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 146 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 147 | PARSE_LANGOPT_BENIGN(SpellChecking); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 148 | PARSE_LANGOPT_BENIGN(DefaultFPContract); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 149 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 150 | #undef PARSE_LANGOPT_BENIGN |
| 151 | |
| 152 | return false; |
| 153 | } |
| 154 | |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 155 | bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) { |
| 156 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 157 | return false; |
| 158 | |
| 159 | Reader.Diag(diag::warn_pch_target_triple) |
| 160 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 161 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 164 | namespace { |
| 165 | struct EmptyStringRef { |
| 166 | bool operator ()(llvm::StringRef r) const { return r.empty(); } |
| 167 | }; |
| 168 | struct EmptyBlock { |
| 169 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 170 | }; |
| 171 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 172 | |
| 173 | static bool EqualConcatenations(llvm::SmallVector<llvm::StringRef, 2> L, |
| 174 | PCHPredefinesBlocks R) { |
| 175 | // First, sum up the lengths. |
| 176 | unsigned LL = 0, RL = 0; |
| 177 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 178 | LL += L[I].size(); |
| 179 | } |
| 180 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 181 | RL += R[I].Data.size(); |
| 182 | } |
| 183 | if (LL != RL) |
| 184 | return false; |
| 185 | if (LL == 0 && RL == 0) |
| 186 | return true; |
| 187 | |
| 188 | // Kick out empty parts, they confuse the algorithm below. |
| 189 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 190 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 191 | |
| 192 | // Do it the hard way. At this point, both vectors must be non-empty. |
| 193 | llvm::StringRef LR = L[0], RR = R[0].Data; |
| 194 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 195 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 196 | for (;;) { |
| 197 | // Compare the current pieces. |
| 198 | if (LR.size() == RR.size()) { |
| 199 | // If they're the same length, it's pretty easy. |
| 200 | if (LR != RR) |
| 201 | return false; |
| 202 | // Both pieces are done, advance. |
| 203 | ++LI; |
| 204 | ++RI; |
| 205 | // If either string is done, they're both done, since they're the same |
| 206 | // length. |
| 207 | if (LI == LN) { |
| 208 | assert(RI == RN && "Strings not the same length after all?"); |
| 209 | return true; |
| 210 | } |
| 211 | LR = L[LI]; |
| 212 | RR = R[RI].Data; |
| 213 | } else if (LR.size() < RR.size()) { |
| 214 | // Right piece is longer. |
| 215 | if (!RR.startswith(LR)) |
| 216 | return false; |
| 217 | ++LI; |
| 218 | assert(LI != LN && "Strings not the same length after all?"); |
| 219 | RR = RR.substr(LR.size()); |
| 220 | LR = L[LI]; |
| 221 | } else { |
| 222 | // Left piece is longer. |
| 223 | if (!LR.startswith(RR)) |
| 224 | return false; |
| 225 | ++RI; |
| 226 | assert(RI != RN && "Strings not the same length after all?"); |
| 227 | LR = LR.substr(RR.size()); |
| 228 | RR = R[RI].Data; |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | static std::pair<FileID, llvm::StringRef::size_type> |
| 234 | FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) { |
| 235 | std::pair<FileID, llvm::StringRef::size_type> Res; |
| 236 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 237 | Res.second = Buffers[I].Data.find(MacroDef); |
| 238 | if (Res.second != llvm::StringRef::npos) { |
| 239 | Res.first = Buffers[I].BufferID; |
| 240 | break; |
| 241 | } |
| 242 | } |
| 243 | return Res; |
| 244 | } |
| 245 | |
| 246 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 247 | llvm::StringRef OriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 248 | std::string &SuggestedPredefines, |
| 249 | FileManager &FileMgr) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 250 | // We are in the context of an implicit include, so the predefines buffer will |
| 251 | // have a #include entry for the PCH file itself (as normalized by the |
| 252 | // preprocessor initialization). Find it and skip over it in the checking |
| 253 | // below. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 254 | llvm::SmallString<256> PCHInclude; |
| 255 | PCHInclude += "#include \""; |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 256 | PCHInclude += NormalizeDashIncludePath(OriginalFileName, FileMgr); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 257 | PCHInclude += "\"\n"; |
| 258 | std::pair<llvm::StringRef,llvm::StringRef> Split = |
| 259 | llvm::StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 260 | llvm::StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 261 | if (Left == PP.getPredefines()) { |
| 262 | Error("Missing PCH include entry!"); |
| 263 | return true; |
| 264 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 265 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 266 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 267 | // command line, we're done. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 268 | llvm::SmallVector<llvm::StringRef, 2> CommandLine; |
| 269 | CommandLine.push_back(Left); |
| 270 | CommandLine.push_back(Right); |
| 271 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 272 | return false; |
| 273 | |
| 274 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 275 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 276 | // The predefines buffers are different. Determine what the differences are, |
| 277 | // and whether they require us to reject the PCH file. |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 278 | llvm::SmallVector<llvm::StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 279 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 280 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 281 | |
| 282 | llvm::SmallVector<llvm::StringRef, 8> CmdLineLines; |
| 283 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 284 | |
| 285 | // Pick out implicit #includes after the PCH and don't consider them for |
| 286 | // validation; we will insert them into SuggestedPredefines so that the |
| 287 | // preprocessor includes them. |
| 288 | std::string IncludesAfterPCH; |
| 289 | llvm::SmallVector<llvm::StringRef, 8> AfterPCHLines; |
| 290 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 291 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 292 | if (AfterPCHLines[i].startswith("#include ")) { |
| 293 | IncludesAfterPCH += AfterPCHLines[i]; |
| 294 | IncludesAfterPCH += '\n'; |
| 295 | } else { |
| 296 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | // Make sure we add the includes last into SuggestedPredefines before we |
| 301 | // exit this function. |
| 302 | struct AddIncludesRAII { |
| 303 | std::string &SuggestedPredefines; |
| 304 | std::string &IncludesAfterPCH; |
| 305 | |
| 306 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 307 | std::string &IncludesAfterPCH) |
| 308 | : SuggestedPredefines(SuggestedPredefines), |
| 309 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 310 | ~AddIncludesRAII() { |
| 311 | SuggestedPredefines += IncludesAfterPCH; |
| 312 | } |
| 313 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 314 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 315 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 316 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 317 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 318 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 319 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 320 | // Determine which predefines that were used to build the PCH file are missing |
| 321 | // from the command line. |
| 322 | std::vector<llvm::StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 323 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 324 | CmdLineLines.begin(), CmdLineLines.end(), |
| 325 | std::back_inserter(MissingPredefines)); |
| 326 | |
| 327 | bool MissingDefines = false; |
| 328 | bool ConflictingDefines = false; |
| 329 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 330 | llvm::StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 331 | if (Missing.startswith("#include ")) { |
| 332 | // An -include was specified when generating the PCH; it is included in |
| 333 | // the PCH, just ignore it. |
| 334 | continue; |
| 335 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 336 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 337 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 338 | return true; |
| 339 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 340 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 341 | // This is a macro definition. Determine the name of the macro we're |
| 342 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 343 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 344 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 345 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 346 | assert(EndOfMacroName != std::string::npos && |
| 347 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 348 | llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 349 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 350 | // Determine whether this macro was given a different definition on the |
| 351 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 352 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 353 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 354 | llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 355 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 356 | MacroDefStart); |
| 357 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 358 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 359 | // Different macro; we're done. |
| 360 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 361 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 362 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 363 | |
| 364 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 365 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 366 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 367 | (*ConflictPos)[MacroDefLen] != '(') |
| 368 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 369 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 370 | // We found a conflicting macro definition. |
| 371 | break; |
| 372 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 374 | if (ConflictPos != CmdLineLines.end()) { |
| 375 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 376 | << MacroName; |
| 377 | |
| 378 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 379 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 380 | FindMacro(Buffers, Missing); |
| 381 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 382 | SourceLocation PCHMissingLoc = |
| 383 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 384 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 385 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 386 | |
| 387 | ConflictingDefines = true; |
| 388 | continue; |
| 389 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 390 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 391 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 392 | // 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] | 393 | if (ConflictingDefines) |
| 394 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 396 | if (!MissingDefines) { |
| 397 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 398 | MissingDefines = true; |
| 399 | } |
| 400 | |
| 401 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 402 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 403 | FindMacro(Buffers, Missing); |
| 404 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 405 | SourceLocation PCHMissingLoc = |
| 406 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 407 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 408 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 409 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 410 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 411 | if (ConflictingDefines) |
| 412 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 413 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 414 | // Determine what predefines were introduced based on command-line |
| 415 | // parameters that were not present when building the PCH |
| 416 | // file. Extra #defines are okay, so long as the identifiers being |
| 417 | // defined were not used within the precompiled header. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 418 | std::vector<llvm::StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 419 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 420 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 421 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 422 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 423 | llvm::StringRef &Extra = ExtraPredefines[I]; |
| 424 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 425 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 426 | return true; |
| 427 | } |
| 428 | |
| 429 | // This is an extra macro definition. Determine the name of the |
| 430 | // macro we're defining. |
| 431 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 433 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 434 | assert(EndOfMacroName != std::string::npos && |
| 435 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 436 | llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 437 | |
| 438 | // Check whether this name was used somewhere in the PCH file. If |
| 439 | // so, defining it as a macro could change behavior, so we reject |
| 440 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 441 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 442 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 443 | return true; |
| 444 | } |
| 445 | |
| 446 | // Add this definition to the suggested predefines buffer. |
| 447 | SuggestedPredefines += Extra; |
| 448 | SuggestedPredefines += '\n'; |
| 449 | } |
| 450 | |
| 451 | // If we get here, it's because the predefines buffer had compatible |
| 452 | // contents. Accept the PCH file. |
| 453 | return false; |
| 454 | } |
| 455 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 456 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 457 | unsigned ID) { |
| 458 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 459 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | void PCHValidator::ReadCounter(unsigned Value) { |
| 463 | PP.setCounterValue(Value); |
| 464 | } |
| 465 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 466 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 467 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 468 | //===----------------------------------------------------------------------===// |
| 469 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 470 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 471 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 472 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 475 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 476 | namespace { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 477 | class ASTSelectorLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 478 | ASTReader &Reader; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 479 | |
| 480 | public: |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 481 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 482 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 483 | ObjCMethodList Instance, Factory; |
| 484 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 485 | |
| 486 | typedef Selector external_key_type; |
| 487 | typedef external_key_type internal_key_type; |
| 488 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 489 | explicit ASTSelectorLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 490 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 491 | static bool EqualKey(const internal_key_type& a, |
| 492 | const internal_key_type& b) { |
| 493 | return a == b; |
| 494 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 496 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 497 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 498 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 500 | // This hopefully will just get inlined and removed by the optimizer. |
| 501 | static const internal_key_type& |
| 502 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 503 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 504 | static std::pair<unsigned, unsigned> |
| 505 | ReadKeyDataLength(const unsigned char*& d) { |
| 506 | using namespace clang::io; |
| 507 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 508 | unsigned DataLen = ReadUnalignedLE16(d); |
| 509 | return std::make_pair(KeyLen, DataLen); |
| 510 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 512 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 513 | using namespace clang::io; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 514 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 515 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | IdentifierInfo *FirstII |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 517 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 518 | if (N == 0) |
| 519 | return SelTable.getNullarySelector(FirstII); |
| 520 | else if (N == 1) |
| 521 | return SelTable.getUnarySelector(FirstII); |
| 522 | |
| 523 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 524 | Args.push_back(FirstII); |
| 525 | for (unsigned I = 1; I != N; ++I) |
| 526 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 527 | |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 528 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 529 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 531 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 532 | using namespace clang::io; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 533 | |
| 534 | data_type Result; |
| 535 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 536 | Result.ID = ReadUnalignedLE32(d); |
| 537 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 538 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 539 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 540 | // Load instance methods |
| 541 | ObjCMethodList *Prev = 0; |
| 542 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 543 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 544 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 545 | if (!Result.Instance.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 546 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 547 | Result.Instance.Method = Method; |
| 548 | Prev = &Result.Instance; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 549 | continue; |
| 550 | } |
| 551 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 552 | ObjCMethodList *Mem = |
| 553 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 554 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 555 | Prev = Prev->Next; |
| 556 | } |
| 557 | |
| 558 | // Load factory methods |
| 559 | Prev = 0; |
| 560 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 561 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 562 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 563 | if (!Result.Factory.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 564 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 565 | Result.Factory.Method = Method; |
| 566 | Prev = &Result.Factory; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 567 | continue; |
| 568 | } |
| 569 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 570 | ObjCMethodList *Mem = |
| 571 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 572 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 573 | Prev = Prev->Next; |
| 574 | } |
| 575 | |
| 576 | return Result; |
| 577 | } |
| 578 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 579 | |
| 580 | } // end anonymous namespace |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 581 | |
| 582 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 583 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 584 | ASTSelectorLookupTable; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 585 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 586 | namespace clang { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 587 | class ASTIdentifierLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 588 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 589 | ASTReader::PerFileData &F; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 590 | |
| 591 | // If we know the IdentifierInfo in advance, it is here and we will |
| 592 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 593 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 594 | IdentifierInfo *KnownII; |
| 595 | |
| 596 | public: |
| 597 | typedef IdentifierInfo * data_type; |
| 598 | |
| 599 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 600 | |
| 601 | typedef external_key_type internal_key_type; |
| 602 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 603 | ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 604 | IdentifierInfo *II = 0) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 605 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 606 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 607 | static bool EqualKey(const internal_key_type& a, |
| 608 | const internal_key_type& b) { |
| 609 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 610 | : false; |
| 611 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 612 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 613 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 614 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 615 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 616 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 617 | // This hopefully will just get inlined and removed by the optimizer. |
| 618 | static const internal_key_type& |
| 619 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 620 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 621 | // This hopefully will just get inlined and removed by the optimizer. |
| 622 | static const external_key_type& |
| 623 | GetExternalKey(const internal_key_type& x) { return x; } |
| 624 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 625 | static std::pair<unsigned, unsigned> |
| 626 | ReadKeyDataLength(const unsigned char*& d) { |
| 627 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 628 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 629 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 630 | return std::make_pair(KeyLen, DataLen); |
| 631 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 632 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 633 | static std::pair<const char*, unsigned> |
| 634 | ReadKey(const unsigned char* d, unsigned n) { |
| 635 | assert(n >= 2 && d[n-1] == '\0'); |
| 636 | return std::make_pair((const char*) d, n-1); |
| 637 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 638 | |
| 639 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 640 | const unsigned char* d, |
| 641 | unsigned DataLen) { |
| 642 | using namespace clang::io; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 643 | IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 644 | bool IsInteresting = ID & 0x01; |
| 645 | |
| 646 | // Wipe out the "is interesting" bit. |
| 647 | ID = ID >> 1; |
| 648 | |
| 649 | if (!IsInteresting) { |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 650 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 651 | // and associate it with the persistent ID. |
| 652 | IdentifierInfo *II = KnownII; |
| 653 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 654 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 655 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 656 | II->setIsFromAST(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 657 | return II; |
| 658 | } |
| 659 | |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 660 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 661 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 662 | Bits >>= 1; |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 663 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 664 | Bits >>= 1; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 665 | bool Poisoned = Bits & 0x01; |
| 666 | Bits >>= 1; |
| 667 | bool ExtensionToken = Bits & 0x01; |
| 668 | Bits >>= 1; |
| 669 | bool hasMacroDefinition = Bits & 0x01; |
| 670 | Bits >>= 1; |
| 671 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 672 | Bits >>= 10; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 673 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 674 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 675 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 676 | |
| 677 | // Build the IdentifierInfo itself and link the identifier ID with |
| 678 | // the new IdentifierInfo. |
| 679 | IdentifierInfo *II = KnownII; |
| 680 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 681 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 682 | Reader.SetIdentifierInfo(ID, II); |
| 683 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 684 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 685 | // Token IDs are read-only. |
| 686 | if (HasRevertedTokenIDToIdentifier) |
| 687 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 688 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 690 | "Incorrect extension token flag"); |
| 691 | (void)ExtensionToken; |
| 692 | II->setIsPoisoned(Poisoned); |
| 693 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 694 | "Incorrect C++ operator keyword flag"); |
| 695 | (void)CPlusPlusOperatorKeyword; |
| 696 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 697 | // If this identifier is a macro, deserialize the macro |
| 698 | // definition. |
| 699 | if (hasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 700 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 701 | Reader.SetIdentifierIsMacro(II, F, Offset); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 702 | DataLen -= 4; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 703 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 704 | |
| 705 | // Read all of the declarations visible at global scope with this |
| 706 | // name. |
Chris Lattner | 6bf690f | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 707 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 708 | if (DataLen > 0) { |
| 709 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 710 | for (; DataLen > 0; DataLen -= 4) |
| 711 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 712 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 713 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 714 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 715 | II->setIsFromAST(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 716 | return II; |
| 717 | } |
| 718 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 719 | |
| 720 | } // end anonymous namespace |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 721 | |
| 722 | /// \brief The on-disk hash table used to contain information about |
| 723 | /// all of the identifiers in the program. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 724 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 725 | ASTIdentifierLookupTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 726 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 727 | namespace { |
| 728 | class ASTDeclContextNameLookupTrait { |
| 729 | ASTReader &Reader; |
| 730 | |
| 731 | public: |
| 732 | /// \brief Pair of begin/end iterators for DeclIDs. |
| 733 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 734 | |
| 735 | /// \brief Special internal key for declaration names. |
| 736 | /// The hash table creates keys for comparison; we do not create |
| 737 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 738 | struct DeclNameKey { |
| 739 | DeclarationName::NameKind Kind; |
| 740 | uint64_t Data; |
| 741 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 742 | }; |
| 743 | |
| 744 | typedef DeclarationName external_key_type; |
| 745 | typedef DeclNameKey internal_key_type; |
| 746 | |
| 747 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
| 748 | |
| 749 | static bool EqualKey(const internal_key_type& a, |
| 750 | const internal_key_type& b) { |
| 751 | return a.Kind == b.Kind && a.Data == b.Data; |
| 752 | } |
| 753 | |
| 754 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 755 | llvm::FoldingSetNodeID ID; |
| 756 | ID.AddInteger(Key.Kind); |
| 757 | |
| 758 | switch (Key.Kind) { |
| 759 | case DeclarationName::Identifier: |
| 760 | case DeclarationName::CXXLiteralOperatorName: |
| 761 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 762 | break; |
| 763 | case DeclarationName::ObjCZeroArgSelector: |
| 764 | case DeclarationName::ObjCOneArgSelector: |
| 765 | case DeclarationName::ObjCMultiArgSelector: |
| 766 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 767 | break; |
| 768 | case DeclarationName::CXXConstructorName: |
| 769 | case DeclarationName::CXXDestructorName: |
| 770 | case DeclarationName::CXXConversionFunctionName: |
| 771 | ID.AddInteger((TypeID)Key.Data); |
| 772 | break; |
| 773 | case DeclarationName::CXXOperatorName: |
| 774 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 775 | break; |
| 776 | case DeclarationName::CXXUsingDirective: |
| 777 | break; |
| 778 | } |
| 779 | |
| 780 | return ID.ComputeHash(); |
| 781 | } |
| 782 | |
| 783 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 784 | DeclNameKey Key; |
| 785 | Key.Kind = Name.getNameKind(); |
| 786 | switch (Name.getNameKind()) { |
| 787 | case DeclarationName::Identifier: |
| 788 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 789 | break; |
| 790 | case DeclarationName::ObjCZeroArgSelector: |
| 791 | case DeclarationName::ObjCOneArgSelector: |
| 792 | case DeclarationName::ObjCMultiArgSelector: |
| 793 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 794 | break; |
| 795 | case DeclarationName::CXXConstructorName: |
| 796 | case DeclarationName::CXXDestructorName: |
| 797 | case DeclarationName::CXXConversionFunctionName: |
| 798 | Key.Data = Reader.GetTypeID(Name.getCXXNameType()); |
| 799 | break; |
| 800 | case DeclarationName::CXXOperatorName: |
| 801 | Key.Data = Name.getCXXOverloadedOperator(); |
| 802 | break; |
| 803 | case DeclarationName::CXXLiteralOperatorName: |
| 804 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 805 | break; |
| 806 | case DeclarationName::CXXUsingDirective: |
| 807 | break; |
| 808 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 809 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 810 | return Key; |
| 811 | } |
| 812 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 813 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 814 | ASTContext *Context = Reader.getContext(); |
| 815 | switch (Key.Kind) { |
| 816 | case DeclarationName::Identifier: |
| 817 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 818 | |
| 819 | case DeclarationName::ObjCZeroArgSelector: |
| 820 | case DeclarationName::ObjCOneArgSelector: |
| 821 | case DeclarationName::ObjCMultiArgSelector: |
| 822 | return DeclarationName(Selector(Key.Data)); |
| 823 | |
| 824 | case DeclarationName::CXXConstructorName: |
| 825 | return Context->DeclarationNames.getCXXConstructorName( |
| 826 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 827 | |
| 828 | case DeclarationName::CXXDestructorName: |
| 829 | return Context->DeclarationNames.getCXXDestructorName( |
| 830 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 831 | |
| 832 | case DeclarationName::CXXConversionFunctionName: |
| 833 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 834 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 835 | |
| 836 | case DeclarationName::CXXOperatorName: |
| 837 | return Context->DeclarationNames.getCXXOperatorName( |
| 838 | (OverloadedOperatorKind)Key.Data); |
| 839 | |
| 840 | case DeclarationName::CXXLiteralOperatorName: |
| 841 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 842 | (IdentifierInfo*)Key.Data); |
| 843 | |
| 844 | case DeclarationName::CXXUsingDirective: |
| 845 | return DeclarationName::getUsingDirectiveName(); |
| 846 | } |
| 847 | |
| 848 | llvm_unreachable("Invalid Name Kind ?"); |
| 849 | } |
| 850 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 851 | static std::pair<unsigned, unsigned> |
| 852 | ReadKeyDataLength(const unsigned char*& d) { |
| 853 | using namespace clang::io; |
| 854 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 855 | unsigned DataLen = ReadUnalignedLE16(d); |
| 856 | return std::make_pair(KeyLen, DataLen); |
| 857 | } |
| 858 | |
| 859 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 860 | using namespace clang::io; |
| 861 | |
| 862 | DeclNameKey Key; |
| 863 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 864 | switch (Key.Kind) { |
| 865 | case DeclarationName::Identifier: |
| 866 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 867 | break; |
| 868 | case DeclarationName::ObjCZeroArgSelector: |
| 869 | case DeclarationName::ObjCOneArgSelector: |
| 870 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 871 | Key.Data = |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 872 | (uint64_t)Reader.DecodeSelector(ReadUnalignedLE32(d)).getAsOpaquePtr(); |
| 873 | break; |
| 874 | case DeclarationName::CXXConstructorName: |
| 875 | case DeclarationName::CXXDestructorName: |
| 876 | case DeclarationName::CXXConversionFunctionName: |
| 877 | Key.Data = ReadUnalignedLE32(d); // TypeID |
| 878 | break; |
| 879 | case DeclarationName::CXXOperatorName: |
| 880 | Key.Data = *d++; // OverloadedOperatorKind |
| 881 | break; |
| 882 | case DeclarationName::CXXLiteralOperatorName: |
| 883 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 884 | break; |
| 885 | case DeclarationName::CXXUsingDirective: |
| 886 | break; |
| 887 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 888 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 889 | return Key; |
| 890 | } |
| 891 | |
| 892 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 893 | unsigned DataLen) { |
| 894 | using namespace clang::io; |
| 895 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 896 | DeclID *Start = (DeclID *)d; |
| 897 | return std::make_pair(Start, Start + NumDecls); |
| 898 | } |
| 899 | }; |
| 900 | |
| 901 | } // end anonymous namespace |
| 902 | |
| 903 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 904 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 905 | ASTDeclContextNameLookupTable; |
| 906 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 907 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 908 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 909 | DeclContextInfo &Info) { |
| 910 | SavedStreamPosition SavedPosition(Cursor); |
| 911 | // First the lexical decls. |
| 912 | if (Offsets.first != 0) { |
| 913 | Cursor.JumpToBit(Offsets.first); |
| 914 | |
| 915 | RecordData Record; |
| 916 | const char *Blob; |
| 917 | unsigned BlobLen; |
| 918 | unsigned Code = Cursor.ReadCode(); |
| 919 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 920 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 921 | Error("Expected lexical block"); |
| 922 | return true; |
| 923 | } |
| 924 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 925 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 926 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 927 | } else { |
| 928 | Info.LexicalDecls = 0; |
| 929 | Info.NumLexicalDecls = 0; |
| 930 | } |
| 931 | |
| 932 | // Now the lookup table. |
| 933 | if (Offsets.second != 0) { |
| 934 | Cursor.JumpToBit(Offsets.second); |
| 935 | |
| 936 | RecordData Record; |
| 937 | const char *Blob; |
| 938 | unsigned BlobLen; |
| 939 | unsigned Code = Cursor.ReadCode(); |
| 940 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 941 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 942 | Error("Expected visible lookup table block"); |
| 943 | return true; |
| 944 | } |
| 945 | Info.NameLookupTableData |
| 946 | = ASTDeclContextNameLookupTable::Create( |
| 947 | (const unsigned char *)Blob + Record[0], |
| 948 | (const unsigned char *)Blob, |
| 949 | ASTDeclContextNameLookupTrait(*this)); |
Sebastian Redl | 0ea8f7f | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 950 | } else { |
| 951 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | return false; |
| 955 | } |
| 956 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 957 | void ASTReader::Error(const char *Msg) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 958 | Diag(diag::err_fe_pch_malformed) << Msg; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 959 | } |
| 960 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 961 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 962 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 963 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 964 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 965 | ActualOriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 966 | SuggestedPredefines, |
| 967 | FileMgr); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 968 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 971 | //===----------------------------------------------------------------------===// |
| 972 | // Source Manager Deserialization |
| 973 | //===----------------------------------------------------------------------===// |
| 974 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 975 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 976 | /// \returns true if there was an error. |
| 977 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 978 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 979 | unsigned Idx = 0; |
| 980 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 981 | |
| 982 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 983 | std::map<int, int> FileIDs; |
| 984 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 985 | // Extract the file name |
| 986 | unsigned FilenameLen = Record[Idx++]; |
| 987 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 988 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 989 | MaybeAddSystemRootToFilename(Filename); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 991 | Filename.size()); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | // Parse the line entries |
| 995 | std::vector<LineEntry> Entries; |
| 996 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 997 | int FID = Record[Idx++]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 998 | |
| 999 | // Extract the line entries |
| 1000 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1001 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1002 | Entries.clear(); |
| 1003 | Entries.reserve(NumEntries); |
| 1004 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1005 | unsigned FileOffset = Record[Idx++]; |
| 1006 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1007 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1008 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1009 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1010 | unsigned IncludeOffset = Record[Idx++]; |
| 1011 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1012 | FileKind, IncludeOffset)); |
| 1013 | } |
| 1014 | LineTable.AddEntry(FID, Entries); |
| 1015 | } |
| 1016 | |
| 1017 | return false; |
| 1018 | } |
| 1019 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1020 | namespace { |
| 1021 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1022 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1023 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1024 | const ino_t ino; |
| 1025 | const dev_t dev; |
| 1026 | const mode_t mode; |
| 1027 | const time_t mtime; |
| 1028 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1029 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1030 | 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] | 1031 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1032 | }; |
| 1033 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1034 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1035 | public: |
| 1036 | typedef const char *external_key_type; |
| 1037 | typedef const char *internal_key_type; |
| 1038 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1039 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1040 | |
| 1041 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1042 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1046 | |
| 1047 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1048 | return strcmp(a, b) == 0; |
| 1049 | } |
| 1050 | |
| 1051 | static std::pair<unsigned, unsigned> |
| 1052 | ReadKeyDataLength(const unsigned char*& d) { |
| 1053 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1054 | unsigned DataLen = (unsigned) *d++; |
| 1055 | return std::make_pair(KeyLen + 1, DataLen); |
| 1056 | } |
| 1057 | |
| 1058 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1059 | return (const char *)d; |
| 1060 | } |
| 1061 | |
| 1062 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1063 | unsigned /*DataLen*/) { |
| 1064 | using namespace clang::io; |
| 1065 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1066 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1067 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1068 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1069 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1070 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1071 | return data_type(ino, dev, mode, mtime, size); |
| 1072 | } |
| 1073 | }; |
| 1074 | |
| 1075 | /// \brief stat() cache for precompiled headers. |
| 1076 | /// |
| 1077 | /// This cache is very similar to the stat cache used by pretokenized |
| 1078 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1079 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1080 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1081 | CacheTy *Cache; |
| 1082 | |
| 1083 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1084 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1085 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1086 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1087 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1088 | Cache = CacheTy::Create(Buckets, Base); |
| 1089 | } |
| 1090 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1091 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1092 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1093 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1094 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1095 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1096 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1097 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1098 | // 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] | 1099 | if (I == Cache->end()) { |
| 1100 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1101 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1102 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1103 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1104 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1105 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1107 | StatBuf.st_ino = Data.ino; |
| 1108 | StatBuf.st_dev = Data.dev; |
| 1109 | StatBuf.st_mtime = Data.mtime; |
| 1110 | StatBuf.st_mode = Data.mode; |
| 1111 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1112 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1113 | } |
| 1114 | }; |
| 1115 | } // end anonymous namespace |
| 1116 | |
| 1117 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1118 | /// \brief Read a source manager block |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1119 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1120 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1121 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1122 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1123 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1124 | // Set the source-location entry cursor to the current position in |
| 1125 | // the stream. This cursor will be used to read the contents of the |
| 1126 | // source manager block initially, and then lazily read |
| 1127 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1128 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1129 | |
| 1130 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1131 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1132 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1133 | return Failure; |
| 1134 | } |
| 1135 | |
| 1136 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1137 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1138 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1139 | return Failure; |
| 1140 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1141 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1142 | RecordData Record; |
| 1143 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1144 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1145 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1146 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1147 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1148 | return Failure; |
| 1149 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1150 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1151 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1152 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1153 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1154 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1155 | SLocEntryCursor.ReadSubBlockID(); |
| 1156 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1157 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1158 | return Failure; |
| 1159 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1160 | continue; |
| 1161 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1162 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1163 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1164 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1165 | continue; |
| 1166 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1167 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1168 | // Read a record. |
| 1169 | const char *BlobStart; |
| 1170 | unsigned BlobLen; |
| 1171 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1172 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1173 | default: // Default behavior: ignore. |
| 1174 | break; |
| 1175 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1176 | case SM_LINE_TABLE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1177 | if (ParseLineTable(F, Record)) |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1178 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1179 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1180 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1181 | case SM_SLOC_FILE_ENTRY: |
| 1182 | case SM_SLOC_BUFFER_ENTRY: |
| 1183 | case SM_SLOC_INSTANTIATION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1184 | // Once we hit one of the source location entries, we're done. |
| 1185 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1186 | } |
| 1187 | } |
| 1188 | } |
| 1189 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1190 | /// \brief If a header file is not found at the path that we expect it to be |
| 1191 | /// and the PCH file was moved from its original location, try to resolve the |
| 1192 | /// file by assuming that header+PCH were moved together and the header is in |
| 1193 | /// the same place relative to the PCH. |
| 1194 | static std::string |
| 1195 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1196 | const std::string &OriginalDir, |
| 1197 | const std::string &CurrDir) { |
| 1198 | assert(OriginalDir != CurrDir && |
| 1199 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1200 | using namespace llvm::sys; |
| 1201 | llvm::SmallString<128> filePath(Filename); |
| 1202 | fs::make_absolute(filePath); |
| 1203 | assert(path::is_absolute(OriginalDir)); |
| 1204 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1205 | |
| 1206 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1207 | fileDirE = path::end(path::parent_path(filePath)); |
| 1208 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1209 | origDirE = path::end(OriginalDir); |
| 1210 | // Skip the common path components from filePath and OriginalDir. |
| 1211 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1212 | *fileDirI == *origDirI) { |
| 1213 | ++fileDirI; |
| 1214 | ++origDirI; |
| 1215 | } |
| 1216 | for (; origDirI != origDirE; ++origDirI) |
| 1217 | path::append(currPCHPath, ".."); |
| 1218 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1219 | path::append(currPCHPath, path::filename(Filename)); |
| 1220 | return currPCHPath.str(); |
| 1221 | } |
| 1222 | |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1223 | /// \brief Get a cursor that's correctly positioned for reading the source |
| 1224 | /// location entry with the given ID. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1225 | ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1226 | assert(ID != 0 && ID <= TotalNumSLocEntries && |
| 1227 | "SLocCursorForID should only be called for real IDs."); |
| 1228 | |
| 1229 | ID -= 1; |
| 1230 | PerFileData *F = 0; |
| 1231 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1232 | F = Chain[N - I - 1]; |
| 1233 | if (ID < F->LocalNumSLocEntries) |
| 1234 | break; |
| 1235 | ID -= F->LocalNumSLocEntries; |
| 1236 | } |
| 1237 | assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); |
| 1238 | |
| 1239 | F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1240 | return F; |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1243 | /// \brief Read in the source location entry with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1244 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1245 | if (ID == 0) |
| 1246 | return Success; |
| 1247 | |
| 1248 | if (ID > TotalNumSLocEntries) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1249 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1250 | return Failure; |
| 1251 | } |
| 1252 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1253 | PerFileData *F = SLocCursorForID(ID); |
| 1254 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1255 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1256 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1257 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1258 | if (Code == llvm::bitc::END_BLOCK || |
| 1259 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1260 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1261 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1262 | return Failure; |
| 1263 | } |
| 1264 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1265 | RecordData Record; |
| 1266 | const char *BlobStart; |
| 1267 | unsigned BlobLen; |
| 1268 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1269 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1270 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1271 | return Failure; |
| 1272 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1273 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1274 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1275 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1276 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1277 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1278 | OriginalDir != CurrentDir) { |
| 1279 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1280 | OriginalDir, |
| 1281 | CurrentDir); |
| 1282 | if (!resolved.empty()) |
| 1283 | File = FileMgr.getFile(resolved); |
| 1284 | } |
Axel Naumann | 0433116 | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1285 | if (File == 0) |
| 1286 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1287 | (time_t)Record[5]); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1288 | if (File == 0) { |
| 1289 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1290 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1291 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1292 | Error(ErrorStr.c_str()); |
| 1293 | return Failure; |
| 1294 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1295 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1296 | if (Record.size() < 6) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1297 | Error("source location entry is incorrect"); |
| 1298 | return Failure; |
| 1299 | } |
| 1300 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1301 | if (!DisableValidation && |
| 1302 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1303 | #if !defined(LLVM_ON_WIN32) |
| 1304 | // In our regression testing, the Windows file system seems to |
| 1305 | // have inconsistent modification times that sometimes |
| 1306 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1307 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1308 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1309 | )) { |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1310 | Diag(diag::err_fe_pch_file_modified) |
| 1311 | << Filename; |
| 1312 | return Failure; |
| 1313 | } |
| 1314 | |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1315 | FileID FID = SourceMgr.createFileID(File, ReadSourceLocation(*F, Record[1]), |
| 1316 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1317 | ID, Record[0]); |
| 1318 | if (Record[3]) |
| 1319 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1320 | .setHasLineDirectives(); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1321 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1322 | break; |
| 1323 | } |
| 1324 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1325 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1326 | const char *Name = BlobStart; |
| 1327 | unsigned Offset = Record[0]; |
| 1328 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1329 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1331 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1332 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1333 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1334 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1335 | return Failure; |
| 1336 | } |
| 1337 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1338 | llvm::MemoryBuffer *Buffer |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1339 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1340 | Name); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1341 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1342 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1343 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1344 | PCHPredefinesBlock Block = { |
| 1345 | BufferID, |
| 1346 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1347 | }; |
| 1348 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1349 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1350 | |
| 1351 | break; |
| 1352 | } |
| 1353 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1354 | case SM_SLOC_INSTANTIATION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1355 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1356 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1357 | ReadSourceLocation(*F, Record[2]), |
| 1358 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1359 | Record[4], |
| 1360 | ID, |
| 1361 | Record[0]); |
| 1362 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1363 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | return Success; |
| 1367 | } |
| 1368 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1369 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1370 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1371 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1372 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1373 | unsigned BlockID) { |
| 1374 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1375 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1376 | return Failure; |
| 1377 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1378 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1379 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1380 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1381 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1382 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1383 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1384 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1385 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1386 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1387 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1388 | Cursor.ReadAbbrevRecord(); |
| 1389 | } |
| 1390 | } |
| 1391 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1392 | PreprocessedEntity *ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1393 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1394 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1395 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1396 | // Keep track of where we are in the stream, then jump back there |
| 1397 | // after reading this macro. |
| 1398 | SavedStreamPosition SavedPosition(Stream); |
| 1399 | |
| 1400 | Stream.JumpToBit(Offset); |
| 1401 | RecordData Record; |
| 1402 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1403 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1404 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1405 | while (true) { |
| 1406 | unsigned Code = Stream.ReadCode(); |
| 1407 | switch (Code) { |
| 1408 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1409 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1410 | |
| 1411 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1412 | // No known subblocks, always skip them. |
| 1413 | Stream.ReadSubBlockID(); |
| 1414 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1415 | Error("malformed block record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1416 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1417 | } |
| 1418 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1419 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1420 | case llvm::bitc::DEFINE_ABBREV: |
| 1421 | Stream.ReadAbbrevRecord(); |
| 1422 | continue; |
| 1423 | default: break; |
| 1424 | } |
| 1425 | |
| 1426 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1427 | const char *BlobStart = 0; |
| 1428 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1429 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1430 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1431 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1432 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1433 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1434 | case PP_MACRO_OBJECT_LIKE: |
| 1435 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1436 | // If we already have a macro, that means that we've hit the end |
| 1437 | // of the definition of the macro we were looking for. We're |
| 1438 | // done. |
| 1439 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1440 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1441 | |
| 1442 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1443 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1444 | Error("macro must have a name in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1445 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1446 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1447 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1448 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1449 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1450 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1451 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1452 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1453 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1454 | unsigned NextIndex = 3; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1455 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1456 | // Decode function-like macro info. |
| 1457 | bool isC99VarArgs = Record[3]; |
| 1458 | bool isGNUVarArgs = Record[4]; |
| 1459 | MacroArgs.clear(); |
| 1460 | unsigned NumArgs = Record[5]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1461 | NextIndex = 6 + NumArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1462 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1463 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1464 | |
| 1465 | // Install function-like macro info. |
| 1466 | MI->setIsFunctionLike(); |
| 1467 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1468 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1469 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1470 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1474 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1475 | |
| 1476 | // Remember that we saw this macro last so that we add the tokens that |
| 1477 | // form its body to it. |
| 1478 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1479 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1480 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1481 | // We have a macro definition. Load it now. |
| 1482 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1483 | getMacroDefinition(Record[NextIndex])); |
| 1484 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1485 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1486 | ++NumMacrosRead; |
| 1487 | break; |
| 1488 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1489 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1490 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1491 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1492 | // erroneous, just pretend we didn't see this. |
| 1493 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1494 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1495 | Token Tok; |
| 1496 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1497 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1498 | Tok.setLength(Record[1]); |
| 1499 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1500 | Tok.setIdentifierInfo(II); |
| 1501 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1502 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1503 | Macro->AddTokenToBody(Tok); |
| 1504 | break; |
| 1505 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1506 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1507 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1508 | |
| 1509 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1512 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(PerFileData &F) { |
| 1513 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1514 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1515 | switch (Code) { |
| 1516 | case llvm::bitc::END_BLOCK: |
| 1517 | return 0; |
| 1518 | |
| 1519 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1520 | Error("unexpected subblock record in preprocessor detail block"); |
| 1521 | return 0; |
| 1522 | |
| 1523 | case llvm::bitc::DEFINE_ABBREV: |
| 1524 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1525 | return 0; |
| 1526 | |
| 1527 | default: |
| 1528 | break; |
| 1529 | } |
| 1530 | |
| 1531 | if (!PP->getPreprocessingRecord()) { |
| 1532 | Error("no preprocessing record"); |
| 1533 | return 0; |
| 1534 | } |
| 1535 | |
| 1536 | // Read the record. |
| 1537 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1538 | const char *BlobStart = 0; |
| 1539 | unsigned BlobLen = 0; |
| 1540 | RecordData Record; |
| 1541 | PreprocessorDetailRecordTypes RecType = |
| 1542 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1543 | Code, Record, BlobStart, BlobLen); |
| 1544 | switch (RecType) { |
| 1545 | case PPD_MACRO_INSTANTIATION: { |
| 1546 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1547 | return PE; |
| 1548 | |
| 1549 | MacroInstantiation *MI |
| 1550 | = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), |
| 1551 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1552 | ReadSourceLocation(F, Record[2])), |
| 1553 | getMacroDefinition(Record[4])); |
| 1554 | PPRec.SetPreallocatedEntity(Record[0], MI); |
| 1555 | return MI; |
| 1556 | } |
| 1557 | |
| 1558 | case PPD_MACRO_DEFINITION: { |
| 1559 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1560 | return PE; |
| 1561 | |
| 1562 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
| 1563 | Error("out-of-bounds macro definition record"); |
| 1564 | return 0; |
| 1565 | } |
| 1566 | |
| 1567 | // Decode the identifier info and then check again; if the macro is |
| 1568 | // still defined and associated with the identifier, |
| 1569 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1570 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1571 | MacroDefinition *MD |
| 1572 | = new (PPRec) MacroDefinition(II, |
| 1573 | ReadSourceLocation(F, Record[5]), |
| 1574 | SourceRange( |
| 1575 | ReadSourceLocation(F, Record[2]), |
| 1576 | ReadSourceLocation(F, Record[3]))); |
| 1577 | |
| 1578 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1579 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
| 1580 | |
| 1581 | if (DeserializationListener) |
| 1582 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1583 | } |
| 1584 | |
| 1585 | return MacroDefinitionsLoaded[Record[1] - 1]; |
| 1586 | } |
| 1587 | |
| 1588 | case PPD_INCLUSION_DIRECTIVE: { |
| 1589 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1590 | return PE; |
| 1591 | |
| 1592 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1593 | const FileEntry *File |
| 1594 | = PP->getFileManager().getFile(llvm::StringRef(FullFileNameStart, |
| 1595 | BlobLen - Record[3])); |
| 1596 | |
| 1597 | // FIXME: Stable encoding |
| 1598 | InclusionDirective::InclusionKind Kind |
| 1599 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1600 | InclusionDirective *ID |
| 1601 | = new (PPRec) InclusionDirective(PPRec, Kind, |
| 1602 | llvm::StringRef(BlobStart, Record[3]), |
| 1603 | Record[4], |
| 1604 | File, |
| 1605 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1606 | ReadSourceLocation(F, Record[2]))); |
| 1607 | PPRec.SetPreallocatedEntity(Record[0], ID); |
| 1608 | return ID; |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | Error("invalid offset in preprocessor detail block"); |
| 1613 | return 0; |
| 1614 | } |
| 1615 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1616 | namespace { |
| 1617 | /// \brief Trait class used to search the on-disk hash table containing all of |
| 1618 | /// the header search information. |
| 1619 | /// |
| 1620 | /// The on-disk hash table contains a mapping from each header path to |
| 1621 | /// information about that header (how many times it has been included, its |
| 1622 | /// controlling macro, etc.). Note that we actually hash based on the |
| 1623 | /// filename, and support "deep" comparisons of file names based on current |
| 1624 | /// inode numbers, so that the search can cope with non-normalized path names |
| 1625 | /// and symlinks. |
| 1626 | class HeaderFileInfoTrait { |
| 1627 | const char *SearchPath; |
| 1628 | struct stat SearchPathStatBuf; |
| 1629 | llvm::Optional<int> SearchPathStatResult; |
| 1630 | |
| 1631 | int StatSimpleCache(const char *Path, struct stat *StatBuf) { |
| 1632 | if (Path == SearchPath) { |
| 1633 | if (!SearchPathStatResult) |
| 1634 | SearchPathStatResult = stat(Path, &SearchPathStatBuf); |
| 1635 | |
| 1636 | *StatBuf = SearchPathStatBuf; |
| 1637 | return *SearchPathStatResult; |
| 1638 | } |
| 1639 | |
| 1640 | return stat(Path, StatBuf); |
| 1641 | } |
| 1642 | |
| 1643 | public: |
| 1644 | typedef const char *external_key_type; |
| 1645 | typedef const char *internal_key_type; |
| 1646 | |
| 1647 | typedef HeaderFileInfo data_type; |
| 1648 | |
| 1649 | HeaderFileInfoTrait(const char *SearchPath = 0) : SearchPath(SearchPath) { } |
| 1650 | |
| 1651 | static unsigned ComputeHash(const char *path) { |
| 1652 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1653 | } |
| 1654 | |
| 1655 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1656 | |
| 1657 | bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1658 | if (strcmp(a, b) == 0) |
| 1659 | return true; |
| 1660 | |
| 1661 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1662 | return false; |
| 1663 | |
| 1664 | // The file names match, but the path names don't. stat() the files to |
| 1665 | // see if they are the same. |
| 1666 | struct stat StatBufA, StatBufB; |
| 1667 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1668 | return false; |
| 1669 | |
| 1670 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1671 | } |
| 1672 | |
| 1673 | static std::pair<unsigned, unsigned> |
| 1674 | ReadKeyDataLength(const unsigned char*& d) { |
| 1675 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1676 | unsigned DataLen = (unsigned) *d++; |
| 1677 | return std::make_pair(KeyLen + 1, DataLen); |
| 1678 | } |
| 1679 | |
| 1680 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1681 | return (const char *)d; |
| 1682 | } |
| 1683 | |
| 1684 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1685 | unsigned DataLen) { |
| 1686 | const unsigned char *End = d + DataLen; |
| 1687 | using namespace clang::io; |
| 1688 | HeaderFileInfo HFI; |
| 1689 | unsigned Flags = *d++; |
| 1690 | HFI.isImport = (Flags >> 3) & 0x01; |
| 1691 | HFI.DirInfo = (Flags >> 1) & 0x03; |
| 1692 | HFI.Resolved = Flags & 0x01; |
| 1693 | HFI.NumIncludes = ReadUnalignedLE16(d); |
| 1694 | HFI.ControllingMacroID = ReadUnalignedLE32(d); |
| 1695 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1696 | (void)End; |
| 1697 | |
| 1698 | // This HeaderFileInfo was externally loaded. |
| 1699 | HFI.External = true; |
| 1700 | return HFI; |
| 1701 | } |
| 1702 | }; |
| 1703 | } |
| 1704 | |
| 1705 | /// \brief The on-disk hash table used for the global method pool. |
| 1706 | typedef OnDiskChainedHashTable<HeaderFileInfoTrait> |
| 1707 | HeaderFileInfoLookupTable; |
| 1708 | |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1709 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F, |
| 1710 | uint64_t Offset) { |
| 1711 | // Note that this identifier has a macro definition. |
| 1712 | II->setHasMacroDefinition(true); |
| 1713 | |
| 1714 | // Adjust the offset based on our position in the chain. |
| 1715 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1716 | if (Chain[I] == &F) |
| 1717 | break; |
| 1718 | |
| 1719 | Offset += Chain[I]->SizeInBits; |
| 1720 | } |
| 1721 | |
| 1722 | UnreadMacroRecordOffsets[II] = Offset; |
| 1723 | } |
| 1724 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1725 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1726 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1727 | PerFileData &F = *Chain[N - I - 1]; |
| 1728 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1729 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1730 | // If there was no preprocessor block, skip this file. |
| 1731 | if (!MacroCursor.getBitStreamReader()) |
| 1732 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1733 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1734 | llvm::BitstreamCursor Cursor = MacroCursor; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1735 | Cursor.JumpToBit(F.MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1736 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1737 | RecordData Record; |
| 1738 | while (true) { |
| 1739 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1740 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1741 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1742 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1743 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1744 | // No known subblocks, always skip them. |
| 1745 | Cursor.ReadSubBlockID(); |
| 1746 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1747 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1748 | return; |
| 1749 | } |
| 1750 | continue; |
| 1751 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1752 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1753 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1754 | Cursor.ReadAbbrevRecord(); |
| 1755 | continue; |
| 1756 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1757 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1758 | // Read a record. |
| 1759 | const char *BlobStart; |
| 1760 | unsigned BlobLen; |
| 1761 | Record.clear(); |
| 1762 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1763 | default: // Default behavior: ignore. |
| 1764 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1765 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1766 | case PP_MACRO_OBJECT_LIKE: |
| 1767 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1768 | DecodeIdentifierInfo(Record[0]); |
| 1769 | break; |
| 1770 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1771 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1772 | // Ignore tokens. |
| 1773 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1774 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1775 | } |
| 1776 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1777 | |
| 1778 | // Drain the unread macro-record offsets map. |
| 1779 | while (!UnreadMacroRecordOffsets.empty()) |
| 1780 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1781 | } |
| 1782 | |
| 1783 | void ASTReader::LoadMacroDefinition( |
| 1784 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1785 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
| 1786 | PerFileData *F = 0; |
| 1787 | uint64_t Offset = Pos->second; |
| 1788 | UnreadMacroRecordOffsets.erase(Pos); |
| 1789 | |
| 1790 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1791 | if (Offset < Chain[I]->SizeInBits) { |
| 1792 | F = Chain[I]; |
| 1793 | break; |
| 1794 | } |
| 1795 | |
| 1796 | Offset -= Chain[I]->SizeInBits; |
| 1797 | } |
| 1798 | if (!F) { |
| 1799 | Error("Malformed macro record offset"); |
| 1800 | return; |
| 1801 | } |
| 1802 | |
| 1803 | ReadMacroRecord(*F, Offset); |
| 1804 | } |
| 1805 | |
| 1806 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1807 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1808 | = UnreadMacroRecordOffsets.find(II); |
| 1809 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1810 | } |
| 1811 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1812 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1813 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1814 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1815 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1816 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1817 | unsigned Index = ID - 1; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1818 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1819 | PerFileData &F = *Chain[N - I - 1]; |
| 1820 | if (Index < F.LocalNumMacroDefinitions) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1821 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 1822 | F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]); |
| 1823 | LoadPreprocessedEntity(F); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1824 | break; |
| 1825 | } |
| 1826 | Index -= F.LocalNumMacroDefinitions; |
| 1827 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1828 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1831 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1834 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1835 | /// not an absolute path, add the system root to the beginning of the file |
| 1836 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1837 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1838 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1839 | if (!RelocatablePCH) |
| 1840 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1841 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1842 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1843 | return; |
| 1844 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1845 | if (isysroot == 0) { |
| 1846 | // If no system root was given, default to '/' |
| 1847 | Filename.insert(Filename.begin(), '/'); |
| 1848 | return; |
| 1849 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1850 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1851 | unsigned Length = strlen(isysroot); |
| 1852 | if (isysroot[Length - 1] != '/') |
| 1853 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1854 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1855 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1856 | } |
| 1857 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1858 | ASTReader::ASTReadResult |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1859 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1860 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1861 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1862 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1863 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1864 | return Failure; |
| 1865 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1866 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1867 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1868 | RecordData Record; |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1869 | bool First = true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1870 | while (!Stream.AtEndOfStream()) { |
| 1871 | unsigned Code = Stream.ReadCode(); |
| 1872 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1873 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1874 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1875 | return Failure; |
| 1876 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1877 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1878 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1882 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1883 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1884 | // We lazily load the decls block, but we want to set up the |
| 1885 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1886 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1887 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1888 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1889 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1890 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1891 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1892 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1893 | return Failure; |
| 1894 | } |
| 1895 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1896 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1897 | case DECL_UPDATES_BLOCK_ID: |
| 1898 | if (Stream.SkipBlock()) { |
| 1899 | Error("malformed block record in AST file"); |
| 1900 | return Failure; |
| 1901 | } |
| 1902 | break; |
| 1903 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1904 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1905 | F.MacroCursor = Stream; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1906 | if (PP) |
| 1907 | PP->setExternalSource(this); |
| 1908 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1909 | if (Stream.SkipBlock() || |
| 1910 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1911 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1912 | return Failure; |
| 1913 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1914 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1915 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1916 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1917 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1918 | F.PreprocessorDetailCursor = Stream; |
| 1919 | if (Stream.SkipBlock() || |
| 1920 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1921 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1922 | Error("malformed preprocessor detail record in AST file"); |
| 1923 | return Failure; |
| 1924 | } |
| 1925 | F.PreprocessorDetailStartOffset |
| 1926 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 1927 | break; |
| 1928 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1929 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1930 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1931 | case Success: |
| 1932 | break; |
| 1933 | |
| 1934 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1935 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1936 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1937 | |
| 1938 | case IgnorePCH: |
| 1939 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1940 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1941 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1942 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1943 | First = false; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1944 | continue; |
| 1945 | } |
| 1946 | |
| 1947 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1948 | Stream.ReadAbbrevRecord(); |
| 1949 | continue; |
| 1950 | } |
| 1951 | |
| 1952 | // Read and process a record. |
| 1953 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1954 | const char *BlobStart = 0; |
| 1955 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1956 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1957 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1958 | default: // Default behavior: ignore. |
| 1959 | break; |
| 1960 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1961 | case METADATA: { |
| 1962 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1963 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1964 | : diag::warn_pch_version_too_new); |
| 1965 | return IgnorePCH; |
| 1966 | } |
| 1967 | |
| 1968 | RelocatablePCH = Record[4]; |
| 1969 | if (Listener) { |
| 1970 | std::string TargetTriple(BlobStart, BlobLen); |
| 1971 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1972 | return IgnorePCH; |
| 1973 | } |
| 1974 | break; |
| 1975 | } |
| 1976 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1977 | case CHAINED_METADATA: { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1978 | if (!First) { |
| 1979 | Error("CHAINED_METADATA is not first record in block"); |
| 1980 | return Failure; |
| 1981 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1982 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1983 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1984 | : diag::warn_pch_version_too_new); |
| 1985 | return IgnorePCH; |
| 1986 | } |
| 1987 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 1988 | // Load the chained file, which is always a PCH file. |
| 1989 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1990 | case Failure: return Failure; |
| 1991 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1992 | case IgnorePCH: return IgnorePCH; |
| 1993 | case Success: break; |
| 1994 | } |
| 1995 | break; |
| 1996 | } |
| 1997 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1998 | case TYPE_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1999 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2000 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2001 | return Failure; |
| 2002 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2003 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 2004 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2005 | break; |
| 2006 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2007 | case DECL_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2008 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2009 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2010 | return Failure; |
| 2011 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2012 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 2013 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2014 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2015 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2016 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2017 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2018 | /* No visible information */ 0, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2019 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 2020 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2021 | }; |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2022 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 2023 | .push_back(Info); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2024 | break; |
| 2025 | } |
| 2026 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2027 | case UPDATE_VISIBLE: { |
| 2028 | serialization::DeclID ID = Record[0]; |
| 2029 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 2030 | (const unsigned char *)BlobStart + Record[1], |
| 2031 | (const unsigned char *)BlobStart, |
| 2032 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2033 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2034 | DeclContextInfo Info = { |
| 2035 | Table, /* No lexical inforamtion */ 0, 0 |
| 2036 | }; |
| 2037 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 2038 | } else |
| 2039 | PendingVisibleUpdates[ID].push_back(Table); |
| 2040 | break; |
| 2041 | } |
| 2042 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2043 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2044 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 2045 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2046 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2047 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 2048 | Latest > FirstLatestDeclIDs[First]) && |
| 2049 | "The new latest is supposed to come after the previous latest"); |
| 2050 | FirstLatestDeclIDs[First] = Latest; |
| 2051 | } |
| 2052 | break; |
| 2053 | } |
| 2054 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2055 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2056 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2057 | return IgnorePCH; |
| 2058 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2059 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2060 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2061 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2062 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2063 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2064 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2065 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2066 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2067 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2068 | if (PP) |
| 2069 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2070 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2071 | break; |
| 2072 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2073 | case IDENTIFIER_OFFSET: |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2074 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2075 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2076 | return Failure; |
| 2077 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2078 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2079 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2080 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2081 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2082 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2083 | // Optimization for the first block. |
| 2084 | if (ExternalDefinitions.empty()) |
| 2085 | ExternalDefinitions.swap(Record); |
| 2086 | else |
| 2087 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 2088 | Record.begin(), Record.end()); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2089 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2090 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2091 | case SPECIAL_TYPES: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2092 | // Optimization for the first block |
| 2093 | if (SpecialTypes.empty()) |
| 2094 | SpecialTypes.swap(Record); |
| 2095 | else |
| 2096 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2097 | break; |
| 2098 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2099 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2100 | TotalNumStatements += Record[0]; |
| 2101 | TotalNumMacros += Record[1]; |
| 2102 | TotalLexicalDeclContexts += Record[2]; |
| 2103 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2104 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2105 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2106 | case TENTATIVE_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2107 | // Optimization for the first block. |
| 2108 | if (TentativeDefinitions.empty()) |
| 2109 | TentativeDefinitions.swap(Record); |
| 2110 | else |
| 2111 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 2112 | Record.begin(), Record.end()); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2113 | break; |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2114 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2115 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2116 | // Optimization for the first block. |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2117 | if (UnusedFileScopedDecls.empty()) |
| 2118 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2119 | else |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2120 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 2121 | Record.begin(), Record.end()); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2122 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2123 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2124 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2125 | // Later blocks overwrite earlier ones. |
| 2126 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2127 | break; |
| 2128 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2129 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2130 | // Optimization for the first block. |
| 2131 | if (LocallyScopedExternalDecls.empty()) |
| 2132 | LocallyScopedExternalDecls.swap(Record); |
| 2133 | else |
| 2134 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 2135 | Record.begin(), Record.end()); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2136 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2137 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2138 | case SELECTOR_OFFSETS: |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2139 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2140 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2141 | break; |
| 2142 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2143 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2144 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2145 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2146 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2147 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2148 | F.SelectorLookupTableData + Record[0], |
| 2149 | F.SelectorLookupTableData, |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2150 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2151 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2152 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2153 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2154 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2155 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2156 | break; |
| 2157 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2158 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2159 | if (!Record.empty() && Listener) |
| 2160 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2161 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2162 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2163 | case SOURCE_LOCATION_OFFSETS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2164 | F.SLocOffsets = (const uint32_t *)BlobStart; |
| 2165 | F.LocalNumSLocEntries = Record[0]; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2166 | F.LocalSLocSize = Record[1]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2167 | break; |
| 2168 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2169 | case SOURCE_LOCATION_PRELOADS: |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2170 | if (PreloadSLocEntries.empty()) |
| 2171 | PreloadSLocEntries.swap(Record); |
| 2172 | else |
| 2173 | PreloadSLocEntries.insert(PreloadSLocEntries.end(), |
| 2174 | Record.begin(), Record.end()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2175 | break; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2176 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2177 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2178 | if (!DisableStatCache) { |
| 2179 | ASTStatCache *MyStatCache = |
| 2180 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2181 | (const unsigned char *)BlobStart, |
| 2182 | NumStatHits, NumStatMisses); |
| 2183 | FileMgr.addStatCache(MyStatCache); |
| 2184 | F.StatCache = MyStatCache; |
| 2185 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2186 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2187 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2188 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2189 | case EXT_VECTOR_DECLS: |
Sebastian Redl | a9f2368 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 2190 | // Optimization for the first block. |
| 2191 | if (ExtVectorDecls.empty()) |
| 2192 | ExtVectorDecls.swap(Record); |
| 2193 | else |
| 2194 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 2195 | Record.begin(), Record.end()); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2196 | break; |
| 2197 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2198 | case VTABLE_USES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2199 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2200 | VTableUses.swap(Record); |
| 2201 | break; |
| 2202 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2203 | case DYNAMIC_CLASSES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2204 | // Optimization for the first block. |
| 2205 | if (DynamicClasses.empty()) |
| 2206 | DynamicClasses.swap(Record); |
| 2207 | else |
| 2208 | DynamicClasses.insert(DynamicClasses.end(), |
| 2209 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2210 | break; |
| 2211 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2212 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2213 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2214 | break; |
| 2215 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2216 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2217 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2218 | SemaDeclRefs.swap(Record); |
| 2219 | break; |
| 2220 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2221 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2222 | // 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] | 2223 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2224 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2225 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2226 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2227 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2228 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2229 | case ORIGINAL_PCH_DIR: |
| 2230 | // The primary AST will be the last to get here, so it will be the one |
| 2231 | // that's used. |
| 2232 | OriginalDir.assign(BlobStart, BlobLen); |
| 2233 | break; |
| 2234 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2235 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2236 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2237 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 2238 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2239 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2240 | return IgnorePCH; |
| 2241 | } |
| 2242 | break; |
| 2243 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2244 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2245 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2246 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2247 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2248 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2249 | break; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2250 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2251 | case DECL_UPDATE_OFFSETS: { |
| 2252 | if (Record.size() % 2 != 0) { |
| 2253 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2254 | return Failure; |
| 2255 | } |
| 2256 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
| 2257 | DeclUpdateOffsets[static_cast<DeclID>(Record[I])] |
| 2258 | .push_back(std::make_pair(&F, Record[I+1])); |
| 2259 | break; |
| 2260 | } |
| 2261 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2262 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2263 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2264 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2265 | return Failure; |
| 2266 | } |
| 2267 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2268 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2269 | std::make_pair(&F, Record[I+1]); |
| 2270 | break; |
| 2271 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2272 | |
| 2273 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2274 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2275 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2276 | return Failure; |
| 2277 | } |
| 2278 | |
| 2279 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2280 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
| 2281 | break; |
| 2282 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2283 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2284 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2285 | if (Record.size() % 2 != 0) { |
| 2286 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2287 | return Failure; |
| 2288 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2289 | if (PragmaDiagMappings.empty()) |
| 2290 | PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2291 | else |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2292 | PragmaDiagMappings.insert(PragmaDiagMappings.end(), |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2293 | Record.begin(), Record.end()); |
| 2294 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2295 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2296 | case CUDA_SPECIAL_DECL_REFS: |
| 2297 | // Later tables overwrite earlier ones. |
| 2298 | CUDASpecialDeclRefs.swap(Record); |
| 2299 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2300 | |
| 2301 | case HEADER_SEARCH_TABLE: |
| 2302 | F.HeaderFileInfoTableData = BlobStart; |
| 2303 | F.LocalNumHeaderFileInfos = Record[1]; |
| 2304 | if (Record[0]) { |
| 2305 | F.HeaderFileInfoTable |
| 2306 | = HeaderFileInfoLookupTable::Create( |
| 2307 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 2308 | (const unsigned char *)F.HeaderFileInfoTableData); |
| 2309 | if (PP) |
| 2310 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2311 | } |
| 2312 | break; |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2313 | |
| 2314 | case FP_PRAGMA_OPTIONS: |
| 2315 | // Later tables overwrite earlier ones. |
| 2316 | FPPragmaOptions.swap(Record); |
| 2317 | break; |
| 2318 | |
| 2319 | case OPENCL_EXTENSIONS: |
| 2320 | // Later tables overwrite earlier ones. |
| 2321 | OpenCLExtensions.swap(Record); |
| 2322 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2323 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2324 | First = false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2325 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2326 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2327 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2330 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2331 | ASTFileType Type) { |
| 2332 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2333 | case Failure: return Failure; |
| 2334 | case IgnorePCH: return IgnorePCH; |
| 2335 | case Success: break; |
| 2336 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2337 | |
| 2338 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2339 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2340 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2341 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2342 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2343 | TotalNumSelectors = 0; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2344 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2345 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2346 | NextSLocOffset += Chain[I]->LocalSLocSize; |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2347 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2348 | TotalNumTypes += Chain[I]->LocalNumTypes; |
| 2349 | TotalNumDecls += Chain[I]->LocalNumDecls; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2350 | TotalNumPreallocatedPreprocessingEntities += |
| 2351 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2352 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2353 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2354 | } |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2355 | SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset); |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2356 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2357 | TypesLoaded.resize(TotalNumTypes); |
| 2358 | DeclsLoaded.resize(TotalNumDecls); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2359 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2360 | if (PP) { |
| 2361 | if (TotalNumIdentifiers > 0) |
| 2362 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2363 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2364 | if (!PP->getPreprocessingRecord()) |
| 2365 | PP->createPreprocessingRecord(); |
| 2366 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2367 | TotalNumPreallocatedPreprocessingEntities); |
| 2368 | } |
| 2369 | } |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2370 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2371 | // Preload SLocEntries. |
| 2372 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2373 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2374 | if (Result != Success) |
| 2375 | return Result; |
| 2376 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2377 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2378 | // Check the predefines buffers. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2379 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2380 | return IgnorePCH; |
| 2381 | |
| 2382 | if (PP) { |
| 2383 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2384 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2385 | // loaded into the IdentifierTable before we intercepted the |
| 2386 | // creation of identifiers. Iterate through the list of known |
| 2387 | // identifiers and determine whether we have to establish |
| 2388 | // preprocessor definitions or top-level identifier declaration |
| 2389 | // chains for those identifiers. |
| 2390 | // |
| 2391 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2392 | // since de-serializing declarations or macro definitions can add |
| 2393 | // new entries into the identifier table, invalidating the |
| 2394 | // iterators. |
| 2395 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2396 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2397 | IdEnd = PP->getIdentifierTable().end(); |
| 2398 | Id != IdEnd; ++Id) |
| 2399 | Identifiers.push_back(Id->second); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2400 | // We need to search the tables in all files. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2401 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2402 | ASTIdentifierLookupTable *IdTable |
| 2403 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2404 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2405 | // ones. |
| 2406 | if (!IdTable) |
| 2407 | continue; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2408 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2409 | IdentifierInfo *II = Identifiers[I]; |
| 2410 | // 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] | 2411 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2412 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2413 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2414 | if (Pos == IdTable->end()) |
| 2415 | continue; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2416 | |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2417 | // Dereferencing the iterator has the effect of populating the |
| 2418 | // IdentifierInfo node with the various declarations it needs. |
| 2419 | (void)*Pos; |
| 2420 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2421 | } |
| 2422 | } |
| 2423 | |
| 2424 | if (Context) |
| 2425 | InitializeContext(*Context); |
| 2426 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2427 | if (DeserializationListener) |
| 2428 | DeserializationListener->ReaderInitialized(this); |
| 2429 | |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2430 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2431 | // the source manager to the file source file from which the preamble was |
| 2432 | // built. This is the only valid way to use a precompiled preamble. |
| 2433 | if (Type == Preamble) { |
| 2434 | SourceLocation Loc |
| 2435 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2436 | if (Loc.isValid()) { |
| 2437 | std::pair<FileID, unsigned> Decomposed = SourceMgr.getDecomposedLoc(Loc); |
| 2438 | SourceMgr.SetPreambleFileID(Decomposed.first); |
| 2439 | } |
| 2440 | } |
| 2441 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2442 | return Success; |
| 2443 | } |
| 2444 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2445 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2446 | ASTFileType Type) { |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2447 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2448 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2449 | PerFileData &F = *Chain.back(); |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2450 | if (Prev) |
| 2451 | Prev->NextInSource = &F; |
| 2452 | else |
| 2453 | FirstInSource = &F; |
| 2454 | F.Loaders.push_back(Prev); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2455 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2456 | // Set the AST file name. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2457 | F.FileName = FileName; |
| 2458 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2459 | if (FileName != "-") { |
| 2460 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2461 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2462 | } |
| 2463 | |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame^] | 2464 | if (!ASTBuffers.empty()) { |
| 2465 | F.Buffer.reset(ASTBuffers.front()); |
| 2466 | ASTBuffers.pop_front(); |
| 2467 | assert(F.Buffer && "Passed null buffer"); |
| 2468 | } else { |
| 2469 | // Open the AST file. |
| 2470 | // |
| 2471 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2472 | std::string ErrStr; |
| 2473 | llvm::error_code ec; |
| 2474 | if (FileName == "-") { |
| 2475 | ec = llvm::MemoryBuffer::getSTDIN(F.Buffer); |
| 2476 | if (ec) |
| 2477 | ErrStr = ec.message(); |
| 2478 | } else |
| 2479 | F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr)); |
| 2480 | if (!F.Buffer) { |
| 2481 | Error(ErrStr.c_str()); |
| 2482 | return IgnorePCH; |
| 2483 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | // Initialize the stream |
| 2487 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2488 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2489 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2490 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2491 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2492 | |
| 2493 | // Sniff for the signature. |
| 2494 | if (Stream.Read(8) != 'C' || |
| 2495 | Stream.Read(8) != 'P' || |
| 2496 | Stream.Read(8) != 'C' || |
| 2497 | Stream.Read(8) != 'H') { |
| 2498 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2499 | return Failure; |
| 2500 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2501 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2502 | while (!Stream.AtEndOfStream()) { |
| 2503 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2504 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2505 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2506 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2507 | return Failure; |
| 2508 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2509 | |
| 2510 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2511 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2512 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2513 | switch (BlockID) { |
| 2514 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2515 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2516 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2517 | return Failure; |
| 2518 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2519 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2520 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2521 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2522 | case Success: |
| 2523 | break; |
| 2524 | |
| 2525 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2526 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2527 | |
| 2528 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2529 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2530 | // AST block, skipping subblocks, to see if there are other |
| 2531 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2532 | |
| 2533 | // Clear out any preallocated source location entries, so that |
| 2534 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2535 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2536 | |
| 2537 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2538 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2539 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2540 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2541 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2542 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2543 | break; |
| 2544 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2545 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2546 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2547 | return Failure; |
| 2548 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2551 | } |
| 2552 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2553 | return Success; |
| 2554 | } |
| 2555 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2556 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2557 | PP = &pp; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2558 | |
| 2559 | unsigned TotalNum = 0; |
| 2560 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2561 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2562 | if (TotalNum) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2563 | if (!PP->getPreprocessingRecord()) |
| 2564 | PP->createPreprocessingRecord(); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2565 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2566 | } |
| 2567 | } |
| 2568 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2569 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2570 | Context = &Ctx; |
| 2571 | assert(Context && "Passed null context!"); |
| 2572 | |
| 2573 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2574 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2575 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2576 | PP->setExternalSource(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2577 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2578 | |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2579 | // If we have an update block for the TU waiting, we have to add it before |
| 2580 | // deserializing the decl. |
| 2581 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2582 | if (DCU != DeclContextOffsets.end()) { |
| 2583 | // Insertion could invalidate map, so grab vector. |
| 2584 | DeclContextInfos T; |
| 2585 | T.swap(DCU->second); |
| 2586 | DeclContextOffsets.erase(DCU); |
| 2587 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2588 | } |
| 2589 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2590 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2591 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2592 | |
| 2593 | // Load the special types. |
| 2594 | Context->setBuiltinVaListType( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2595 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2596 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2597 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2598 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2599 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2600 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2601 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2602 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2603 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2604 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2605 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2606 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2607 | if (unsigned FastEnum |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2608 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2609 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2610 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2611 | QualType FileType = GetType(File); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2612 | if (FileType.isNull()) { |
| 2613 | Error("FILE type is NULL"); |
| 2614 | return; |
| 2615 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2616 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2617 | Context->setFILEDecl(Typedef->getDecl()); |
| 2618 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2619 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2620 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2621 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2622 | return; |
| 2623 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2624 | Context->setFILEDecl(Tag->getDecl()); |
| 2625 | } |
| 2626 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2627 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2628 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2629 | if (Jmp_bufType.isNull()) { |
| 2630 | Error("jmp_bug type is NULL"); |
| 2631 | return; |
| 2632 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2633 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2634 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2635 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2636 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2637 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2638 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2639 | return; |
| 2640 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2641 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2642 | } |
| 2643 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2644 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2645 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2646 | if (Sigjmp_bufType.isNull()) { |
| 2647 | Error("sigjmp_buf type is NULL"); |
| 2648 | return; |
| 2649 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2650 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2651 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2652 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2653 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2654 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2655 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2656 | } |
| 2657 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2658 | if (unsigned ObjCIdRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2659 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2660 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2661 | if (unsigned ObjCClassRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2662 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2663 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2664 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2665 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2666 | if (unsigned String |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2667 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2668 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2669 | if (unsigned ObjCSelRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2670 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2671 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2672 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2673 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2674 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2675 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2676 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2677 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2678 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2679 | |
| 2680 | // If there were any CUDA special declarations, deserialize them. |
| 2681 | if (!CUDASpecialDeclRefs.empty()) { |
| 2682 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 2683 | Context->setcudaConfigureCallDecl( |
| 2684 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2685 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2686 | } |
| 2687 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2688 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2689 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2690 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2691 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2692 | FileManager &FileMgr, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2693 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2694 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2695 | std::string ErrStr; |
| 2696 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2697 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2698 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2699 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2700 | return std::string(); |
| 2701 | } |
| 2702 | |
| 2703 | // Initialize the stream |
| 2704 | llvm::BitstreamReader StreamFile; |
| 2705 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2706 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2707 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2708 | Stream.init(StreamFile); |
| 2709 | |
| 2710 | // Sniff for the signature. |
| 2711 | if (Stream.Read(8) != 'C' || |
| 2712 | Stream.Read(8) != 'P' || |
| 2713 | Stream.Read(8) != 'C' || |
| 2714 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2715 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2716 | return std::string(); |
| 2717 | } |
| 2718 | |
| 2719 | RecordData Record; |
| 2720 | while (!Stream.AtEndOfStream()) { |
| 2721 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2722 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2723 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2724 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2725 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2726 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2727 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2728 | case AST_BLOCK_ID: |
| 2729 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2730 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2731 | return std::string(); |
| 2732 | } |
| 2733 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2734 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2735 | default: |
| 2736 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2737 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2738 | return std::string(); |
| 2739 | } |
| 2740 | break; |
| 2741 | } |
| 2742 | continue; |
| 2743 | } |
| 2744 | |
| 2745 | if (Code == llvm::bitc::END_BLOCK) { |
| 2746 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2747 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2748 | return std::string(); |
| 2749 | } |
| 2750 | continue; |
| 2751 | } |
| 2752 | |
| 2753 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2754 | Stream.ReadAbbrevRecord(); |
| 2755 | continue; |
| 2756 | } |
| 2757 | |
| 2758 | Record.clear(); |
| 2759 | const char *BlobStart = 0; |
| 2760 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2761 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2762 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2763 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2764 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2765 | |
| 2766 | return std::string(); |
| 2767 | } |
| 2768 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2769 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2770 | /// structure. |
| 2771 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2772 | /// This routine parses the language options from the AST file and then gives |
| 2773 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2774 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2775 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2776 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2777 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2778 | if (Listener) { |
| 2779 | LangOptions LangOpts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2780 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2781 | #define PARSE_LANGOPT(Option) \ |
| 2782 | LangOpts.Option = Record[Idx]; \ |
| 2783 | ++Idx |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2784 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2785 | unsigned Idx = 0; |
| 2786 | PARSE_LANGOPT(Trigraphs); |
| 2787 | PARSE_LANGOPT(BCPLComment); |
| 2788 | PARSE_LANGOPT(DollarIdents); |
| 2789 | PARSE_LANGOPT(AsmPreprocessor); |
| 2790 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2791 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2792 | PARSE_LANGOPT(ImplicitInt); |
| 2793 | PARSE_LANGOPT(Digraphs); |
| 2794 | PARSE_LANGOPT(HexFloats); |
| 2795 | PARSE_LANGOPT(C99); |
| 2796 | PARSE_LANGOPT(Microsoft); |
| 2797 | PARSE_LANGOPT(CPlusPlus); |
| 2798 | PARSE_LANGOPT(CPlusPlus0x); |
| 2799 | PARSE_LANGOPT(CXXOperatorNames); |
| 2800 | PARSE_LANGOPT(ObjC1); |
| 2801 | PARSE_LANGOPT(ObjC2); |
| 2802 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 2803 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 2804 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 2805 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 2806 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2807 | PARSE_LANGOPT(PascalStrings); |
| 2808 | PARSE_LANGOPT(WritableStrings); |
| 2809 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2810 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2811 | PARSE_LANGOPT(Exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 2812 | PARSE_LANGOPT(ObjCExceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 2813 | PARSE_LANGOPT(CXXExceptions); |
| 2814 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 2815 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2816 | PARSE_LANGOPT(NeXTRuntime); |
| 2817 | PARSE_LANGOPT(Freestanding); |
| 2818 | PARSE_LANGOPT(NoBuiltin); |
| 2819 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 2820 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2821 | PARSE_LANGOPT(Blocks); |
| 2822 | PARSE_LANGOPT(EmitAllDecls); |
| 2823 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2824 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 2825 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2826 | PARSE_LANGOPT(HeinousExtensions); |
| 2827 | PARSE_LANGOPT(Optimize); |
| 2828 | PARSE_LANGOPT(OptimizeSize); |
| 2829 | PARSE_LANGOPT(Static); |
| 2830 | PARSE_LANGOPT(PICLevel); |
| 2831 | PARSE_LANGOPT(GNUInline); |
| 2832 | PARSE_LANGOPT(NoInline); |
| 2833 | PARSE_LANGOPT(AccessControl); |
| 2834 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2835 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | b1bdced | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 2836 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2837 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2838 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 2839 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2840 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2841 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2842 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 2843 | PARSE_LANGOPT(CUDA); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2844 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2845 | PARSE_LANGOPT(DefaultFPContract); |
Roman Divacky | 1c51b1c | 2011-03-01 17:36:40 +0000 | [diff] [blame] | 2846 | PARSE_LANGOPT(ElideConstructors); |
| 2847 | PARSE_LANGOPT(SpellChecking); |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 2848 | PARSE_LANGOPT(MRTD); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2849 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2850 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2851 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2852 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2853 | |
| 2854 | return false; |
| 2855 | } |
| 2856 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2857 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2858 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2859 | PerFileData &F = *Chain[I]; |
| 2860 | if (!F.PreprocessorDetailCursor.getBitStreamReader()) |
| 2861 | continue; |
| 2862 | |
| 2863 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 2864 | F.PreprocessorDetailCursor.JumpToBit(F.PreprocessorDetailStartOffset); |
| 2865 | while (LoadPreprocessedEntity(F)) { } |
| 2866 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2867 | } |
| 2868 | |
Douglas Gregor | 0a48029 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 2869 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2870 | PerFileData *F = 0; |
| 2871 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2872 | if (Offset < Chain[I]->SizeInBits) { |
| 2873 | F = Chain[I]; |
| 2874 | break; |
| 2875 | } |
| 2876 | |
| 2877 | Offset -= Chain[I]->SizeInBits; |
| 2878 | } |
| 2879 | |
| 2880 | if (!F) { |
| 2881 | Error("Malformed preprocessed entity offset"); |
| 2882 | return 0; |
| 2883 | } |
| 2884 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2885 | // Keep track of where we are in the stream, then jump back there |
| 2886 | // after reading this entity. |
| 2887 | SavedStreamPosition SavedPosition(F->PreprocessorDetailCursor); |
| 2888 | F->PreprocessorDetailCursor.JumpToBit(Offset); |
| 2889 | return LoadPreprocessedEntity(*F); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2890 | } |
| 2891 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2892 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
| 2893 | HeaderFileInfoTrait Trait(FE->getName()); |
| 2894 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2895 | PerFileData &F = *Chain[I]; |
| 2896 | HeaderFileInfoLookupTable *Table |
| 2897 | = static_cast<HeaderFileInfoLookupTable *>(F.HeaderFileInfoTable); |
| 2898 | if (!Table) |
| 2899 | continue; |
| 2900 | |
| 2901 | // Look in the on-disk hash table for an entry for this file name. |
| 2902 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE->getName(), |
| 2903 | &Trait); |
| 2904 | if (Pos == Table->end()) |
| 2905 | continue; |
| 2906 | |
| 2907 | HeaderFileInfo HFI = *Pos; |
| 2908 | if (Listener) |
| 2909 | Listener->ReadHeaderFileInfo(HFI, FE->getUID()); |
| 2910 | |
| 2911 | return HFI; |
| 2912 | } |
| 2913 | |
| 2914 | return HeaderFileInfo(); |
| 2915 | } |
| 2916 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2917 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2918 | unsigned Idx = 0; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2919 | while (Idx < PragmaDiagMappings.size()) { |
| 2920 | SourceLocation |
| 2921 | Loc = SourceLocation::getFromRawEncoding(PragmaDiagMappings[Idx++]); |
| 2922 | while (1) { |
| 2923 | assert(Idx < PragmaDiagMappings.size() && |
| 2924 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 2925 | if (Idx >= PragmaDiagMappings.size()) |
| 2926 | break; // Something is messed up but at least avoid infinite loop in |
| 2927 | // release build. |
| 2928 | unsigned DiagID = PragmaDiagMappings[Idx++]; |
| 2929 | if (DiagID == (unsigned)-1) |
| 2930 | break; // no more diag/map pairs for this location. |
| 2931 | diag::Mapping Map = (diag::Mapping)PragmaDiagMappings[Idx++]; |
| 2932 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 2933 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2934 | } |
| 2935 | } |
| 2936 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2937 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2938 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2939 | PerFileData *F = 0; |
| 2940 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2941 | F = Chain[N - I - 1]; |
| 2942 | if (Index < F->LocalNumTypes) |
| 2943 | break; |
| 2944 | Index -= F->LocalNumTypes; |
| 2945 | } |
| 2946 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2947 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2951 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2952 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 2953 | /// routine actually reads the record corresponding to the type at the given |
| 2954 | /// location. It is a helper routine for GetType, which deals with reading type |
| 2955 | /// IDs. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2956 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2957 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2958 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2959 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2960 | // Keep track of where we are in the stream, then jump back there |
| 2961 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2962 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2963 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 2964 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 2965 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2966 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 2967 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2968 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2969 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2970 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2971 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2972 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 2973 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2974 | if (Record.size() != 2) { |
| 2975 | Error("Incorrect encoding of extended qualifier type"); |
| 2976 | return QualType(); |
| 2977 | } |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2978 | QualType Base = GetType(Record[0]); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2979 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 2980 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2981 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2982 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2983 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2984 | if (Record.size() != 1) { |
| 2985 | Error("Incorrect encoding of complex type"); |
| 2986 | return QualType(); |
| 2987 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2988 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2989 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2990 | } |
| 2991 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2992 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2993 | if (Record.size() != 1) { |
| 2994 | Error("Incorrect encoding of pointer type"); |
| 2995 | return QualType(); |
| 2996 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2997 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2998 | return Context->getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2999 | } |
| 3000 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3001 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3002 | if (Record.size() != 1) { |
| 3003 | Error("Incorrect encoding of block pointer type"); |
| 3004 | return QualType(); |
| 3005 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3006 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3007 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3008 | } |
| 3009 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3010 | case TYPE_LVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3011 | if (Record.size() != 1) { |
| 3012 | Error("Incorrect encoding of lvalue reference type"); |
| 3013 | return QualType(); |
| 3014 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3015 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3016 | return Context->getLValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3017 | } |
| 3018 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3019 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3020 | if (Record.size() != 1) { |
| 3021 | Error("Incorrect encoding of rvalue reference type"); |
| 3022 | return QualType(); |
| 3023 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3024 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3025 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3026 | } |
| 3027 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3028 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3029 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3030 | Error("Incorrect encoding of member pointer type"); |
| 3031 | return QualType(); |
| 3032 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3033 | QualType PointeeType = GetType(Record[0]); |
| 3034 | QualType ClassType = GetType(Record[1]); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3035 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3036 | return QualType(); |
| 3037 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3038 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3039 | } |
| 3040 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3041 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3042 | QualType ElementType = GetType(Record[0]); |
| 3043 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3044 | unsigned IndexTypeQuals = Record[2]; |
| 3045 | unsigned Idx = 3; |
| 3046 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3047 | return Context->getConstantArrayType(ElementType, Size, |
| 3048 | ASM, IndexTypeQuals); |
| 3049 | } |
| 3050 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3051 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3052 | QualType ElementType = GetType(Record[0]); |
| 3053 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3054 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3055 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3058 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3059 | QualType ElementType = GetType(Record[0]); |
| 3060 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3061 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3062 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3063 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 3064 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3065 | ASM, IndexTypeQuals, |
| 3066 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3067 | } |
| 3068 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3069 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3070 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3071 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3072 | return QualType(); |
| 3073 | } |
| 3074 | |
| 3075 | QualType ElementType = GetType(Record[0]); |
| 3076 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3077 | unsigned VecKind = Record[2]; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3078 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3079 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3080 | } |
| 3081 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3082 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3083 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3084 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3085 | return QualType(); |
| 3086 | } |
| 3087 | |
| 3088 | QualType ElementType = GetType(Record[0]); |
| 3089 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3090 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3091 | } |
| 3092 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3093 | case TYPE_FUNCTION_NO_PROTO: { |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3094 | if (Record.size() != 4) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3095 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3096 | return QualType(); |
| 3097 | } |
| 3098 | QualType ResultType = GetType(Record[0]); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3099 | FunctionType::ExtInfo Info(Record[1], Record[2], (CallingConv)Record[3]); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 3100 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3101 | } |
| 3102 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3103 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3104 | QualType ResultType = GetType(Record[0]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3105 | |
| 3106 | FunctionProtoType::ExtProtoInfo EPI; |
| 3107 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
| 3108 | /*regparm*/ Record[2], |
| 3109 | static_cast<CallingConv>(Record[3])); |
| 3110 | |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3111 | unsigned Idx = 4; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3112 | unsigned NumParams = Record[Idx++]; |
| 3113 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 3114 | for (unsigned I = 0; I != NumParams; ++I) |
| 3115 | ParamTypes.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3116 | |
| 3117 | EPI.Variadic = Record[Idx++]; |
| 3118 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3119 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 8b5b409 | 2011-03-06 10:52:04 +0000 | [diff] [blame] | 3120 | bool HasExceptionSpec = Record[Idx++]; |
| 3121 | bool HasAnyExceptionSpec = Record[Idx++]; |
| 3122 | EPI.ExceptionSpecType = HasExceptionSpec ? |
| 3123 | (HasAnyExceptionSpec ? EST_DynamicAny : EST_Dynamic) : EST_None; |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3124 | EPI.NumExceptions = Record[Idx++]; |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 3125 | llvm::SmallVector<QualType, 2> Exceptions; |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3126 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 3127 | Exceptions.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3128 | EPI.Exceptions = Exceptions.data(); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 3129 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3130 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3131 | } |
| 3132 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3133 | case TYPE_UNRESOLVED_USING: |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3134 | return Context->getTypeDeclType( |
| 3135 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 3136 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3137 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3138 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3139 | Error("incorrect encoding of typedef type"); |
| 3140 | return QualType(); |
| 3141 | } |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3142 | TypedefDecl *Decl = cast<TypedefDecl>(GetDecl(Record[0])); |
| 3143 | QualType Canonical = GetType(Record[1]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3144 | if (!Canonical.isNull()) |
| 3145 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3146 | return Context->getTypedefType(Decl, Canonical); |
| 3147 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3148 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3149 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3150 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3151 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3152 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3153 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3154 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3155 | return QualType(); |
| 3156 | } |
| 3157 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3158 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3159 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3160 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3161 | case TYPE_DECLTYPE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3162 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3163 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3164 | case TYPE_AUTO: |
| 3165 | return Context->getAutoType(GetType(Record[0])); |
| 3166 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3167 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3168 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3169 | Error("incorrect encoding of record type"); |
| 3170 | return QualType(); |
| 3171 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3172 | bool IsDependent = Record[0]; |
| 3173 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3174 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3175 | return T; |
| 3176 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3177 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3178 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3179 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3180 | Error("incorrect encoding of enum type"); |
| 3181 | return QualType(); |
| 3182 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3183 | bool IsDependent = Record[0]; |
| 3184 | QualType T = Context->getEnumType(cast<EnumDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3185 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3186 | return T; |
| 3187 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3188 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3189 | case TYPE_ATTRIBUTED: { |
| 3190 | if (Record.size() != 3) { |
| 3191 | Error("incorrect encoding of attributed type"); |
| 3192 | return QualType(); |
| 3193 | } |
| 3194 | QualType modifiedType = GetType(Record[0]); |
| 3195 | QualType equivalentType = GetType(Record[1]); |
| 3196 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 3197 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 3198 | } |
| 3199 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3200 | case TYPE_PAREN: { |
| 3201 | if (Record.size() != 1) { |
| 3202 | Error("incorrect encoding of paren type"); |
| 3203 | return QualType(); |
| 3204 | } |
| 3205 | QualType InnerType = GetType(Record[0]); |
| 3206 | return Context->getParenType(InnerType); |
| 3207 | } |
| 3208 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3209 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3210 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3211 | Error("incorrect encoding of pack expansion type"); |
| 3212 | return QualType(); |
| 3213 | } |
| 3214 | QualType Pattern = GetType(Record[0]); |
| 3215 | if (Pattern.isNull()) |
| 3216 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3217 | llvm::Optional<unsigned> NumExpansions; |
| 3218 | if (Record[1]) |
| 3219 | NumExpansions = Record[1] - 1; |
| 3220 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3221 | } |
| 3222 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3223 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3224 | unsigned Idx = 0; |
| 3225 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3226 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3227 | QualType NamedType = GetType(Record[Idx++]); |
| 3228 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3229 | } |
| 3230 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3231 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3232 | unsigned Idx = 0; |
| 3233 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3234 | return Context->getObjCInterfaceType(ItfD); |
| 3235 | } |
| 3236 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3237 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3238 | unsigned Idx = 0; |
| 3239 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3240 | unsigned NumProtos = Record[Idx++]; |
| 3241 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 3242 | for (unsigned I = 0; I != NumProtos; ++I) |
| 3243 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3244 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3245 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3246 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3247 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3248 | unsigned Idx = 0; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3249 | QualType Pointee = GetType(Record[Idx++]); |
| 3250 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3251 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3252 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3253 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3254 | unsigned Idx = 0; |
| 3255 | QualType Parm = GetType(Record[Idx++]); |
| 3256 | QualType Replacement = GetType(Record[Idx++]); |
| 3257 | return |
| 3258 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3259 | Replacement); |
| 3260 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3261 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3262 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3263 | unsigned Idx = 0; |
| 3264 | QualType Parm = GetType(Record[Idx++]); |
| 3265 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3266 | return Context->getSubstTemplateTypeParmPackType( |
| 3267 | cast<TemplateTypeParmType>(Parm), |
| 3268 | ArgPack); |
| 3269 | } |
| 3270 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3271 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3272 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 3273 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3274 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3275 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3276 | return |
| 3277 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3278 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3279 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3280 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3281 | unsigned Idx = 0; |
| 3282 | unsigned Depth = Record[Idx++]; |
| 3283 | unsigned Index = Record[Idx++]; |
| 3284 | bool Pack = Record[Idx++]; |
| 3285 | IdentifierInfo *Name = GetIdentifierInfo(Record, Idx); |
| 3286 | return Context->getTemplateTypeParmType(Depth, Index, Pack, Name); |
| 3287 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3288 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3289 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3290 | unsigned Idx = 0; |
| 3291 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3292 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3293 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3294 | QualType Canon = GetType(Record[Idx++]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3295 | if (!Canon.isNull()) |
| 3296 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3297 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3298 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3299 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3300 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3301 | unsigned Idx = 0; |
| 3302 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3303 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3304 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
| 3305 | unsigned NumArgs = Record[Idx++]; |
| 3306 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 3307 | Args.reserve(NumArgs); |
| 3308 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3309 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3310 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3311 | Args.size(), Args.data()); |
| 3312 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3313 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3314 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3315 | unsigned Idx = 0; |
| 3316 | |
| 3317 | // ArrayType |
| 3318 | QualType ElementType = GetType(Record[Idx++]); |
| 3319 | ArrayType::ArraySizeModifier ASM |
| 3320 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3321 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3322 | |
| 3323 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3324 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3325 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3326 | |
| 3327 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3328 | IndexTypeQuals, Brackets); |
| 3329 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3330 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3331 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3332 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3333 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3334 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3335 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3336 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3337 | QualType Canon = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3338 | QualType T; |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3339 | if (Canon.isNull()) |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3340 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3341 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3342 | else |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3343 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
| 3344 | Args.size(), Canon); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3345 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3346 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3347 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3348 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3349 | // Suppress a GCC warning |
| 3350 | return QualType(); |
| 3351 | } |
| 3352 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3353 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3354 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3355 | ASTReader::PerFileData &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3356 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3357 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3358 | unsigned &Idx; |
| 3359 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3360 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3361 | unsigned &I) { |
| 3362 | return Reader.ReadSourceLocation(F, R, I); |
| 3363 | } |
| 3364 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3365 | public: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3366 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3367 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3368 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3369 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3370 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3371 | // We want compile-time assurance that we've enumerated all of |
| 3372 | // these, so unfortunately we have to declare them first, then |
| 3373 | // define them out-of-line. |
| 3374 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3375 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3376 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3377 | #include "clang/AST/TypeLocNodes.def" |
| 3378 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3379 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3380 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3381 | }; |
| 3382 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3383 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3384 | // nothing to do |
| 3385 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3386 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3387 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3388 | if (TL.needsExtraLocalData()) { |
| 3389 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3390 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3391 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3392 | TL.setModeAttr(Record[Idx++]); |
| 3393 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3394 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3395 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3396 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3397 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3398 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3399 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3400 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3401 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3402 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3403 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3404 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3405 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3406 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3407 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3408 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3409 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3410 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3411 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3412 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, 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::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3415 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3416 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3417 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3418 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3419 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3420 | TL.setSizeExpr(0); |
| 3421 | } |
| 3422 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3423 | VisitArrayTypeLoc(TL); |
| 3424 | } |
| 3425 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3426 | VisitArrayTypeLoc(TL); |
| 3427 | } |
| 3428 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3429 | VisitArrayTypeLoc(TL); |
| 3430 | } |
| 3431 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3432 | DependentSizedArrayTypeLoc TL) { |
| 3433 | VisitArrayTypeLoc(TL); |
| 3434 | } |
| 3435 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3436 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3437 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3438 | } |
| 3439 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3440 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3441 | } |
| 3442 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3443 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3444 | } |
| 3445 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3446 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3447 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3448 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3449 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | 86acc2a | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 3450 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3451 | } |
| 3452 | } |
| 3453 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3454 | VisitFunctionTypeLoc(TL); |
| 3455 | } |
| 3456 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3457 | VisitFunctionTypeLoc(TL); |
| 3458 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3459 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3460 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3461 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3462 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3463 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3464 | } |
| 3465 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3466 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3467 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3468 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3469 | } |
| 3470 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3471 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3472 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3473 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3474 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3475 | } |
| 3476 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3477 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3478 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3479 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3480 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3481 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3482 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3483 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3484 | } |
| 3485 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3486 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3487 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3488 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3489 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3490 | if (TL.hasAttrOperand()) { |
| 3491 | SourceRange range; |
| 3492 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3493 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3494 | TL.setAttrOperandParensRange(range); |
| 3495 | } |
| 3496 | if (TL.hasAttrExprOperand()) { |
| 3497 | if (Record[Idx++]) |
| 3498 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3499 | else |
| 3500 | TL.setAttrExprOperand(0); |
| 3501 | } else if (TL.hasAttrEnumOperand()) |
| 3502 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3503 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3504 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3505 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3506 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3507 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3508 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3509 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3510 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3511 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3512 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3513 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3514 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3515 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3516 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3517 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3518 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3519 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3520 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3521 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3522 | Reader.GetTemplateArgumentLocInfo(F, |
| 3523 | TL.getTypePtr()->getArg(i).getKind(), |
| 3524 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3525 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3526 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3527 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3528 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3529 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3530 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3531 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3532 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3533 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3534 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3535 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3536 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3537 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3538 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3539 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3540 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3541 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3542 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3543 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3544 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3545 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3546 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3547 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3548 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3549 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3550 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3551 | Reader.GetTemplateArgumentLocInfo(F, |
| 3552 | TL.getTypePtr()->getArg(I).getKind(), |
| 3553 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3554 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3555 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3556 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3557 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3558 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3559 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3560 | } |
| 3561 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3562 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3563 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3564 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3565 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3566 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3567 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3568 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3569 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3570 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3571 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3572 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3573 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3574 | unsigned &Idx) { |
| 3575 | QualType InfoTy = GetType(Record[Idx++]); |
| 3576 | if (InfoTy.isNull()) |
| 3577 | return 0; |
| 3578 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3579 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3580 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3581 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3582 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3583 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3584 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3585 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3586 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3587 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3588 | unsigned Index = ID >> Qualifiers::FastWidth; |
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 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3591 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3592 | switch ((PredefinedTypeIDs)Index) { |
| 3593 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3594 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3595 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3596 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3597 | case PREDEF_TYPE_CHAR_U_ID: |
| 3598 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3599 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3600 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3601 | break; |
| 3602 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3603 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3604 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3605 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3606 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3607 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3608 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3609 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3610 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3611 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3612 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3613 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3614 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3615 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3616 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3617 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3618 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3619 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
| 3620 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
| 3621 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3622 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3623 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3624 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3625 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3626 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3627 | } |
| 3628 | |
| 3629 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3630 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3631 | } |
| 3632 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3633 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3634 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3635 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3636 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3637 | if (TypesLoaded[Index].isNull()) |
| 3638 | return QualType(); |
| 3639 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3640 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3641 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3642 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3643 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3644 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3645 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3646 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3647 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3648 | } |
| 3649 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3650 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3651 | return MakeTypeID(T, |
| 3652 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3653 | } |
| 3654 | |
| 3655 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3656 | if (T.isNull()) |
| 3657 | return TypeIdx(); |
| 3658 | assert(!T.getLocalFastQualifiers()); |
| 3659 | |
| 3660 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3661 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3662 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3663 | // If the type didn't come from the AST file use a specially marked index |
| 3664 | // so that any hash/key comparison fail since no such index is stored |
| 3665 | // in a AST file. |
| 3666 | if (I == TypeIdxs.end()) |
| 3667 | return TypeIdx(-1); |
| 3668 | return I->second; |
| 3669 | } |
| 3670 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3671 | unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const { |
| 3672 | unsigned Result = 0; |
| 3673 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 3674 | Result += Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3675 | |
| 3676 | return Result; |
| 3677 | } |
| 3678 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3679 | TemplateArgumentLocInfo |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3680 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3681 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3682 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3683 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3684 | switch (Kind) { |
| 3685 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3686 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3687 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3688 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3689 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3690 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3691 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3692 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3693 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3694 | SourceLocation()); |
| 3695 | } |
| 3696 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3697 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3698 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3699 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3700 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3701 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3702 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3703 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3704 | case TemplateArgument::Null: |
| 3705 | case TemplateArgument::Integral: |
| 3706 | case TemplateArgument::Declaration: |
| 3707 | case TemplateArgument::Pack: |
| 3708 | return TemplateArgumentLocInfo(); |
| 3709 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3710 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3711 | return TemplateArgumentLocInfo(); |
| 3712 | } |
| 3713 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3714 | TemplateArgumentLoc |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3715 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3716 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3717 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3718 | |
| 3719 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3720 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3721 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3722 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3723 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3724 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3725 | } |
| 3726 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3727 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3728 | return GetDecl(ID); |
| 3729 | } |
| 3730 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3731 | uint64_t |
| 3732 | ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) { |
| 3733 | if (ID == 0) |
| 3734 | return 0; |
| 3735 | |
| 3736 | --ID; |
| 3737 | uint64_t Offset = 0; |
| 3738 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3739 | PerFileData &F = *Chain[N - I - 1]; |
| 3740 | |
| 3741 | if (ID < F.LocalNumCXXBaseSpecifiers) |
| 3742 | return Offset + F.CXXBaseSpecifiersOffsets[ID]; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3743 | |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3744 | ID -= F.LocalNumCXXBaseSpecifiers; |
| 3745 | Offset += F.SizeInBits; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | assert(false && "CXXBaseSpecifiers not found"); |
| 3749 | return 0; |
| 3750 | } |
| 3751 | |
| 3752 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 3753 | // Figure out which AST file contains this offset. |
| 3754 | PerFileData *F = 0; |
| 3755 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3756 | if (Offset < Chain[N - I - 1]->SizeInBits) { |
| 3757 | F = Chain[N - I - 1]; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3758 | break; |
| 3759 | } |
| 3760 | |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3761 | Offset -= Chain[N - I - 1]->SizeInBits; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3762 | } |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3763 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3764 | if (!F) { |
| 3765 | Error("Malformed AST file: C++ base specifiers at impossible offset"); |
| 3766 | return 0; |
| 3767 | } |
| 3768 | |
| 3769 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3770 | SavedStreamPosition SavedPosition(Cursor); |
| 3771 | Cursor.JumpToBit(Offset); |
| 3772 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3773 | RecordData Record; |
| 3774 | unsigned Code = Cursor.ReadCode(); |
| 3775 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 3776 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 3777 | Error("Malformed AST file: missing C++ base specifiers"); |
| 3778 | return 0; |
| 3779 | } |
| 3780 | |
| 3781 | unsigned Idx = 0; |
| 3782 | unsigned NumBases = Record[Idx++]; |
| 3783 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 3784 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 3785 | for (unsigned I = 0; I != NumBases; ++I) |
| 3786 | Bases[I] = ReadCXXBaseSpecifier(*F, Record, Idx); |
| 3787 | return Bases; |
| 3788 | } |
| 3789 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3790 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3791 | if (!DeclsLoaded[0]) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 3792 | ReadDeclRecord(0, 1); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3793 | if (DeserializationListener) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3794 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3795 | } |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 3796 | |
| 3797 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 3798 | } |
| 3799 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3800 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3801 | if (ID == 0) |
| 3802 | return 0; |
| 3803 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3804 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3805 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3806 | return 0; |
| 3807 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3808 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3809 | unsigned Index = ID - 1; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3810 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3811 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3812 | if (DeserializationListener) |
| 3813 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3814 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3815 | |
| 3816 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3817 | } |
| 3818 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3819 | /// \brief Resolve the offset of a statement into a statement. |
| 3820 | /// |
| 3821 | /// This operation will read a new statement from the external |
| 3822 | /// source each time it is called, and is meant to be used via a |
| 3823 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3824 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 3825 | // Switch case IDs are per Decl. |
| 3826 | ClearSwitchCaseIDs(); |
| 3827 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3828 | // Offset here is a global offset across the entire chain. |
| 3829 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3830 | PerFileData &F = *Chain[N - I - 1]; |
| 3831 | if (Offset < F.SizeInBits) { |
| 3832 | // Since we know that this statement is part of a decl, make sure to use |
| 3833 | // the decl cursor to read it. |
| 3834 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3835 | return ReadStmtFromStream(F); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3836 | } |
| 3837 | Offset -= F.SizeInBits; |
| 3838 | } |
| 3839 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 3840 | } |
| 3841 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3842 | bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3843 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3844 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3845 | assert(DC->hasExternalLexicalStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3846 | "DeclContext has no lexical decls in storage"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3847 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3848 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 3849 | // at least. |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3850 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 3851 | // so make a copy of the vector. |
| 3852 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3853 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3854 | I != E; ++I) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3855 | // IDs can be 0 if this context doesn't contain declarations. |
| 3856 | if (!I->LexicalDecls) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3857 | continue; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3858 | |
| 3859 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3860 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 3861 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 3862 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 3863 | continue; |
| 3864 | |
| 3865 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3866 | assert(D && "Null decl in lexical decls"); |
| 3867 | Decls.push_back(D); |
| 3868 | } |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3869 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3870 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3871 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3872 | return false; |
| 3873 | } |
| 3874 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3875 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3876 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3877 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3878 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3879 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3880 | if (!Name) |
| 3881 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 3882 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3883 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3884 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 8b12273 | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 3885 | // 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] | 3886 | // and namespaces. For any given name, the last available results replace |
| 3887 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3888 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3889 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3890 | I != E; ++I) { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3891 | if (!I->NameLookupTableData) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3892 | continue; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3893 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3894 | ASTDeclContextNameLookupTable *LookupTable = |
| 3895 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3896 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 3897 | if (Pos == LookupTable->end()) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3898 | continue; |
| 3899 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3900 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 3901 | for (; Data.first != Data.second; ++Data.first) |
| 3902 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3903 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3904 | } |
| 3905 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3906 | ++NumVisibleDeclContextsRead; |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3907 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3908 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3909 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3910 | } |
| 3911 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 3912 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 3913 | assert(DC->hasExternalVisibleStorage() && |
| 3914 | "DeclContext has no visible decls in storage"); |
| 3915 | |
| 3916 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 3917 | // There might be visible decls in multiple parts of the chain, for the TU |
| 3918 | // and namespaces. |
| 3919 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 3920 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3921 | I != E; ++I) { |
| 3922 | if (!I->NameLookupTableData) |
| 3923 | continue; |
| 3924 | |
| 3925 | ASTDeclContextNameLookupTable *LookupTable = |
| 3926 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3927 | for (ASTDeclContextNameLookupTable::item_iterator |
| 3928 | ItemI = LookupTable->item_begin(), |
| 3929 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 3930 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 3931 | = *ItemI; |
| 3932 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 3933 | Decls.clear(); |
| 3934 | for (; Data.first != Data.second; ++Data.first) |
| 3935 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 3936 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 3937 | } |
| 3938 | } |
| 3939 | } |
| 3940 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3941 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3942 | assert(Consumer); |
| 3943 | while (!InterestingDecls.empty()) { |
| 3944 | DeclGroupRef DG(InterestingDecls.front()); |
| 3945 | InterestingDecls.pop_front(); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3946 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3947 | } |
| 3948 | } |
| 3949 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3950 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 3951 | this->Consumer = Consumer; |
| 3952 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3953 | if (!Consumer) |
| 3954 | return; |
| 3955 | |
| 3956 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3957 | // Force deserialization of this decl, which will cause it to be queued for |
| 3958 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 3959 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3960 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 3961 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3962 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3963 | } |
| 3964 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3965 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3966 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3967 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3968 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3969 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3970 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3971 | unsigned NumDeclsLoaded |
| 3972 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 3973 | (Decl *)0); |
| 3974 | unsigned NumIdentifiersLoaded |
| 3975 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 3976 | IdentifiersLoaded.end(), |
| 3977 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3978 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3979 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 3980 | SelectorsLoaded.end(), |
| 3981 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 3982 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3983 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 3984 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 3985 | if (TotalNumSLocEntries) |
| 3986 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 3987 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 3988 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3989 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3990 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3991 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 3992 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 3993 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3994 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3995 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 3996 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3997 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3998 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3999 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4000 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4001 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4002 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4003 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4004 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4005 | if (TotalNumStatements) |
| 4006 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4007 | NumStatementsRead, TotalNumStatements, |
| 4008 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4009 | if (TotalNumMacros) |
| 4010 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4011 | NumMacrosRead, TotalNumMacros, |
| 4012 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4013 | if (TotalLexicalDeclContexts) |
| 4014 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4015 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4016 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4017 | * 100)); |
| 4018 | if (TotalVisibleDeclContexts) |
| 4019 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4020 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4021 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4022 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4023 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4024 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4025 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4026 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4027 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4028 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4029 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4030 | std::fprintf(stderr, "\n"); |
| 4031 | } |
| 4032 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4033 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4034 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4035 | S.ExternalSource = this; |
| 4036 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4037 | // Makes sure any declarations that were deserialized "too early" |
| 4038 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4039 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4040 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4041 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4042 | |
| 4043 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4044 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4045 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4046 | |
| 4047 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4048 | // them to Sema's list of tentative definitions. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4049 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4050 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4051 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4052 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 4053 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4054 | // If there were any unused file scoped decls, deserialize them and add to |
| 4055 | // Sema's list of unused file scoped decls. |
| 4056 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4057 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4058 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 4059 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4060 | |
| 4061 | // If there were any locally-scoped external declarations, |
| 4062 | // deserialize them and add them to Sema's table of locally-scoped |
| 4063 | // external declarations. |
| 4064 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4065 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4066 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 4067 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4068 | |
| 4069 | // If there were any ext_vector type declarations, deserialize them |
| 4070 | // and add them to Sema's vector of such declarations. |
| 4071 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 4072 | SemaObj->ExtVectorDecls.push_back( |
| 4073 | cast<TypedefDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4074 | |
| 4075 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 4076 | // Can we cut them down before writing them ? |
| 4077 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4078 | // If there were any dynamic classes declarations, deserialize them |
| 4079 | // and add them to Sema's vector of such declarations. |
| 4080 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 4081 | SemaObj->DynamicClasses.push_back( |
| 4082 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4083 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4084 | // Load the offsets of the declarations that Sema references. |
| 4085 | // They will be lazily deserialized when needed. |
| 4086 | if (!SemaDeclRefs.empty()) { |
| 4087 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 4088 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4089 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 4090 | } |
| 4091 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4092 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 4093 | |
| 4094 | // If there are @selector references added them to its pool. This is for |
| 4095 | // implementation of -Wselector. |
| 4096 | if (!F->ReferencedSelectorsData.empty()) { |
| 4097 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 4098 | unsigned I = 0; |
| 4099 | while (I < DataSize) { |
| 4100 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 4101 | SourceLocation SelLoc = ReadSourceLocation( |
| 4102 | *F, F->ReferencedSelectorsData, I); |
| 4103 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 4104 | } |
| 4105 | } |
| 4106 | |
| 4107 | // If there were any pending implicit instantiations, deserialize them |
| 4108 | // and add them to Sema's queue of such instantiations. |
| 4109 | assert(F->PendingInstantiations.size() % 2 == 0 && |
| 4110 | "Expected pairs of entries"); |
| 4111 | for (unsigned Idx = 0, N = F->PendingInstantiations.size(); Idx < N;) { |
| 4112 | ValueDecl *D=cast<ValueDecl>(GetDecl(F->PendingInstantiations[Idx++])); |
| 4113 | SourceLocation Loc = ReadSourceLocation(*F, F->PendingInstantiations,Idx); |
| 4114 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 4115 | } |
| 4116 | } |
| 4117 | |
| 4118 | // The two special data sets below always come from the most recent PCH, |
| 4119 | // which is at the front of the chain. |
| 4120 | PerFileData &F = *Chain.front(); |
| 4121 | |
| 4122 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 4123 | // Sema's list of weak undeclared identifiers. |
| 4124 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 4125 | unsigned Idx = 0; |
| 4126 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 4127 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4128 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4129 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 4130 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 4131 | Sema::WeakInfo WI(AliasId, Loc); |
| 4132 | WI.setUsed(Used); |
| 4133 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 4134 | } |
| 4135 | } |
| 4136 | |
| 4137 | // If there were any VTable uses, deserialize the information and add it |
| 4138 | // to Sema's vector and map of VTable uses. |
| 4139 | if (!VTableUses.empty()) { |
| 4140 | unsigned Idx = 0; |
| 4141 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 4142 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4143 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 4144 | bool DefinitionRequired = VTableUses[Idx++]; |
| 4145 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 4146 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4147 | } |
| 4148 | } |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4149 | |
| 4150 | if (!FPPragmaOptions.empty()) { |
| 4151 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4152 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4153 | } |
| 4154 | |
| 4155 | if (!OpenCLExtensions.empty()) { |
| 4156 | unsigned I = 0; |
| 4157 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4158 | #include "clang/Basic/OpenCLExtensions.def" |
| 4159 | |
| 4160 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4161 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4162 | } |
| 4163 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4164 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4165 | // Try to find this name within our on-disk hash tables. We start with the |
| 4166 | // 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] | 4167 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4168 | ASTIdentifierLookupTable *IdTable |
| 4169 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4170 | if (!IdTable) |
| 4171 | continue; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4172 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4173 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4174 | if (Pos == IdTable->end()) |
| 4175 | continue; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4176 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4177 | // Dereferencing the iterator has the effect of building the |
| 4178 | // IdentifierInfo node and populating it with the various |
| 4179 | // declarations it needs. |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4180 | return *Pos; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4181 | } |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4182 | return 0; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4183 | } |
| 4184 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4185 | namespace clang { |
| 4186 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4187 | /// identifiers stored within a set of AST files. |
| 4188 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4189 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4190 | const ASTReader &Reader; |
| 4191 | |
| 4192 | /// \brief The current index into the chain of AST files stored in |
| 4193 | /// the AST reader. |
| 4194 | unsigned Index; |
| 4195 | |
| 4196 | /// \brief The current position within the identifier lookup table |
| 4197 | /// of the current AST file. |
| 4198 | ASTIdentifierLookupTable::key_iterator Current; |
| 4199 | |
| 4200 | /// \brief The end position within the identifier lookup table of |
| 4201 | /// the current AST file. |
| 4202 | ASTIdentifierLookupTable::key_iterator End; |
| 4203 | |
| 4204 | public: |
| 4205 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4206 | |
| 4207 | virtual llvm::StringRef Next(); |
| 4208 | }; |
| 4209 | } |
| 4210 | |
| 4211 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 4212 | : Reader(Reader), Index(Reader.Chain.size() - 1) { |
| 4213 | ASTIdentifierLookupTable *IdTable |
| 4214 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4215 | Current = IdTable->key_begin(); |
| 4216 | End = IdTable->key_end(); |
| 4217 | } |
| 4218 | |
| 4219 | llvm::StringRef ASTIdentifierIterator::Next() { |
| 4220 | while (Current == End) { |
| 4221 | // If we have exhausted all of our AST files, we're done. |
| 4222 | if (Index == 0) |
| 4223 | return llvm::StringRef(); |
| 4224 | |
| 4225 | --Index; |
| 4226 | ASTIdentifierLookupTable *IdTable |
| 4227 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4228 | Current = IdTable->key_begin(); |
| 4229 | End = IdTable->key_end(); |
| 4230 | } |
| 4231 | |
| 4232 | // We have any identifiers remaining in the current AST file; return |
| 4233 | // the next one. |
| 4234 | std::pair<const char*, unsigned> Key = *Current; |
| 4235 | ++Current; |
| 4236 | return llvm::StringRef(Key.first, Key.second); |
| 4237 | } |
| 4238 | |
| 4239 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4240 | return new ASTIdentifierIterator(*this); |
| 4241 | } |
| 4242 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4243 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4244 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4245 | // Find this selector in a hash table. We want to find the most recent entry. |
| 4246 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4247 | PerFileData &F = *Chain[I]; |
| 4248 | if (!F.SelectorLookupTable) |
| 4249 | continue; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4250 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4251 | ASTSelectorLookupTable *PoolTable |
| 4252 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 4253 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4254 | if (Pos != PoolTable->end()) { |
| 4255 | ++NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4256 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4257 | // disable this tracking when called via LoadSelector. |
| 4258 | // Also, should entries without methods count as misses? |
| 4259 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4260 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4261 | if (DeserializationListener) |
| 4262 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 4263 | return std::make_pair(Data.Instance, Data.Factory); |
| 4264 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4265 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4266 | |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4267 | ++NumMethodPoolMisses; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4268 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4269 | } |
| 4270 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4271 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4272 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4273 | ReadMethodPool(Sel); |
| 4274 | } |
| 4275 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4276 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4277 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4278 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4279 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4280 | if (DeserializationListener) |
| 4281 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4282 | } |
| 4283 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4284 | /// \brief Set the globally-visible declarations associated with the given |
| 4285 | /// identifier. |
| 4286 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4287 | /// 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] | 4288 | /// 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] | 4289 | /// them. |
| 4290 | /// |
| 4291 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4292 | /// declarations. |
| 4293 | /// |
| 4294 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4295 | /// visible at global scope. |
| 4296 | /// |
| 4297 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4298 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4299 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4300 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4301 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4302 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 4303 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4304 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4305 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4306 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4307 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4308 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4309 | return; |
| 4310 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4311 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4312 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4313 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4314 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4315 | if (SemaObj->TUScope) { |
| 4316 | // Introduce this declaration into the translation-unit scope |
| 4317 | // and add it to the declaration chain for this identifier, so |
| 4318 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4319 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4320 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4321 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4322 | } else { |
| 4323 | // Queue this declaration so that it will be added to the |
| 4324 | // translation unit scope and identifier's declaration chain |
| 4325 | // once a Sema object is known. |
| 4326 | PreloadedDecls.push_back(D); |
| 4327 | } |
| 4328 | } |
| 4329 | } |
| 4330 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4331 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4332 | if (ID == 0) |
| 4333 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4334 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4335 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4336 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4337 | return 0; |
| 4338 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4339 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4340 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4341 | ID -= 1; |
| 4342 | if (!IdentifiersLoaded[ID]) { |
| 4343 | unsigned Index = ID; |
| 4344 | const char *Str = 0; |
| 4345 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4346 | PerFileData *F = Chain[N - I - 1]; |
| 4347 | if (Index < F->LocalNumIdentifiers) { |
| 4348 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 4349 | Str = F->IdentifierTableData + Offset; |
| 4350 | break; |
| 4351 | } |
| 4352 | Index -= F->LocalNumIdentifiers; |
| 4353 | } |
| 4354 | assert(Str && "Broken Chain"); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4355 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4356 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4357 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4358 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4359 | // unsigned integers. This is important to avoid integer overflow when |
| 4360 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4361 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4362 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4363 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4364 | IdentifiersLoaded[ID] |
Kovarththanan Rajaratnam | 811f426 | 2010-03-12 10:32:27 +0000 | [diff] [blame] | 4365 | = &PP->getIdentifierTable().get(Str, StrLen); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4366 | if (DeserializationListener) |
| 4367 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4368 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4369 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4370 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4371 | } |
| 4372 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4373 | void ASTReader::ReadSLocEntry(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4374 | ReadSLocEntryRecord(ID); |
| 4375 | } |
| 4376 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4377 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4378 | if (ID == 0) |
| 4379 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4380 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4381 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4382 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4383 | return Selector(); |
| 4384 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4385 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4386 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4387 | // Load this selector from the selector table. |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4388 | unsigned Idx = ID - 1; |
| 4389 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4390 | PerFileData &F = *Chain[N - I - 1]; |
| 4391 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4392 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4393 | SelectorsLoaded[ID - 1] = |
| 4394 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 4395 | if (DeserializationListener) |
| 4396 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 4397 | break; |
| 4398 | } |
| 4399 | Idx -= F.LocalNumSelectors; |
| 4400 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4401 | } |
| 4402 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4403 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4404 | } |
| 4405 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4406 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4407 | return DecodeSelector(ID); |
| 4408 | } |
| 4409 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4410 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4411 | // ID 0 (the null selector) is considered an external selector. |
| 4412 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4413 | } |
| 4414 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4415 | DeclarationName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4416 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4417 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4418 | switch (Kind) { |
| 4419 | case DeclarationName::Identifier: |
| 4420 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 4421 | |
| 4422 | case DeclarationName::ObjCZeroArgSelector: |
| 4423 | case DeclarationName::ObjCOneArgSelector: |
| 4424 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 4425 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4426 | |
| 4427 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4428 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4429 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4430 | |
| 4431 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4432 | return Context->DeclarationNames.getCXXDestructorName( |
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::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4436 | return Context->DeclarationNames.getCXXConversionFunctionName( |
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::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4440 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4441 | (OverloadedOperatorKind)Record[Idx++]); |
| 4442 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4443 | case DeclarationName::CXXLiteralOperatorName: |
| 4444 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 4445 | GetIdentifierInfo(Record, Idx)); |
| 4446 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4447 | case DeclarationName::CXXUsingDirective: |
| 4448 | return DeclarationName::getUsingDirectiveName(); |
| 4449 | } |
| 4450 | |
| 4451 | // Required to silence GCC warning |
| 4452 | return DeclarationName(); |
| 4453 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4454 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4455 | void ASTReader::ReadDeclarationNameLoc(PerFileData &F, |
| 4456 | DeclarationNameLoc &DNLoc, |
| 4457 | DeclarationName Name, |
| 4458 | const RecordData &Record, unsigned &Idx) { |
| 4459 | switch (Name.getNameKind()) { |
| 4460 | case DeclarationName::CXXConstructorName: |
| 4461 | case DeclarationName::CXXDestructorName: |
| 4462 | case DeclarationName::CXXConversionFunctionName: |
| 4463 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4464 | break; |
| 4465 | |
| 4466 | case DeclarationName::CXXOperatorName: |
| 4467 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4468 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4469 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4470 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4471 | break; |
| 4472 | |
| 4473 | case DeclarationName::CXXLiteralOperatorName: |
| 4474 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4475 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4476 | break; |
| 4477 | |
| 4478 | case DeclarationName::Identifier: |
| 4479 | case DeclarationName::ObjCZeroArgSelector: |
| 4480 | case DeclarationName::ObjCOneArgSelector: |
| 4481 | case DeclarationName::ObjCMultiArgSelector: |
| 4482 | case DeclarationName::CXXUsingDirective: |
| 4483 | break; |
| 4484 | } |
| 4485 | } |
| 4486 | |
| 4487 | void ASTReader::ReadDeclarationNameInfo(PerFileData &F, |
| 4488 | DeclarationNameInfo &NameInfo, |
| 4489 | const RecordData &Record, unsigned &Idx) { |
| 4490 | NameInfo.setName(ReadDeclarationName(Record, Idx)); |
| 4491 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4492 | DeclarationNameLoc DNLoc; |
| 4493 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4494 | NameInfo.setInfo(DNLoc); |
| 4495 | } |
| 4496 | |
| 4497 | void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info, |
| 4498 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4499 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4500 | unsigned NumTPLists = Record[Idx++]; |
| 4501 | Info.NumTemplParamLists = NumTPLists; |
| 4502 | if (NumTPLists) { |
| 4503 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 4504 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4505 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4506 | } |
| 4507 | } |
| 4508 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4509 | TemplateName |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4510 | ASTReader::ReadTemplateName(PerFileData &F, const RecordData &Record, |
| 4511 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4512 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4513 | switch (Kind) { |
| 4514 | case TemplateName::Template: |
| 4515 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 4516 | |
| 4517 | case TemplateName::OverloadedTemplate: { |
| 4518 | unsigned size = Record[Idx++]; |
| 4519 | UnresolvedSet<8> Decls; |
| 4520 | while (size--) |
| 4521 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 4522 | |
| 4523 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 4524 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4525 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4526 | case TemplateName::QualifiedTemplate: { |
| 4527 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4528 | bool hasTemplKeyword = Record[Idx++]; |
| 4529 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 4530 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 4531 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4532 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4533 | case TemplateName::DependentTemplate: { |
| 4534 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4535 | if (Record[Idx++]) // isIdentifier |
| 4536 | return Context->getDependentTemplateName(NNS, |
| 4537 | GetIdentifierInfo(Record, Idx)); |
| 4538 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4539 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4540 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4541 | |
| 4542 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4543 | TemplateTemplateParmDecl *Param |
| 4544 | = cast_or_null<TemplateTemplateParmDecl>(GetDecl(Record[Idx++])); |
| 4545 | if (!Param) |
| 4546 | return TemplateName(); |
| 4547 | |
| 4548 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 4549 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 4550 | return TemplateName(); |
| 4551 | |
| 4552 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 4553 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4554 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4555 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4556 | assert(0 && "Unhandled template name kind!"); |
| 4557 | return TemplateName(); |
| 4558 | } |
| 4559 | |
| 4560 | TemplateArgument |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4561 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4562 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4563 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 4564 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4565 | case TemplateArgument::Null: |
| 4566 | return TemplateArgument(); |
| 4567 | case TemplateArgument::Type: |
| 4568 | return TemplateArgument(GetType(Record[Idx++])); |
| 4569 | case TemplateArgument::Declaration: |
| 4570 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4571 | case TemplateArgument::Integral: { |
| 4572 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 4573 | QualType T = GetType(Record[Idx++]); |
| 4574 | return TemplateArgument(Value, T); |
| 4575 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4576 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4577 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4578 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4579 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4580 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 4581 | if (unsigned NumExpansions = Record[Idx++]) |
| 4582 | NumTemplateExpansions = NumExpansions - 1; |
| 4583 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4584 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4585 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4586 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4587 | case TemplateArgument::Pack: { |
| 4588 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4589 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 4590 | for (unsigned I = 0; I != NumArgs; ++I) |
| 4591 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 4592 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4593 | } |
| 4594 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4595 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4596 | assert(0 && "Unhandled template argument kind!"); |
| 4597 | return TemplateArgument(); |
| 4598 | } |
| 4599 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4600 | TemplateParameterList * |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4601 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 4602 | const RecordData &Record, unsigned &Idx) { |
| 4603 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 4604 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 4605 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4606 | |
| 4607 | unsigned NumParams = Record[Idx++]; |
| 4608 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 4609 | Params.reserve(NumParams); |
| 4610 | while (NumParams--) |
| 4611 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4612 | |
| 4613 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4614 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 4615 | Params.data(), Params.size(), RAngleLoc); |
| 4616 | return TemplateParams; |
| 4617 | } |
| 4618 | |
| 4619 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4620 | ASTReader:: |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4621 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4622 | PerFileData &F, const RecordData &Record, |
| 4623 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4624 | unsigned NumTemplateArgs = Record[Idx++]; |
| 4625 | TemplArgs.reserve(NumTemplateArgs); |
| 4626 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4627 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4628 | } |
| 4629 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4630 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4631 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4632 | const RecordData &Record, unsigned &Idx) { |
| 4633 | unsigned NumDecls = Record[Idx++]; |
| 4634 | while (NumDecls--) { |
| 4635 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 4636 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 4637 | Set.addDecl(D, AS); |
| 4638 | } |
| 4639 | } |
| 4640 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4641 | CXXBaseSpecifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4642 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4643 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4644 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 4645 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 4646 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4647 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4648 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4649 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4650 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4651 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4652 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4653 | Result.setInheritConstructors(inheritConstructors); |
| 4654 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4655 | } |
| 4656 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4657 | std::pair<CXXCtorInitializer **, unsigned> |
| 4658 | ASTReader::ReadCXXCtorInitializers(PerFileData &F, const RecordData &Record, |
| 4659 | unsigned &Idx) { |
| 4660 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4661 | unsigned NumInitializers = Record[Idx++]; |
| 4662 | if (NumInitializers) { |
| 4663 | ASTContext &C = *getContext(); |
| 4664 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4665 | CtorInitializers |
| 4666 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4667 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 4668 | TypeSourceInfo *BaseClassInfo = 0; |
| 4669 | bool IsBaseVirtual = false; |
| 4670 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4671 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4672 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4673 | bool IsBaseInitializer = Record[Idx++]; |
| 4674 | if (IsBaseInitializer) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4675 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4676 | IsBaseVirtual = Record[Idx++]; |
| 4677 | } else { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4678 | bool IsIndirectMemberInitializer = Record[Idx++]; |
| 4679 | if (IsIndirectMemberInitializer) |
| 4680 | IndirectMember = cast<IndirectFieldDecl>(GetDecl(Record[Idx++])); |
| 4681 | else |
| 4682 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4683 | } |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 4684 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4685 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4686 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 4687 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4688 | bool IsWritten = Record[Idx++]; |
| 4689 | unsigned SourceOrderOrNumArrayIndices; |
| 4690 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 4691 | if (IsWritten) { |
| 4692 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4693 | } else { |
| 4694 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4695 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 4696 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 4697 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 4698 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4699 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4700 | CXXCtorInitializer *BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4701 | if (IsBaseInitializer) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4702 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 4703 | LParenLoc, Init, RParenLoc, |
| 4704 | MemberOrEllipsisLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4705 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4706 | if (Member) |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4707 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 4708 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4709 | else |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4710 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 4711 | MemberOrEllipsisLoc, LParenLoc, |
| 4712 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4713 | } else { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4714 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 4715 | LParenLoc, Init, RParenLoc, |
| 4716 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4717 | } |
| 4718 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 4719 | if (IsWritten) |
| 4720 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4721 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4722 | } |
| 4723 | } |
| 4724 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4725 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4726 | } |
| 4727 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4728 | NestedNameSpecifier * |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4729 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4730 | unsigned N = Record[Idx++]; |
| 4731 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 4732 | for (unsigned I = 0; I != N; ++I) { |
| 4733 | NestedNameSpecifier::SpecifierKind Kind |
| 4734 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4735 | switch (Kind) { |
| 4736 | case NestedNameSpecifier::Identifier: { |
| 4737 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 4738 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 4739 | break; |
| 4740 | } |
| 4741 | |
| 4742 | case NestedNameSpecifier::Namespace: { |
| 4743 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 4744 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 4745 | break; |
| 4746 | } |
| 4747 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 4748 | case NestedNameSpecifier::NamespaceAlias: { |
| 4749 | NamespaceAliasDecl *Alias |
| 4750 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
| 4751 | NNS = NestedNameSpecifier::Create(*Context, Prev, Alias); |
| 4752 | break; |
| 4753 | } |
| 4754 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4755 | case NestedNameSpecifier::TypeSpec: |
| 4756 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4757 | const Type *T = GetType(Record[Idx++]).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 4758 | if (!T) |
| 4759 | return 0; |
| 4760 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4761 | bool Template = Record[Idx++]; |
| 4762 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 4763 | break; |
| 4764 | } |
| 4765 | |
| 4766 | case NestedNameSpecifier::Global: { |
| 4767 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4768 | // No associated value, and there can't be a prefix. |
| 4769 | break; |
| 4770 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4771 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 4772 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4773 | } |
| 4774 | return NNS; |
| 4775 | } |
| 4776 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4777 | NestedNameSpecifierLoc |
| 4778 | ASTReader::ReadNestedNameSpecifierLoc(PerFileData &F, const RecordData &Record, |
| 4779 | unsigned &Idx) { |
| 4780 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4781 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4782 | for (unsigned I = 0; I != N; ++I) { |
| 4783 | NestedNameSpecifier::SpecifierKind Kind |
| 4784 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4785 | switch (Kind) { |
| 4786 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4787 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4788 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4789 | Builder.Extend(*Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4790 | break; |
| 4791 | } |
| 4792 | |
| 4793 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4794 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4795 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4796 | Builder.Extend(*Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4797 | break; |
| 4798 | } |
| 4799 | |
| 4800 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4801 | NamespaceAliasDecl *Alias |
| 4802 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4803 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4804 | Builder.Extend(*Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4805 | break; |
| 4806 | } |
| 4807 | |
| 4808 | case NestedNameSpecifier::TypeSpec: |
| 4809 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4810 | bool Template = Record[Idx++]; |
| 4811 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 4812 | if (!T) |
| 4813 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4814 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4815 | |
| 4816 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
| 4817 | Builder.Extend(*Context, |
| 4818 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 4819 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4820 | break; |
| 4821 | } |
| 4822 | |
| 4823 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4824 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4825 | Builder.MakeGlobal(*Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4826 | break; |
| 4827 | } |
| 4828 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4829 | } |
| 4830 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4831 | return Builder.getWithLocInContext(*Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4832 | } |
| 4833 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4834 | SourceRange |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4835 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 4836 | unsigned &Idx) { |
| 4837 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 4838 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 4839 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4840 | } |
| 4841 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4842 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4843 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4844 | unsigned BitWidth = Record[Idx++]; |
| 4845 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 4846 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 4847 | Idx += NumWords; |
| 4848 | return Result; |
| 4849 | } |
| 4850 | |
| 4851 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4852 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4853 | bool isUnsigned = Record[Idx++]; |
| 4854 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 4855 | } |
| 4856 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4857 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4858 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4859 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 4860 | } |
| 4861 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4862 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4863 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4864 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 4865 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4866 | Idx += Len; |
| 4867 | return Result; |
| 4868 | } |
| 4869 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4870 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4871 | unsigned &Idx) { |
| 4872 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 4873 | return CXXTemporary::Create(*Context, Decl); |
| 4874 | } |
| 4875 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4876 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 4877 | return Diag(SourceLocation(), DiagID); |
| 4878 | } |
| 4879 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4880 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4881 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4882 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4883 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4884 | /// \brief Retrieve the identifier table associated with the |
| 4885 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4886 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4887 | assert(PP && "Forgot to set Preprocessor ?"); |
| 4888 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4889 | } |
| 4890 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4891 | /// \brief Record that the given ID maps to the given switch-case |
| 4892 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4893 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4894 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 4895 | SwitchCaseStmts[ID] = SC; |
| 4896 | } |
| 4897 | |
| 4898 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4899 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4900 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 4901 | return SwitchCaseStmts[ID]; |
| 4902 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4903 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4904 | void ASTReader::ClearSwitchCaseIDs() { |
| 4905 | SwitchCaseStmts.clear(); |
| 4906 | } |
| 4907 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4908 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4909 | assert(NumCurrentElementsDeserializing && |
| 4910 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 4911 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4912 | // If any identifiers with corresponding top-level declarations have |
| 4913 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4914 | while (!PendingIdentifierInfos.empty()) { |
| 4915 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 4916 | PendingIdentifierInfos.front().DeclIDs, true); |
| 4917 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4918 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4919 | |
Argyrios Kyrtzidis | 0895d15 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 4920 | // Ready to load previous declarations of Decls that were delayed. |
| 4921 | while (!PendingPreviousDecls.empty()) { |
| 4922 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 4923 | PendingPreviousDecls.front().second); |
| 4924 | PendingPreviousDecls.pop_front(); |
| 4925 | } |
| 4926 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4927 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 4928 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4929 | if (Consumer) |
| 4930 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 4931 | |
| 4932 | assert(PendingForwardRefs.size() == 0 && |
| 4933 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4934 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4935 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4936 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4937 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4938 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4939 | const char *isysroot, bool DisableValidation, |
| 4940 | bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4941 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 4942 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 4943 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
| 4944 | Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4945 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 4946 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), NextSLocOffset(0), |
| 4947 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 4948 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 4949 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 4950 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
| 4951 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 4952 | NumCurrentElementsDeserializing(0) |
| 4953 | { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4954 | RelocatablePCH = false; |
| 4955 | } |
| 4956 | |
| 4957 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 4958 | Diagnostic &Diags, const char *isysroot, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4959 | bool DisableValidation, bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4960 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
| 4961 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4962 | isysroot(isysroot), DisableValidation(DisableValidation), |
| 4963 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 4964 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4965 | NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0), |
| 4966 | NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), |
| 4967 | NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
| 4968 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4969 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4970 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4971 | RelocatablePCH = false; |
| 4972 | } |
| 4973 | |
| 4974 | ASTReader::~ASTReader() { |
| 4975 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 4976 | delete Chain[e - i - 1]; |
| 4977 | // Delete all visible decl lookup tables |
| 4978 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 4979 | E = DeclContextOffsets.end(); |
| 4980 | I != E; ++I) { |
| 4981 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 4982 | J != F; ++J) { |
| 4983 | if (J->NameLookupTableData) |
| 4984 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 4985 | J->NameLookupTableData); |
| 4986 | } |
| 4987 | } |
| 4988 | for (DeclContextVisibleUpdatesPending::iterator |
| 4989 | I = PendingVisibleUpdates.begin(), |
| 4990 | E = PendingVisibleUpdates.end(); |
| 4991 | I != E; ++I) { |
| 4992 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 4993 | F = I->second.end(); |
| 4994 | J != F; ++J) |
| 4995 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 4996 | } |
| 4997 | } |
| 4998 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 4999 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
| 5000 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5001 | LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), |
| 5002 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5003 | MacroDefinitionOffsets(0), |
| 5004 | LocalNumHeaderFileInfos(0), HeaderFileInfoTableData(0), |
| 5005 | HeaderFileInfoTable(0), |
| 5006 | LocalNumSelectors(0), SelectorOffsets(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5007 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5008 | DeclOffsets(0), LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
| 5009 | LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 5010 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5011 | {} |
| 5012 | |
| 5013 | ASTReader::PerFileData::~PerFileData() { |
| 5014 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5015 | delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5016 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 5017 | } |