Sebastian Redl | 904c9c8 | 2010-08-18 23:57:11 +0000 | [diff] [blame] | 1 | //===--- ASTReader.cpp - AST File Reader ------------------------*- C++ -*-===// |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 10 | // This file defines the ASTReader class, which reads AST files. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 13 | |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTReader.h" |
| 15 | #include "clang/Serialization/ASTDeserializationListener.h" |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 16 | #include "ASTCommon.h" |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 17 | #include "clang/Frontend/FrontendDiagnostic.h" |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/Utils.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 19 | #include "clang/Sema/Sema.h" |
John McCall | 5f1e094 | 2010-08-24 08:50:51 +0000 | [diff] [blame] | 20 | #include "clang/Sema/Scope.h" |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 21 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 22 | #include "clang/AST/ASTContext.h" |
John McCall | 2a7fb27 | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 24 | #include "clang/AST/Expr.h" |
John McCall | 7a1fad3 | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 26 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 27 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 28 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 29 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 30 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 31 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 32 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 33 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 34 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 35 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 36 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 37 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 38 | #include "clang/Basic/Version.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 39 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 40 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 41 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 42 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 43 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 44 | #include "llvm/Support/Path.h" |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 45 | #include "llvm/Support/system_error.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 46 | #include <algorithm> |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 47 | #include <iterator> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 48 | #include <cstdio> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 49 | #include <sys/stat.h> |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 50 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 51 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 52 | using namespace clang::serialization; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 53 | |
| 54 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 55 | // PCH validator implementation |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 56 | //===----------------------------------------------------------------------===// |
| 57 | |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 58 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 59 | |
| 60 | bool |
| 61 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 62 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 63 | #define PARSE_LANGOPT_BENIGN(Option) |
| 64 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 65 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 66 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 67 | return true; \ |
| 68 | } |
| 69 | |
| 70 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 71 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 72 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 73 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 74 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 75 | PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 76 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 77 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 78 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 79 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
| 80 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 81 | PARSE_LANGOPT_BENIGN(MSCVersion); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 82 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 83 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 84 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 85 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 86 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 87 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 88 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 89 | PARSE_LANGOPT_IMPORTANT(AppleKext, diag::warn_pch_apple_kext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 90 | PARSE_LANGOPT_IMPORTANT(ObjCDefaultSynthProperties, |
| 91 | diag::warn_pch_objc_auto_properties); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 92 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 93 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 94 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 95 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 96 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 97 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 98 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 99 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 100 | PARSE_LANGOPT_IMPORTANT(ObjCExceptions, diag::warn_pch_objc_exceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 101 | PARSE_LANGOPT_IMPORTANT(CXXExceptions, diag::warn_pch_cxx_exceptions); |
| 102 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 103 | PARSE_LANGOPT_IMPORTANT(MSBitfields, diag::warn_pch_ms_bitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 104 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 105 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 106 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 108 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 109 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 110 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 111 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 112 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 113 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 115 | diag::warn_pch_heinous_extensions); |
| 116 | // FIXME: Most of the options below are benign if the macro wasn't |
| 117 | // used. Unfortunately, this means that a PCH compiled without |
| 118 | // optimization can't be used with optimization turned on, even |
| 119 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 120 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 121 | // doesn't matter. We could consider making this some special kind |
| 122 | // of check. |
| 123 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 124 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 125 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 126 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 127 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 128 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
| 129 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 130 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 131 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 132 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 133 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 134 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 135 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 136 | return true; |
| 137 | } |
| 138 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 139 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 140 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 141 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 142 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 143 | PARSE_LANGOPT_IMPORTANT(CUDA, diag::warn_pch_cuda); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 144 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 145 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 146 | PARSE_LANGOPT_BENIGN(SpellChecking); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 147 | PARSE_LANGOPT_BENIGN(DefaultFPContract); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 148 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 149 | #undef PARSE_LANGOPT_BENIGN |
| 150 | |
| 151 | return false; |
| 152 | } |
| 153 | |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 154 | bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) { |
| 155 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 156 | return false; |
| 157 | |
| 158 | Reader.Diag(diag::warn_pch_target_triple) |
| 159 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 160 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 163 | namespace { |
| 164 | struct EmptyStringRef { |
| 165 | bool operator ()(llvm::StringRef r) const { return r.empty(); } |
| 166 | }; |
| 167 | struct EmptyBlock { |
| 168 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 169 | }; |
| 170 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 171 | |
| 172 | static bool EqualConcatenations(llvm::SmallVector<llvm::StringRef, 2> L, |
| 173 | PCHPredefinesBlocks R) { |
| 174 | // First, sum up the lengths. |
| 175 | unsigned LL = 0, RL = 0; |
| 176 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 177 | LL += L[I].size(); |
| 178 | } |
| 179 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 180 | RL += R[I].Data.size(); |
| 181 | } |
| 182 | if (LL != RL) |
| 183 | return false; |
| 184 | if (LL == 0 && RL == 0) |
| 185 | return true; |
| 186 | |
| 187 | // Kick out empty parts, they confuse the algorithm below. |
| 188 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 189 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 190 | |
| 191 | // Do it the hard way. At this point, both vectors must be non-empty. |
| 192 | llvm::StringRef LR = L[0], RR = R[0].Data; |
| 193 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 194 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 195 | for (;;) { |
| 196 | // Compare the current pieces. |
| 197 | if (LR.size() == RR.size()) { |
| 198 | // If they're the same length, it's pretty easy. |
| 199 | if (LR != RR) |
| 200 | return false; |
| 201 | // Both pieces are done, advance. |
| 202 | ++LI; |
| 203 | ++RI; |
| 204 | // If either string is done, they're both done, since they're the same |
| 205 | // length. |
| 206 | if (LI == LN) { |
| 207 | assert(RI == RN && "Strings not the same length after all?"); |
| 208 | return true; |
| 209 | } |
| 210 | LR = L[LI]; |
| 211 | RR = R[RI].Data; |
| 212 | } else if (LR.size() < RR.size()) { |
| 213 | // Right piece is longer. |
| 214 | if (!RR.startswith(LR)) |
| 215 | return false; |
| 216 | ++LI; |
| 217 | assert(LI != LN && "Strings not the same length after all?"); |
| 218 | RR = RR.substr(LR.size()); |
| 219 | LR = L[LI]; |
| 220 | } else { |
| 221 | // Left piece is longer. |
| 222 | if (!LR.startswith(RR)) |
| 223 | return false; |
| 224 | ++RI; |
| 225 | assert(RI != RN && "Strings not the same length after all?"); |
| 226 | LR = LR.substr(RR.size()); |
| 227 | RR = R[RI].Data; |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | static std::pair<FileID, llvm::StringRef::size_type> |
| 233 | FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) { |
| 234 | std::pair<FileID, llvm::StringRef::size_type> Res; |
| 235 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 236 | Res.second = Buffers[I].Data.find(MacroDef); |
| 237 | if (Res.second != llvm::StringRef::npos) { |
| 238 | Res.first = Buffers[I].BufferID; |
| 239 | break; |
| 240 | } |
| 241 | } |
| 242 | return Res; |
| 243 | } |
| 244 | |
| 245 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 246 | llvm::StringRef OriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 247 | std::string &SuggestedPredefines, |
| 248 | FileManager &FileMgr) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 249 | // We are in the context of an implicit include, so the predefines buffer will |
| 250 | // have a #include entry for the PCH file itself (as normalized by the |
| 251 | // preprocessor initialization). Find it and skip over it in the checking |
| 252 | // below. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 253 | llvm::SmallString<256> PCHInclude; |
| 254 | PCHInclude += "#include \""; |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 255 | PCHInclude += NormalizeDashIncludePath(OriginalFileName, FileMgr); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 256 | PCHInclude += "\"\n"; |
| 257 | std::pair<llvm::StringRef,llvm::StringRef> Split = |
| 258 | llvm::StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 259 | llvm::StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 260 | if (Left == PP.getPredefines()) { |
| 261 | Error("Missing PCH include entry!"); |
| 262 | return true; |
| 263 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 264 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 265 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 266 | // command line, we're done. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 267 | llvm::SmallVector<llvm::StringRef, 2> CommandLine; |
| 268 | CommandLine.push_back(Left); |
| 269 | CommandLine.push_back(Right); |
| 270 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 271 | return false; |
| 272 | |
| 273 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 274 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 275 | // The predefines buffers are different. Determine what the differences are, |
| 276 | // and whether they require us to reject the PCH file. |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 277 | llvm::SmallVector<llvm::StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 278 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 279 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 280 | |
| 281 | llvm::SmallVector<llvm::StringRef, 8> CmdLineLines; |
| 282 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 283 | |
| 284 | // Pick out implicit #includes after the PCH and don't consider them for |
| 285 | // validation; we will insert them into SuggestedPredefines so that the |
| 286 | // preprocessor includes them. |
| 287 | std::string IncludesAfterPCH; |
| 288 | llvm::SmallVector<llvm::StringRef, 8> AfterPCHLines; |
| 289 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 290 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 291 | if (AfterPCHLines[i].startswith("#include ")) { |
| 292 | IncludesAfterPCH += AfterPCHLines[i]; |
| 293 | IncludesAfterPCH += '\n'; |
| 294 | } else { |
| 295 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | // Make sure we add the includes last into SuggestedPredefines before we |
| 300 | // exit this function. |
| 301 | struct AddIncludesRAII { |
| 302 | std::string &SuggestedPredefines; |
| 303 | std::string &IncludesAfterPCH; |
| 304 | |
| 305 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 306 | std::string &IncludesAfterPCH) |
| 307 | : SuggestedPredefines(SuggestedPredefines), |
| 308 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 309 | ~AddIncludesRAII() { |
| 310 | SuggestedPredefines += IncludesAfterPCH; |
| 311 | } |
| 312 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 313 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 314 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 315 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 316 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 317 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 318 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 319 | // Determine which predefines that were used to build the PCH file are missing |
| 320 | // from the command line. |
| 321 | std::vector<llvm::StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 322 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 323 | CmdLineLines.begin(), CmdLineLines.end(), |
| 324 | std::back_inserter(MissingPredefines)); |
| 325 | |
| 326 | bool MissingDefines = false; |
| 327 | bool ConflictingDefines = false; |
| 328 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 329 | llvm::StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 330 | if (Missing.startswith("#include ")) { |
| 331 | // An -include was specified when generating the PCH; it is included in |
| 332 | // the PCH, just ignore it. |
| 333 | continue; |
| 334 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 335 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 336 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 337 | return true; |
| 338 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 339 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 340 | // This is a macro definition. Determine the name of the macro we're |
| 341 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 342 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 343 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 344 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 345 | assert(EndOfMacroName != std::string::npos && |
| 346 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 347 | llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 348 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 349 | // Determine whether this macro was given a different definition on the |
| 350 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 351 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 352 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 353 | llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 354 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 355 | MacroDefStart); |
| 356 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 357 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 358 | // Different macro; we're done. |
| 359 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 360 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 361 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 362 | |
| 363 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 364 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 366 | (*ConflictPos)[MacroDefLen] != '(') |
| 367 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 368 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 369 | // We found a conflicting macro definition. |
| 370 | break; |
| 371 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 372 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 373 | if (ConflictPos != CmdLineLines.end()) { |
| 374 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 375 | << MacroName; |
| 376 | |
| 377 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 378 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 379 | FindMacro(Buffers, Missing); |
| 380 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 381 | SourceLocation PCHMissingLoc = |
| 382 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 383 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 384 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 385 | |
| 386 | ConflictingDefines = true; |
| 387 | continue; |
| 388 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 389 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 390 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 391 | // 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] | 392 | if (ConflictingDefines) |
| 393 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 394 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 395 | if (!MissingDefines) { |
| 396 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 397 | MissingDefines = true; |
| 398 | } |
| 399 | |
| 400 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 401 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 402 | FindMacro(Buffers, Missing); |
| 403 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 404 | SourceLocation PCHMissingLoc = |
| 405 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 406 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 407 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 408 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 410 | if (ConflictingDefines) |
| 411 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 413 | // Determine what predefines were introduced based on command-line |
| 414 | // parameters that were not present when building the PCH |
| 415 | // file. Extra #defines are okay, so long as the identifiers being |
| 416 | // defined were not used within the precompiled header. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 417 | std::vector<llvm::StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 418 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 419 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 421 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 422 | llvm::StringRef &Extra = ExtraPredefines[I]; |
| 423 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 424 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 425 | return true; |
| 426 | } |
| 427 | |
| 428 | // This is an extra macro definition. Determine the name of the |
| 429 | // macro we're defining. |
| 430 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 431 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 432 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 433 | assert(EndOfMacroName != std::string::npos && |
| 434 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 435 | llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 436 | |
| 437 | // Check whether this name was used somewhere in the PCH file. If |
| 438 | // so, defining it as a macro could change behavior, so we reject |
| 439 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 440 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 441 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 442 | return true; |
| 443 | } |
| 444 | |
| 445 | // Add this definition to the suggested predefines buffer. |
| 446 | SuggestedPredefines += Extra; |
| 447 | SuggestedPredefines += '\n'; |
| 448 | } |
| 449 | |
| 450 | // If we get here, it's because the predefines buffer had compatible |
| 451 | // contents. Accept the PCH file. |
| 452 | return false; |
| 453 | } |
| 454 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 455 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 456 | unsigned ID) { |
| 457 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 458 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | void PCHValidator::ReadCounter(unsigned Value) { |
| 462 | PP.setCounterValue(Value); |
| 463 | } |
| 464 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 465 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 466 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 467 | //===----------------------------------------------------------------------===// |
| 468 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 469 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 470 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 471 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 474 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 475 | namespace { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 476 | class ASTSelectorLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 477 | ASTReader &Reader; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 478 | |
| 479 | public: |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 480 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 481 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 482 | ObjCMethodList Instance, Factory; |
| 483 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 484 | |
| 485 | typedef Selector external_key_type; |
| 486 | typedef external_key_type internal_key_type; |
| 487 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 488 | explicit ASTSelectorLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 489 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 490 | static bool EqualKey(const internal_key_type& a, |
| 491 | const internal_key_type& b) { |
| 492 | return a == b; |
| 493 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 494 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 495 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 496 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 497 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 498 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 499 | // This hopefully will just get inlined and removed by the optimizer. |
| 500 | static const internal_key_type& |
| 501 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 503 | static std::pair<unsigned, unsigned> |
| 504 | ReadKeyDataLength(const unsigned char*& d) { |
| 505 | using namespace clang::io; |
| 506 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 507 | unsigned DataLen = ReadUnalignedLE16(d); |
| 508 | return std::make_pair(KeyLen, DataLen); |
| 509 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 510 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 511 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 512 | using namespace clang::io; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 513 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 514 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 515 | IdentifierInfo *FirstII |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 516 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 517 | if (N == 0) |
| 518 | return SelTable.getNullarySelector(FirstII); |
| 519 | else if (N == 1) |
| 520 | return SelTable.getUnarySelector(FirstII); |
| 521 | |
| 522 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 523 | Args.push_back(FirstII); |
| 524 | for (unsigned I = 1; I != N; ++I) |
| 525 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 526 | |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 527 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 528 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 529 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 530 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 531 | using namespace clang::io; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 532 | |
| 533 | data_type Result; |
| 534 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 535 | Result.ID = ReadUnalignedLE32(d); |
| 536 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 537 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 538 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 539 | // Load instance methods |
| 540 | ObjCMethodList *Prev = 0; |
| 541 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 543 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 544 | if (!Result.Instance.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 545 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 546 | Result.Instance.Method = Method; |
| 547 | Prev = &Result.Instance; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 548 | continue; |
| 549 | } |
| 550 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 551 | ObjCMethodList *Mem = |
| 552 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 553 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 554 | Prev = Prev->Next; |
| 555 | } |
| 556 | |
| 557 | // Load factory methods |
| 558 | Prev = 0; |
| 559 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 560 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 561 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 562 | if (!Result.Factory.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 563 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 564 | Result.Factory.Method = Method; |
| 565 | Prev = &Result.Factory; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 566 | continue; |
| 567 | } |
| 568 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 569 | ObjCMethodList *Mem = |
| 570 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 571 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 572 | Prev = Prev->Next; |
| 573 | } |
| 574 | |
| 575 | return Result; |
| 576 | } |
| 577 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 578 | |
| 579 | } // end anonymous namespace |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 580 | |
| 581 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 582 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 583 | ASTSelectorLookupTable; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 584 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 585 | namespace clang { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 586 | class ASTIdentifierLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 587 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 588 | ASTReader::PerFileData &F; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 589 | |
| 590 | // If we know the IdentifierInfo in advance, it is here and we will |
| 591 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 592 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 593 | IdentifierInfo *KnownII; |
| 594 | |
| 595 | public: |
| 596 | typedef IdentifierInfo * data_type; |
| 597 | |
| 598 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 599 | |
| 600 | typedef external_key_type internal_key_type; |
| 601 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 602 | ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 603 | IdentifierInfo *II = 0) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 604 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 605 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 606 | static bool EqualKey(const internal_key_type& a, |
| 607 | const internal_key_type& b) { |
| 608 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 609 | : false; |
| 610 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 611 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 612 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 613 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 614 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 615 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 616 | // This hopefully will just get inlined and removed by the optimizer. |
| 617 | static const internal_key_type& |
| 618 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 619 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 620 | // This hopefully will just get inlined and removed by the optimizer. |
| 621 | static const external_key_type& |
| 622 | GetExternalKey(const internal_key_type& x) { return x; } |
| 623 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 624 | static std::pair<unsigned, unsigned> |
| 625 | ReadKeyDataLength(const unsigned char*& d) { |
| 626 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 627 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 628 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 629 | return std::make_pair(KeyLen, DataLen); |
| 630 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 631 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 632 | static std::pair<const char*, unsigned> |
| 633 | ReadKey(const unsigned char* d, unsigned n) { |
| 634 | assert(n >= 2 && d[n-1] == '\0'); |
| 635 | return std::make_pair((const char*) d, n-1); |
| 636 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 637 | |
| 638 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 639 | const unsigned char* d, |
| 640 | unsigned DataLen) { |
| 641 | using namespace clang::io; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 642 | IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 643 | bool IsInteresting = ID & 0x01; |
| 644 | |
| 645 | // Wipe out the "is interesting" bit. |
| 646 | ID = ID >> 1; |
| 647 | |
| 648 | if (!IsInteresting) { |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 649 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 650 | // and associate it with the persistent ID. |
| 651 | IdentifierInfo *II = KnownII; |
| 652 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 653 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 654 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 655 | II->setIsFromAST(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 656 | return II; |
| 657 | } |
| 658 | |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 659 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 660 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 661 | Bits >>= 1; |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 662 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 663 | Bits >>= 1; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 664 | bool Poisoned = Bits & 0x01; |
| 665 | Bits >>= 1; |
| 666 | bool ExtensionToken = Bits & 0x01; |
| 667 | Bits >>= 1; |
| 668 | bool hasMacroDefinition = Bits & 0x01; |
| 669 | Bits >>= 1; |
| 670 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 671 | Bits >>= 10; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 672 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 673 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 674 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 675 | |
| 676 | // Build the IdentifierInfo itself and link the identifier ID with |
| 677 | // the new IdentifierInfo. |
| 678 | IdentifierInfo *II = KnownII; |
| 679 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 680 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 681 | Reader.SetIdentifierInfo(ID, II); |
| 682 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 683 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 684 | // Token IDs are read-only. |
| 685 | if (HasRevertedTokenIDToIdentifier) |
| 686 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 687 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 688 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 689 | "Incorrect extension token flag"); |
| 690 | (void)ExtensionToken; |
| 691 | II->setIsPoisoned(Poisoned); |
| 692 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 693 | "Incorrect C++ operator keyword flag"); |
| 694 | (void)CPlusPlusOperatorKeyword; |
| 695 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 696 | // If this identifier is a macro, deserialize the macro |
| 697 | // definition. |
| 698 | if (hasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 699 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 700 | Reader.SetIdentifierIsMacro(II, F, Offset); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 701 | DataLen -= 4; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 702 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 703 | |
| 704 | // Read all of the declarations visible at global scope with this |
| 705 | // name. |
Chris Lattner | 6bf690f | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 706 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 707 | if (DataLen > 0) { |
| 708 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 709 | for (; DataLen > 0; DataLen -= 4) |
| 710 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 711 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 712 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 713 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 714 | II->setIsFromAST(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 715 | return II; |
| 716 | } |
| 717 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 718 | |
| 719 | } // end anonymous namespace |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 720 | |
| 721 | /// \brief The on-disk hash table used to contain information about |
| 722 | /// all of the identifiers in the program. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 723 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 724 | ASTIdentifierLookupTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 725 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 726 | namespace { |
| 727 | class ASTDeclContextNameLookupTrait { |
| 728 | ASTReader &Reader; |
| 729 | |
| 730 | public: |
| 731 | /// \brief Pair of begin/end iterators for DeclIDs. |
| 732 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 733 | |
| 734 | /// \brief Special internal key for declaration names. |
| 735 | /// The hash table creates keys for comparison; we do not create |
| 736 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 737 | struct DeclNameKey { |
| 738 | DeclarationName::NameKind Kind; |
| 739 | uint64_t Data; |
| 740 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 741 | }; |
| 742 | |
| 743 | typedef DeclarationName external_key_type; |
| 744 | typedef DeclNameKey internal_key_type; |
| 745 | |
| 746 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
| 747 | |
| 748 | static bool EqualKey(const internal_key_type& a, |
| 749 | const internal_key_type& b) { |
| 750 | return a.Kind == b.Kind && a.Data == b.Data; |
| 751 | } |
| 752 | |
| 753 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 754 | llvm::FoldingSetNodeID ID; |
| 755 | ID.AddInteger(Key.Kind); |
| 756 | |
| 757 | switch (Key.Kind) { |
| 758 | case DeclarationName::Identifier: |
| 759 | case DeclarationName::CXXLiteralOperatorName: |
| 760 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 761 | break; |
| 762 | case DeclarationName::ObjCZeroArgSelector: |
| 763 | case DeclarationName::ObjCOneArgSelector: |
| 764 | case DeclarationName::ObjCMultiArgSelector: |
| 765 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 766 | break; |
| 767 | case DeclarationName::CXXConstructorName: |
| 768 | case DeclarationName::CXXDestructorName: |
| 769 | case DeclarationName::CXXConversionFunctionName: |
| 770 | ID.AddInteger((TypeID)Key.Data); |
| 771 | break; |
| 772 | case DeclarationName::CXXOperatorName: |
| 773 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 774 | break; |
| 775 | case DeclarationName::CXXUsingDirective: |
| 776 | break; |
| 777 | } |
| 778 | |
| 779 | return ID.ComputeHash(); |
| 780 | } |
| 781 | |
| 782 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 783 | DeclNameKey Key; |
| 784 | Key.Kind = Name.getNameKind(); |
| 785 | switch (Name.getNameKind()) { |
| 786 | case DeclarationName::Identifier: |
| 787 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 788 | break; |
| 789 | case DeclarationName::ObjCZeroArgSelector: |
| 790 | case DeclarationName::ObjCOneArgSelector: |
| 791 | case DeclarationName::ObjCMultiArgSelector: |
| 792 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 793 | break; |
| 794 | case DeclarationName::CXXConstructorName: |
| 795 | case DeclarationName::CXXDestructorName: |
| 796 | case DeclarationName::CXXConversionFunctionName: |
| 797 | Key.Data = Reader.GetTypeID(Name.getCXXNameType()); |
| 798 | break; |
| 799 | case DeclarationName::CXXOperatorName: |
| 800 | Key.Data = Name.getCXXOverloadedOperator(); |
| 801 | break; |
| 802 | case DeclarationName::CXXLiteralOperatorName: |
| 803 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 804 | break; |
| 805 | case DeclarationName::CXXUsingDirective: |
| 806 | break; |
| 807 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 808 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 809 | return Key; |
| 810 | } |
| 811 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 812 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 813 | ASTContext *Context = Reader.getContext(); |
| 814 | switch (Key.Kind) { |
| 815 | case DeclarationName::Identifier: |
| 816 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 817 | |
| 818 | case DeclarationName::ObjCZeroArgSelector: |
| 819 | case DeclarationName::ObjCOneArgSelector: |
| 820 | case DeclarationName::ObjCMultiArgSelector: |
| 821 | return DeclarationName(Selector(Key.Data)); |
| 822 | |
| 823 | case DeclarationName::CXXConstructorName: |
| 824 | return Context->DeclarationNames.getCXXConstructorName( |
| 825 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 826 | |
| 827 | case DeclarationName::CXXDestructorName: |
| 828 | return Context->DeclarationNames.getCXXDestructorName( |
| 829 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 830 | |
| 831 | case DeclarationName::CXXConversionFunctionName: |
| 832 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 833 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 834 | |
| 835 | case DeclarationName::CXXOperatorName: |
| 836 | return Context->DeclarationNames.getCXXOperatorName( |
| 837 | (OverloadedOperatorKind)Key.Data); |
| 838 | |
| 839 | case DeclarationName::CXXLiteralOperatorName: |
| 840 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 841 | (IdentifierInfo*)Key.Data); |
| 842 | |
| 843 | case DeclarationName::CXXUsingDirective: |
| 844 | return DeclarationName::getUsingDirectiveName(); |
| 845 | } |
| 846 | |
| 847 | llvm_unreachable("Invalid Name Kind ?"); |
| 848 | } |
| 849 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 850 | static std::pair<unsigned, unsigned> |
| 851 | ReadKeyDataLength(const unsigned char*& d) { |
| 852 | using namespace clang::io; |
| 853 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 854 | unsigned DataLen = ReadUnalignedLE16(d); |
| 855 | return std::make_pair(KeyLen, DataLen); |
| 856 | } |
| 857 | |
| 858 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 859 | using namespace clang::io; |
| 860 | |
| 861 | DeclNameKey Key; |
| 862 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 863 | switch (Key.Kind) { |
| 864 | case DeclarationName::Identifier: |
| 865 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 866 | break; |
| 867 | case DeclarationName::ObjCZeroArgSelector: |
| 868 | case DeclarationName::ObjCOneArgSelector: |
| 869 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 870 | Key.Data = |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 871 | (uint64_t)Reader.DecodeSelector(ReadUnalignedLE32(d)).getAsOpaquePtr(); |
| 872 | break; |
| 873 | case DeclarationName::CXXConstructorName: |
| 874 | case DeclarationName::CXXDestructorName: |
| 875 | case DeclarationName::CXXConversionFunctionName: |
| 876 | Key.Data = ReadUnalignedLE32(d); // TypeID |
| 877 | break; |
| 878 | case DeclarationName::CXXOperatorName: |
| 879 | Key.Data = *d++; // OverloadedOperatorKind |
| 880 | break; |
| 881 | case DeclarationName::CXXLiteralOperatorName: |
| 882 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 883 | break; |
| 884 | case DeclarationName::CXXUsingDirective: |
| 885 | break; |
| 886 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 887 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 888 | return Key; |
| 889 | } |
| 890 | |
| 891 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 892 | unsigned DataLen) { |
| 893 | using namespace clang::io; |
| 894 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 895 | DeclID *Start = (DeclID *)d; |
| 896 | return std::make_pair(Start, Start + NumDecls); |
| 897 | } |
| 898 | }; |
| 899 | |
| 900 | } // end anonymous namespace |
| 901 | |
| 902 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 903 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 904 | ASTDeclContextNameLookupTable; |
| 905 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 906 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 907 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 908 | DeclContextInfo &Info) { |
| 909 | SavedStreamPosition SavedPosition(Cursor); |
| 910 | // First the lexical decls. |
| 911 | if (Offsets.first != 0) { |
| 912 | Cursor.JumpToBit(Offsets.first); |
| 913 | |
| 914 | RecordData Record; |
| 915 | const char *Blob; |
| 916 | unsigned BlobLen; |
| 917 | unsigned Code = Cursor.ReadCode(); |
| 918 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 919 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 920 | Error("Expected lexical block"); |
| 921 | return true; |
| 922 | } |
| 923 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 924 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 925 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 926 | } else { |
| 927 | Info.LexicalDecls = 0; |
| 928 | Info.NumLexicalDecls = 0; |
| 929 | } |
| 930 | |
| 931 | // Now the lookup table. |
| 932 | if (Offsets.second != 0) { |
| 933 | Cursor.JumpToBit(Offsets.second); |
| 934 | |
| 935 | RecordData Record; |
| 936 | const char *Blob; |
| 937 | unsigned BlobLen; |
| 938 | unsigned Code = Cursor.ReadCode(); |
| 939 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 940 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 941 | Error("Expected visible lookup table block"); |
| 942 | return true; |
| 943 | } |
| 944 | Info.NameLookupTableData |
| 945 | = ASTDeclContextNameLookupTable::Create( |
| 946 | (const unsigned char *)Blob + Record[0], |
| 947 | (const unsigned char *)Blob, |
| 948 | ASTDeclContextNameLookupTrait(*this)); |
Sebastian Redl | 0ea8f7f | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 949 | } else { |
| 950 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | return false; |
| 954 | } |
| 955 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 956 | void ASTReader::Error(const char *Msg) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 957 | Diag(diag::err_fe_pch_malformed) << Msg; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 960 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 961 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 962 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 963 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 964 | ActualOriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 965 | SuggestedPredefines, |
| 966 | FileMgr); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 967 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 968 | } |
| 969 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 970 | //===----------------------------------------------------------------------===// |
| 971 | // Source Manager Deserialization |
| 972 | //===----------------------------------------------------------------------===// |
| 973 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 974 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 975 | /// \returns true if there was an error. |
| 976 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 977 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 978 | unsigned Idx = 0; |
| 979 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 980 | |
| 981 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 982 | std::map<int, int> FileIDs; |
| 983 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 984 | // Extract the file name |
| 985 | unsigned FilenameLen = Record[Idx++]; |
| 986 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 987 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 988 | MaybeAddSystemRootToFilename(Filename); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 989 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 990 | Filename.size()); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | // Parse the line entries |
| 994 | std::vector<LineEntry> Entries; |
| 995 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 996 | int FID = Record[Idx++]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 997 | |
| 998 | // Extract the line entries |
| 999 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1000 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1001 | Entries.clear(); |
| 1002 | Entries.reserve(NumEntries); |
| 1003 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1004 | unsigned FileOffset = Record[Idx++]; |
| 1005 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1006 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1007 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1008 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1009 | unsigned IncludeOffset = Record[Idx++]; |
| 1010 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1011 | FileKind, IncludeOffset)); |
| 1012 | } |
| 1013 | LineTable.AddEntry(FID, Entries); |
| 1014 | } |
| 1015 | |
| 1016 | return false; |
| 1017 | } |
| 1018 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1019 | namespace { |
| 1020 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1021 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1022 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1023 | const ino_t ino; |
| 1024 | const dev_t dev; |
| 1025 | const mode_t mode; |
| 1026 | const time_t mtime; |
| 1027 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1028 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1029 | 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] | 1030 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1031 | }; |
| 1032 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1033 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1034 | public: |
| 1035 | typedef const char *external_key_type; |
| 1036 | typedef const char *internal_key_type; |
| 1037 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1038 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1039 | |
| 1040 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1041 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1045 | |
| 1046 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1047 | return strcmp(a, b) == 0; |
| 1048 | } |
| 1049 | |
| 1050 | static std::pair<unsigned, unsigned> |
| 1051 | ReadKeyDataLength(const unsigned char*& d) { |
| 1052 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1053 | unsigned DataLen = (unsigned) *d++; |
| 1054 | return std::make_pair(KeyLen + 1, DataLen); |
| 1055 | } |
| 1056 | |
| 1057 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1058 | return (const char *)d; |
| 1059 | } |
| 1060 | |
| 1061 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1062 | unsigned /*DataLen*/) { |
| 1063 | using namespace clang::io; |
| 1064 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1065 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1066 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1067 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1068 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1069 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1070 | return data_type(ino, dev, mode, mtime, size); |
| 1071 | } |
| 1072 | }; |
| 1073 | |
| 1074 | /// \brief stat() cache for precompiled headers. |
| 1075 | /// |
| 1076 | /// This cache is very similar to the stat cache used by pretokenized |
| 1077 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1078 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1079 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1080 | CacheTy *Cache; |
| 1081 | |
| 1082 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1083 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1084 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1085 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1086 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1087 | Cache = CacheTy::Create(Buckets, Base); |
| 1088 | } |
| 1089 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1090 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1091 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1092 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1093 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1094 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1095 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1096 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1097 | // 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] | 1098 | if (I == Cache->end()) { |
| 1099 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1100 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1101 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1103 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1104 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1105 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1106 | StatBuf.st_ino = Data.ino; |
| 1107 | StatBuf.st_dev = Data.dev; |
| 1108 | StatBuf.st_mtime = Data.mtime; |
| 1109 | StatBuf.st_mode = Data.mode; |
| 1110 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1111 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1112 | } |
| 1113 | }; |
| 1114 | } // end anonymous namespace |
| 1115 | |
| 1116 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1117 | /// \brief Read a source manager block |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1118 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1119 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1120 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1121 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1122 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1123 | // Set the source-location entry cursor to the current position in |
| 1124 | // the stream. This cursor will be used to read the contents of the |
| 1125 | // source manager block initially, and then lazily read |
| 1126 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1127 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1128 | |
| 1129 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1130 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1131 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1132 | return Failure; |
| 1133 | } |
| 1134 | |
| 1135 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1136 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1137 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1138 | return Failure; |
| 1139 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1140 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1141 | RecordData Record; |
| 1142 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1143 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1144 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1145 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1146 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1147 | return Failure; |
| 1148 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1149 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1150 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1151 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1152 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1153 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1154 | SLocEntryCursor.ReadSubBlockID(); |
| 1155 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1156 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1157 | return Failure; |
| 1158 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1159 | continue; |
| 1160 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1161 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1162 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1163 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1164 | continue; |
| 1165 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1166 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1167 | // Read a record. |
| 1168 | const char *BlobStart; |
| 1169 | unsigned BlobLen; |
| 1170 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1171 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1172 | default: // Default behavior: ignore. |
| 1173 | break; |
| 1174 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1175 | case SM_LINE_TABLE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1176 | if (ParseLineTable(F, Record)) |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1177 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1178 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1179 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1180 | case SM_SLOC_FILE_ENTRY: |
| 1181 | case SM_SLOC_BUFFER_ENTRY: |
| 1182 | case SM_SLOC_INSTANTIATION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1183 | // Once we hit one of the source location entries, we're done. |
| 1184 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1185 | } |
| 1186 | } |
| 1187 | } |
| 1188 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1189 | /// \brief If a header file is not found at the path that we expect it to be |
| 1190 | /// and the PCH file was moved from its original location, try to resolve the |
| 1191 | /// file by assuming that header+PCH were moved together and the header is in |
| 1192 | /// the same place relative to the PCH. |
| 1193 | static std::string |
| 1194 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1195 | const std::string &OriginalDir, |
| 1196 | const std::string &CurrDir) { |
| 1197 | assert(OriginalDir != CurrDir && |
| 1198 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1199 | using namespace llvm::sys; |
| 1200 | llvm::SmallString<128> filePath(Filename); |
| 1201 | fs::make_absolute(filePath); |
| 1202 | assert(path::is_absolute(OriginalDir)); |
| 1203 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1204 | |
| 1205 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1206 | fileDirE = path::end(path::parent_path(filePath)); |
| 1207 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1208 | origDirE = path::end(OriginalDir); |
| 1209 | // Skip the common path components from filePath and OriginalDir. |
| 1210 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1211 | *fileDirI == *origDirI) { |
| 1212 | ++fileDirI; |
| 1213 | ++origDirI; |
| 1214 | } |
| 1215 | for (; origDirI != origDirE; ++origDirI) |
| 1216 | path::append(currPCHPath, ".."); |
| 1217 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1218 | path::append(currPCHPath, path::filename(Filename)); |
| 1219 | return currPCHPath.str(); |
| 1220 | } |
| 1221 | |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1222 | /// \brief Get a cursor that's correctly positioned for reading the source |
| 1223 | /// location entry with the given ID. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1224 | ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1225 | assert(ID != 0 && ID <= TotalNumSLocEntries && |
| 1226 | "SLocCursorForID should only be called for real IDs."); |
| 1227 | |
| 1228 | ID -= 1; |
| 1229 | PerFileData *F = 0; |
| 1230 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1231 | F = Chain[N - I - 1]; |
| 1232 | if (ID < F->LocalNumSLocEntries) |
| 1233 | break; |
| 1234 | ID -= F->LocalNumSLocEntries; |
| 1235 | } |
| 1236 | assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); |
| 1237 | |
| 1238 | F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1239 | return F; |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1242 | /// \brief Read in the source location entry with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1243 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1244 | if (ID == 0) |
| 1245 | return Success; |
| 1246 | |
| 1247 | if (ID > TotalNumSLocEntries) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1248 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1249 | return Failure; |
| 1250 | } |
| 1251 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1252 | PerFileData *F = SLocCursorForID(ID); |
| 1253 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1254 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1255 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1256 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1257 | if (Code == llvm::bitc::END_BLOCK || |
| 1258 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1259 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1260 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1261 | return Failure; |
| 1262 | } |
| 1263 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1264 | RecordData Record; |
| 1265 | const char *BlobStart; |
| 1266 | unsigned BlobLen; |
| 1267 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1268 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1269 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1270 | return Failure; |
| 1271 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1272 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1273 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1274 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1275 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1276 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1277 | OriginalDir != CurrentDir) { |
| 1278 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1279 | OriginalDir, |
| 1280 | CurrentDir); |
| 1281 | if (!resolved.empty()) |
| 1282 | File = FileMgr.getFile(resolved); |
| 1283 | } |
Axel Naumann | 0433116 | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1284 | if (File == 0) |
| 1285 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1286 | (time_t)Record[5]); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1287 | if (File == 0) { |
| 1288 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1289 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1290 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1291 | Error(ErrorStr.c_str()); |
| 1292 | return Failure; |
| 1293 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1294 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1295 | if (Record.size() < 6) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1296 | Error("source location entry is incorrect"); |
| 1297 | return Failure; |
| 1298 | } |
| 1299 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1300 | if (!DisableValidation && |
| 1301 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1302 | #if !defined(LLVM_ON_WIN32) |
| 1303 | // In our regression testing, the Windows file system seems to |
| 1304 | // have inconsistent modification times that sometimes |
| 1305 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1306 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1307 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1308 | )) { |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1309 | Diag(diag::err_fe_pch_file_modified) |
| 1310 | << Filename; |
| 1311 | return Failure; |
| 1312 | } |
| 1313 | |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1314 | FileID FID = SourceMgr.createFileID(File, ReadSourceLocation(*F, Record[1]), |
| 1315 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1316 | ID, Record[0]); |
| 1317 | if (Record[3]) |
| 1318 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1319 | .setHasLineDirectives(); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1320 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1321 | break; |
| 1322 | } |
| 1323 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1324 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1325 | const char *Name = BlobStart; |
| 1326 | unsigned Offset = Record[0]; |
| 1327 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1328 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1329 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1330 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1331 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1332 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1333 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1334 | return Failure; |
| 1335 | } |
| 1336 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1337 | llvm::MemoryBuffer *Buffer |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1338 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1339 | Name); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1340 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1341 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1342 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1343 | PCHPredefinesBlock Block = { |
| 1344 | BufferID, |
| 1345 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1346 | }; |
| 1347 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1348 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1349 | |
| 1350 | break; |
| 1351 | } |
| 1352 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1353 | case SM_SLOC_INSTANTIATION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1354 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1355 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1356 | ReadSourceLocation(*F, Record[2]), |
| 1357 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1358 | Record[4], |
| 1359 | ID, |
| 1360 | Record[0]); |
| 1361 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1362 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | return Success; |
| 1366 | } |
| 1367 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1368 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1369 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1370 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1371 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1372 | unsigned BlockID) { |
| 1373 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1374 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1375 | return Failure; |
| 1376 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1377 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1378 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1379 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1380 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1381 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1382 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1383 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1384 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1385 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1386 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1387 | Cursor.ReadAbbrevRecord(); |
| 1388 | } |
| 1389 | } |
| 1390 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1391 | PreprocessedEntity *ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1392 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1393 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1394 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1395 | // Keep track of where we are in the stream, then jump back there |
| 1396 | // after reading this macro. |
| 1397 | SavedStreamPosition SavedPosition(Stream); |
| 1398 | |
| 1399 | Stream.JumpToBit(Offset); |
| 1400 | RecordData Record; |
| 1401 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1402 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1403 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1404 | while (true) { |
| 1405 | unsigned Code = Stream.ReadCode(); |
| 1406 | switch (Code) { |
| 1407 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1408 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1409 | |
| 1410 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1411 | // No known subblocks, always skip them. |
| 1412 | Stream.ReadSubBlockID(); |
| 1413 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1414 | Error("malformed block record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1415 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1416 | } |
| 1417 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1418 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1419 | case llvm::bitc::DEFINE_ABBREV: |
| 1420 | Stream.ReadAbbrevRecord(); |
| 1421 | continue; |
| 1422 | default: break; |
| 1423 | } |
| 1424 | |
| 1425 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1426 | const char *BlobStart = 0; |
| 1427 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1428 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1429 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1430 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1431 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1432 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1433 | case PP_MACRO_OBJECT_LIKE: |
| 1434 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1435 | // If we already have a macro, that means that we've hit the end |
| 1436 | // of the definition of the macro we were looking for. We're |
| 1437 | // done. |
| 1438 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1439 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1440 | |
| 1441 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1442 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1443 | Error("macro must have a name in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1444 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1445 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1446 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1447 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1448 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1449 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1450 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1451 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1452 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1453 | unsigned NextIndex = 3; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1454 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1455 | // Decode function-like macro info. |
| 1456 | bool isC99VarArgs = Record[3]; |
| 1457 | bool isGNUVarArgs = Record[4]; |
| 1458 | MacroArgs.clear(); |
| 1459 | unsigned NumArgs = Record[5]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1460 | NextIndex = 6 + NumArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1461 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1462 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1463 | |
| 1464 | // Install function-like macro info. |
| 1465 | MI->setIsFunctionLike(); |
| 1466 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1467 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1468 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1469 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1473 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1474 | |
| 1475 | // Remember that we saw this macro last so that we add the tokens that |
| 1476 | // form its body to it. |
| 1477 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1478 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1479 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1480 | // We have a macro definition. Load it now. |
| 1481 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1482 | getMacroDefinition(Record[NextIndex])); |
| 1483 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1484 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1485 | ++NumMacrosRead; |
| 1486 | break; |
| 1487 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1488 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1489 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1490 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1491 | // erroneous, just pretend we didn't see this. |
| 1492 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1493 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1494 | Token Tok; |
| 1495 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1496 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1497 | Tok.setLength(Record[1]); |
| 1498 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1499 | Tok.setIdentifierInfo(II); |
| 1500 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1501 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1502 | Macro->AddTokenToBody(Tok); |
| 1503 | break; |
| 1504 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1505 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1506 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1507 | |
| 1508 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1509 | } |
| 1510 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1511 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(PerFileData &F) { |
| 1512 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1513 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1514 | switch (Code) { |
| 1515 | case llvm::bitc::END_BLOCK: |
| 1516 | return 0; |
| 1517 | |
| 1518 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1519 | Error("unexpected subblock record in preprocessor detail block"); |
| 1520 | return 0; |
| 1521 | |
| 1522 | case llvm::bitc::DEFINE_ABBREV: |
| 1523 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1524 | return 0; |
| 1525 | |
| 1526 | default: |
| 1527 | break; |
| 1528 | } |
| 1529 | |
| 1530 | if (!PP->getPreprocessingRecord()) { |
| 1531 | Error("no preprocessing record"); |
| 1532 | return 0; |
| 1533 | } |
| 1534 | |
| 1535 | // Read the record. |
| 1536 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1537 | const char *BlobStart = 0; |
| 1538 | unsigned BlobLen = 0; |
| 1539 | RecordData Record; |
| 1540 | PreprocessorDetailRecordTypes RecType = |
| 1541 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1542 | Code, Record, BlobStart, BlobLen); |
| 1543 | switch (RecType) { |
| 1544 | case PPD_MACRO_INSTANTIATION: { |
| 1545 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1546 | return PE; |
| 1547 | |
| 1548 | MacroInstantiation *MI |
| 1549 | = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), |
| 1550 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1551 | ReadSourceLocation(F, Record[2])), |
| 1552 | getMacroDefinition(Record[4])); |
| 1553 | PPRec.SetPreallocatedEntity(Record[0], MI); |
| 1554 | return MI; |
| 1555 | } |
| 1556 | |
| 1557 | case PPD_MACRO_DEFINITION: { |
| 1558 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1559 | return PE; |
| 1560 | |
| 1561 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
| 1562 | Error("out-of-bounds macro definition record"); |
| 1563 | return 0; |
| 1564 | } |
| 1565 | |
| 1566 | // Decode the identifier info and then check again; if the macro is |
| 1567 | // still defined and associated with the identifier, |
| 1568 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1569 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1570 | MacroDefinition *MD |
| 1571 | = new (PPRec) MacroDefinition(II, |
| 1572 | ReadSourceLocation(F, Record[5]), |
| 1573 | SourceRange( |
| 1574 | ReadSourceLocation(F, Record[2]), |
| 1575 | ReadSourceLocation(F, Record[3]))); |
| 1576 | |
| 1577 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1578 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
| 1579 | |
| 1580 | if (DeserializationListener) |
| 1581 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1582 | } |
| 1583 | |
| 1584 | return MacroDefinitionsLoaded[Record[1] - 1]; |
| 1585 | } |
| 1586 | |
| 1587 | case PPD_INCLUSION_DIRECTIVE: { |
| 1588 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1589 | return PE; |
| 1590 | |
| 1591 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1592 | const FileEntry *File |
| 1593 | = PP->getFileManager().getFile(llvm::StringRef(FullFileNameStart, |
| 1594 | BlobLen - Record[3])); |
| 1595 | |
| 1596 | // FIXME: Stable encoding |
| 1597 | InclusionDirective::InclusionKind Kind |
| 1598 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1599 | InclusionDirective *ID |
| 1600 | = new (PPRec) InclusionDirective(PPRec, Kind, |
| 1601 | llvm::StringRef(BlobStart, Record[3]), |
| 1602 | Record[4], |
| 1603 | File, |
| 1604 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1605 | ReadSourceLocation(F, Record[2]))); |
| 1606 | PPRec.SetPreallocatedEntity(Record[0], ID); |
| 1607 | return ID; |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | Error("invalid offset in preprocessor detail block"); |
| 1612 | return 0; |
| 1613 | } |
| 1614 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1615 | namespace { |
| 1616 | /// \brief Trait class used to search the on-disk hash table containing all of |
| 1617 | /// the header search information. |
| 1618 | /// |
| 1619 | /// The on-disk hash table contains a mapping from each header path to |
| 1620 | /// information about that header (how many times it has been included, its |
| 1621 | /// controlling macro, etc.). Note that we actually hash based on the |
| 1622 | /// filename, and support "deep" comparisons of file names based on current |
| 1623 | /// inode numbers, so that the search can cope with non-normalized path names |
| 1624 | /// and symlinks. |
| 1625 | class HeaderFileInfoTrait { |
| 1626 | const char *SearchPath; |
| 1627 | struct stat SearchPathStatBuf; |
| 1628 | llvm::Optional<int> SearchPathStatResult; |
| 1629 | |
| 1630 | int StatSimpleCache(const char *Path, struct stat *StatBuf) { |
| 1631 | if (Path == SearchPath) { |
| 1632 | if (!SearchPathStatResult) |
| 1633 | SearchPathStatResult = stat(Path, &SearchPathStatBuf); |
| 1634 | |
| 1635 | *StatBuf = SearchPathStatBuf; |
| 1636 | return *SearchPathStatResult; |
| 1637 | } |
| 1638 | |
| 1639 | return stat(Path, StatBuf); |
| 1640 | } |
| 1641 | |
| 1642 | public: |
| 1643 | typedef const char *external_key_type; |
| 1644 | typedef const char *internal_key_type; |
| 1645 | |
| 1646 | typedef HeaderFileInfo data_type; |
| 1647 | |
| 1648 | HeaderFileInfoTrait(const char *SearchPath = 0) : SearchPath(SearchPath) { } |
| 1649 | |
| 1650 | static unsigned ComputeHash(const char *path) { |
| 1651 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1652 | } |
| 1653 | |
| 1654 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1655 | |
| 1656 | bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1657 | if (strcmp(a, b) == 0) |
| 1658 | return true; |
| 1659 | |
| 1660 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1661 | return false; |
| 1662 | |
| 1663 | // The file names match, but the path names don't. stat() the files to |
| 1664 | // see if they are the same. |
| 1665 | struct stat StatBufA, StatBufB; |
| 1666 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1667 | return false; |
| 1668 | |
| 1669 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1670 | } |
| 1671 | |
| 1672 | static std::pair<unsigned, unsigned> |
| 1673 | ReadKeyDataLength(const unsigned char*& d) { |
| 1674 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1675 | unsigned DataLen = (unsigned) *d++; |
| 1676 | return std::make_pair(KeyLen + 1, DataLen); |
| 1677 | } |
| 1678 | |
| 1679 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1680 | return (const char *)d; |
| 1681 | } |
| 1682 | |
| 1683 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1684 | unsigned DataLen) { |
| 1685 | const unsigned char *End = d + DataLen; |
| 1686 | using namespace clang::io; |
| 1687 | HeaderFileInfo HFI; |
| 1688 | unsigned Flags = *d++; |
| 1689 | HFI.isImport = (Flags >> 3) & 0x01; |
| 1690 | HFI.DirInfo = (Flags >> 1) & 0x03; |
| 1691 | HFI.Resolved = Flags & 0x01; |
| 1692 | HFI.NumIncludes = ReadUnalignedLE16(d); |
| 1693 | HFI.ControllingMacroID = ReadUnalignedLE32(d); |
| 1694 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1695 | (void)End; |
| 1696 | |
| 1697 | // This HeaderFileInfo was externally loaded. |
| 1698 | HFI.External = true; |
| 1699 | return HFI; |
| 1700 | } |
| 1701 | }; |
| 1702 | } |
| 1703 | |
| 1704 | /// \brief The on-disk hash table used for the global method pool. |
| 1705 | typedef OnDiskChainedHashTable<HeaderFileInfoTrait> |
| 1706 | HeaderFileInfoLookupTable; |
| 1707 | |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1708 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F, |
| 1709 | uint64_t Offset) { |
| 1710 | // Note that this identifier has a macro definition. |
| 1711 | II->setHasMacroDefinition(true); |
| 1712 | |
| 1713 | // Adjust the offset based on our position in the chain. |
| 1714 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1715 | if (Chain[I] == &F) |
| 1716 | break; |
| 1717 | |
| 1718 | Offset += Chain[I]->SizeInBits; |
| 1719 | } |
| 1720 | |
| 1721 | UnreadMacroRecordOffsets[II] = Offset; |
| 1722 | } |
| 1723 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1724 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1725 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1726 | PerFileData &F = *Chain[N - I - 1]; |
| 1727 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1728 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1729 | // If there was no preprocessor block, skip this file. |
| 1730 | if (!MacroCursor.getBitStreamReader()) |
| 1731 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1732 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1733 | llvm::BitstreamCursor Cursor = MacroCursor; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1734 | Cursor.JumpToBit(F.MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1735 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1736 | RecordData Record; |
| 1737 | while (true) { |
| 1738 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1739 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1740 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1741 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1742 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1743 | // No known subblocks, always skip them. |
| 1744 | Cursor.ReadSubBlockID(); |
| 1745 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1746 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1747 | return; |
| 1748 | } |
| 1749 | continue; |
| 1750 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1751 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1752 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1753 | Cursor.ReadAbbrevRecord(); |
| 1754 | continue; |
| 1755 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1756 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1757 | // Read a record. |
| 1758 | const char *BlobStart; |
| 1759 | unsigned BlobLen; |
| 1760 | Record.clear(); |
| 1761 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1762 | default: // Default behavior: ignore. |
| 1763 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1764 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1765 | case PP_MACRO_OBJECT_LIKE: |
| 1766 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1767 | DecodeIdentifierInfo(Record[0]); |
| 1768 | break; |
| 1769 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1770 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1771 | // Ignore tokens. |
| 1772 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1773 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1774 | } |
| 1775 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1776 | |
| 1777 | // Drain the unread macro-record offsets map. |
| 1778 | while (!UnreadMacroRecordOffsets.empty()) |
| 1779 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1780 | } |
| 1781 | |
| 1782 | void ASTReader::LoadMacroDefinition( |
| 1783 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1784 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
| 1785 | PerFileData *F = 0; |
| 1786 | uint64_t Offset = Pos->second; |
| 1787 | UnreadMacroRecordOffsets.erase(Pos); |
| 1788 | |
| 1789 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1790 | if (Offset < Chain[I]->SizeInBits) { |
| 1791 | F = Chain[I]; |
| 1792 | break; |
| 1793 | } |
| 1794 | |
| 1795 | Offset -= Chain[I]->SizeInBits; |
| 1796 | } |
| 1797 | if (!F) { |
| 1798 | Error("Malformed macro record offset"); |
| 1799 | return; |
| 1800 | } |
| 1801 | |
| 1802 | ReadMacroRecord(*F, Offset); |
| 1803 | } |
| 1804 | |
| 1805 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1806 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1807 | = UnreadMacroRecordOffsets.find(II); |
| 1808 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1811 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1812 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1813 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1814 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1815 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1816 | unsigned Index = ID - 1; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1817 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1818 | PerFileData &F = *Chain[N - I - 1]; |
| 1819 | if (Index < F.LocalNumMacroDefinitions) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1820 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 1821 | F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]); |
| 1822 | LoadPreprocessedEntity(F); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1823 | break; |
| 1824 | } |
| 1825 | Index -= F.LocalNumMacroDefinitions; |
| 1826 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1827 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1830 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1833 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1834 | /// not an absolute path, add the system root to the beginning of the file |
| 1835 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1836 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1837 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1838 | if (!RelocatablePCH) |
| 1839 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1840 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1841 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1842 | return; |
| 1843 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1844 | if (isysroot == 0) { |
| 1845 | // If no system root was given, default to '/' |
| 1846 | Filename.insert(Filename.begin(), '/'); |
| 1847 | return; |
| 1848 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1849 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1850 | unsigned Length = strlen(isysroot); |
| 1851 | if (isysroot[Length - 1] != '/') |
| 1852 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1853 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1854 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1855 | } |
| 1856 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1857 | ASTReader::ASTReadResult |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1858 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1859 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1860 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1861 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1862 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1863 | return Failure; |
| 1864 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1865 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1866 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1867 | RecordData Record; |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1868 | bool First = true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1869 | while (!Stream.AtEndOfStream()) { |
| 1870 | unsigned Code = Stream.ReadCode(); |
| 1871 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1872 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1873 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1874 | return Failure; |
| 1875 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1876 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1877 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1881 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1882 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1883 | // We lazily load the decls block, but we want to set up the |
| 1884 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1885 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1886 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1887 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1888 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1889 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1890 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1891 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1892 | return Failure; |
| 1893 | } |
| 1894 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1895 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1896 | case DECL_UPDATES_BLOCK_ID: |
| 1897 | if (Stream.SkipBlock()) { |
| 1898 | Error("malformed block record in AST file"); |
| 1899 | return Failure; |
| 1900 | } |
| 1901 | break; |
| 1902 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1903 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1904 | F.MacroCursor = Stream; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1905 | if (PP) |
| 1906 | PP->setExternalSource(this); |
| 1907 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1908 | if (Stream.SkipBlock() || |
| 1909 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1910 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1911 | return Failure; |
| 1912 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1913 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1914 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1915 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1916 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1917 | F.PreprocessorDetailCursor = Stream; |
| 1918 | if (Stream.SkipBlock() || |
| 1919 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1920 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1921 | Error("malformed preprocessor detail record in AST file"); |
| 1922 | return Failure; |
| 1923 | } |
| 1924 | F.PreprocessorDetailStartOffset |
| 1925 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 1926 | break; |
| 1927 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1928 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1929 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1930 | case Success: |
| 1931 | break; |
| 1932 | |
| 1933 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1934 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1935 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1936 | |
| 1937 | case IgnorePCH: |
| 1938 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1939 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1940 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1941 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1942 | First = false; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1943 | continue; |
| 1944 | } |
| 1945 | |
| 1946 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1947 | Stream.ReadAbbrevRecord(); |
| 1948 | continue; |
| 1949 | } |
| 1950 | |
| 1951 | // Read and process a record. |
| 1952 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1953 | const char *BlobStart = 0; |
| 1954 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1955 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1956 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1957 | default: // Default behavior: ignore. |
| 1958 | break; |
| 1959 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1960 | case METADATA: { |
| 1961 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1962 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1963 | : diag::warn_pch_version_too_new); |
| 1964 | return IgnorePCH; |
| 1965 | } |
| 1966 | |
| 1967 | RelocatablePCH = Record[4]; |
| 1968 | if (Listener) { |
| 1969 | std::string TargetTriple(BlobStart, BlobLen); |
| 1970 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1971 | return IgnorePCH; |
| 1972 | } |
| 1973 | break; |
| 1974 | } |
| 1975 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1976 | case CHAINED_METADATA: { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1977 | if (!First) { |
| 1978 | Error("CHAINED_METADATA is not first record in block"); |
| 1979 | return Failure; |
| 1980 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1981 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1982 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1983 | : diag::warn_pch_version_too_new); |
| 1984 | return IgnorePCH; |
| 1985 | } |
| 1986 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 1987 | // Load the chained file, which is always a PCH file. |
| 1988 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1989 | case Failure: return Failure; |
| 1990 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1991 | case IgnorePCH: return IgnorePCH; |
| 1992 | case Success: break; |
| 1993 | } |
| 1994 | break; |
| 1995 | } |
| 1996 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1997 | case TYPE_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1998 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1999 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2000 | return Failure; |
| 2001 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2002 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 2003 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2004 | break; |
| 2005 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2006 | case DECL_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2007 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2008 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2009 | return Failure; |
| 2010 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2011 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 2012 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2013 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2014 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2015 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2016 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2017 | /* No visible information */ 0, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2018 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 2019 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2020 | }; |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2021 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 2022 | .push_back(Info); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2023 | break; |
| 2024 | } |
| 2025 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2026 | case UPDATE_VISIBLE: { |
| 2027 | serialization::DeclID ID = Record[0]; |
| 2028 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 2029 | (const unsigned char *)BlobStart + Record[1], |
| 2030 | (const unsigned char *)BlobStart, |
| 2031 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2032 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2033 | DeclContextInfo Info = { |
| 2034 | Table, /* No lexical inforamtion */ 0, 0 |
| 2035 | }; |
| 2036 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 2037 | } else |
| 2038 | PendingVisibleUpdates[ID].push_back(Table); |
| 2039 | break; |
| 2040 | } |
| 2041 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2042 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2043 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 2044 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2045 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2046 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 2047 | Latest > FirstLatestDeclIDs[First]) && |
| 2048 | "The new latest is supposed to come after the previous latest"); |
| 2049 | FirstLatestDeclIDs[First] = Latest; |
| 2050 | } |
| 2051 | break; |
| 2052 | } |
| 2053 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2054 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2055 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2056 | return IgnorePCH; |
| 2057 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2058 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2059 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2060 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2061 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2062 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2063 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2064 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2065 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2066 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2067 | if (PP) |
| 2068 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2069 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2070 | break; |
| 2071 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2072 | case IDENTIFIER_OFFSET: |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2073 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2074 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2075 | return Failure; |
| 2076 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2077 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2078 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2079 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2080 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2081 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2082 | // Optimization for the first block. |
| 2083 | if (ExternalDefinitions.empty()) |
| 2084 | ExternalDefinitions.swap(Record); |
| 2085 | else |
| 2086 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 2087 | Record.begin(), Record.end()); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2088 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2089 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2090 | case SPECIAL_TYPES: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2091 | // Optimization for the first block |
| 2092 | if (SpecialTypes.empty()) |
| 2093 | SpecialTypes.swap(Record); |
| 2094 | else |
| 2095 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2096 | break; |
| 2097 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2098 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2099 | TotalNumStatements += Record[0]; |
| 2100 | TotalNumMacros += Record[1]; |
| 2101 | TotalLexicalDeclContexts += Record[2]; |
| 2102 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2103 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2104 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2105 | case TENTATIVE_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2106 | // Optimization for the first block. |
| 2107 | if (TentativeDefinitions.empty()) |
| 2108 | TentativeDefinitions.swap(Record); |
| 2109 | else |
| 2110 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 2111 | Record.begin(), Record.end()); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2112 | break; |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2113 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2114 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2115 | // Optimization for the first block. |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2116 | if (UnusedFileScopedDecls.empty()) |
| 2117 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2118 | else |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2119 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 2120 | Record.begin(), Record.end()); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2121 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2122 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2123 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2124 | // Later blocks overwrite earlier ones. |
| 2125 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2126 | break; |
| 2127 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2128 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2129 | // Optimization for the first block. |
| 2130 | if (LocallyScopedExternalDecls.empty()) |
| 2131 | LocallyScopedExternalDecls.swap(Record); |
| 2132 | else |
| 2133 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 2134 | Record.begin(), Record.end()); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2135 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2136 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2137 | case SELECTOR_OFFSETS: |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2138 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2139 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2140 | break; |
| 2141 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2142 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2143 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2144 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2145 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2146 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2147 | F.SelectorLookupTableData + Record[0], |
| 2148 | F.SelectorLookupTableData, |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2149 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2150 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2151 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2152 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2153 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2154 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2155 | break; |
| 2156 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2157 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2158 | if (!Record.empty() && Listener) |
| 2159 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2160 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2161 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2162 | case SOURCE_LOCATION_OFFSETS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2163 | F.SLocOffsets = (const uint32_t *)BlobStart; |
| 2164 | F.LocalNumSLocEntries = Record[0]; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2165 | F.LocalSLocSize = Record[1]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2166 | break; |
| 2167 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2168 | case SOURCE_LOCATION_PRELOADS: |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2169 | if (PreloadSLocEntries.empty()) |
| 2170 | PreloadSLocEntries.swap(Record); |
| 2171 | else |
| 2172 | PreloadSLocEntries.insert(PreloadSLocEntries.end(), |
| 2173 | Record.begin(), Record.end()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2174 | break; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2175 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2176 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2177 | if (!DisableStatCache) { |
| 2178 | ASTStatCache *MyStatCache = |
| 2179 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2180 | (const unsigned char *)BlobStart, |
| 2181 | NumStatHits, NumStatMisses); |
| 2182 | FileMgr.addStatCache(MyStatCache); |
| 2183 | F.StatCache = MyStatCache; |
| 2184 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2185 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2186 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2187 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2188 | case EXT_VECTOR_DECLS: |
Sebastian Redl | a9f2368 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 2189 | // Optimization for the first block. |
| 2190 | if (ExtVectorDecls.empty()) |
| 2191 | ExtVectorDecls.swap(Record); |
| 2192 | else |
| 2193 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 2194 | Record.begin(), Record.end()); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2195 | break; |
| 2196 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2197 | case VTABLE_USES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2198 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2199 | VTableUses.swap(Record); |
| 2200 | break; |
| 2201 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2202 | case DYNAMIC_CLASSES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2203 | // Optimization for the first block. |
| 2204 | if (DynamicClasses.empty()) |
| 2205 | DynamicClasses.swap(Record); |
| 2206 | else |
| 2207 | DynamicClasses.insert(DynamicClasses.end(), |
| 2208 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2209 | break; |
| 2210 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2211 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2212 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2213 | break; |
| 2214 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2215 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2216 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2217 | SemaDeclRefs.swap(Record); |
| 2218 | break; |
| 2219 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2220 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2221 | // 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] | 2222 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2223 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2224 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2225 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2226 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2227 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2228 | case ORIGINAL_PCH_DIR: |
| 2229 | // The primary AST will be the last to get here, so it will be the one |
| 2230 | // that's used. |
| 2231 | OriginalDir.assign(BlobStart, BlobLen); |
| 2232 | break; |
| 2233 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2234 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2235 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2236 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 2237 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2238 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2239 | return IgnorePCH; |
| 2240 | } |
| 2241 | break; |
| 2242 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2243 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2244 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2245 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2246 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2247 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2248 | break; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2249 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2250 | case DECL_UPDATE_OFFSETS: { |
| 2251 | if (Record.size() % 2 != 0) { |
| 2252 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2253 | return Failure; |
| 2254 | } |
| 2255 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
| 2256 | DeclUpdateOffsets[static_cast<DeclID>(Record[I])] |
| 2257 | .push_back(std::make_pair(&F, Record[I+1])); |
| 2258 | break; |
| 2259 | } |
| 2260 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2261 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2262 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2263 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2264 | return Failure; |
| 2265 | } |
| 2266 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2267 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2268 | std::make_pair(&F, Record[I+1]); |
| 2269 | break; |
| 2270 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2271 | |
| 2272 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2273 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2274 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2275 | return Failure; |
| 2276 | } |
| 2277 | |
| 2278 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2279 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
| 2280 | break; |
| 2281 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2282 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2283 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2284 | if (Record.size() % 2 != 0) { |
| 2285 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2286 | return Failure; |
| 2287 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2288 | if (PragmaDiagMappings.empty()) |
| 2289 | PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2290 | else |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2291 | PragmaDiagMappings.insert(PragmaDiagMappings.end(), |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2292 | Record.begin(), Record.end()); |
| 2293 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2294 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2295 | case CUDA_SPECIAL_DECL_REFS: |
| 2296 | // Later tables overwrite earlier ones. |
| 2297 | CUDASpecialDeclRefs.swap(Record); |
| 2298 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2299 | |
| 2300 | case HEADER_SEARCH_TABLE: |
| 2301 | F.HeaderFileInfoTableData = BlobStart; |
| 2302 | F.LocalNumHeaderFileInfos = Record[1]; |
| 2303 | if (Record[0]) { |
| 2304 | F.HeaderFileInfoTable |
| 2305 | = HeaderFileInfoLookupTable::Create( |
| 2306 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 2307 | (const unsigned char *)F.HeaderFileInfoTableData); |
| 2308 | if (PP) |
| 2309 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2310 | } |
| 2311 | break; |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2312 | |
| 2313 | case FP_PRAGMA_OPTIONS: |
| 2314 | // Later tables overwrite earlier ones. |
| 2315 | FPPragmaOptions.swap(Record); |
| 2316 | break; |
| 2317 | |
| 2318 | case OPENCL_EXTENSIONS: |
| 2319 | // Later tables overwrite earlier ones. |
| 2320 | OpenCLExtensions.swap(Record); |
| 2321 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2322 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2323 | First = false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2324 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2325 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2326 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2327 | } |
| 2328 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2329 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2330 | ASTFileType Type) { |
| 2331 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2332 | case Failure: return Failure; |
| 2333 | case IgnorePCH: return IgnorePCH; |
| 2334 | case Success: break; |
| 2335 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2336 | |
| 2337 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2338 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2339 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2340 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2341 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2342 | TotalNumSelectors = 0; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2343 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2344 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2345 | NextSLocOffset += Chain[I]->LocalSLocSize; |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2346 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2347 | TotalNumTypes += Chain[I]->LocalNumTypes; |
| 2348 | TotalNumDecls += Chain[I]->LocalNumDecls; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2349 | TotalNumPreallocatedPreprocessingEntities += |
| 2350 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2351 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2352 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2353 | } |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2354 | SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset); |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2355 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2356 | TypesLoaded.resize(TotalNumTypes); |
| 2357 | DeclsLoaded.resize(TotalNumDecls); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2358 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2359 | if (PP) { |
| 2360 | if (TotalNumIdentifiers > 0) |
| 2361 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2362 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2363 | if (!PP->getPreprocessingRecord()) |
| 2364 | PP->createPreprocessingRecord(); |
| 2365 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2366 | TotalNumPreallocatedPreprocessingEntities); |
| 2367 | } |
| 2368 | } |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2369 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2370 | // Preload SLocEntries. |
| 2371 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2372 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2373 | if (Result != Success) |
| 2374 | return Result; |
| 2375 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2376 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2377 | // Check the predefines buffers. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2378 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2379 | return IgnorePCH; |
| 2380 | |
| 2381 | if (PP) { |
| 2382 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2383 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2384 | // loaded into the IdentifierTable before we intercepted the |
| 2385 | // creation of identifiers. Iterate through the list of known |
| 2386 | // identifiers and determine whether we have to establish |
| 2387 | // preprocessor definitions or top-level identifier declaration |
| 2388 | // chains for those identifiers. |
| 2389 | // |
| 2390 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2391 | // since de-serializing declarations or macro definitions can add |
| 2392 | // new entries into the identifier table, invalidating the |
| 2393 | // iterators. |
| 2394 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2395 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2396 | IdEnd = PP->getIdentifierTable().end(); |
| 2397 | Id != IdEnd; ++Id) |
| 2398 | Identifiers.push_back(Id->second); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2399 | // We need to search the tables in all files. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2400 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2401 | ASTIdentifierLookupTable *IdTable |
| 2402 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2403 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2404 | // ones. |
| 2405 | if (!IdTable) |
| 2406 | continue; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2407 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2408 | IdentifierInfo *II = Identifiers[I]; |
| 2409 | // 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] | 2410 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2411 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2412 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2413 | if (Pos == IdTable->end()) |
| 2414 | continue; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2415 | |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2416 | // Dereferencing the iterator has the effect of populating the |
| 2417 | // IdentifierInfo node with the various declarations it needs. |
| 2418 | (void)*Pos; |
| 2419 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2420 | } |
| 2421 | } |
| 2422 | |
| 2423 | if (Context) |
| 2424 | InitializeContext(*Context); |
| 2425 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2426 | if (DeserializationListener) |
| 2427 | DeserializationListener->ReaderInitialized(this); |
| 2428 | |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2429 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2430 | // the source manager to the file source file from which the preamble was |
| 2431 | // built. This is the only valid way to use a precompiled preamble. |
| 2432 | if (Type == Preamble) { |
| 2433 | SourceLocation Loc |
| 2434 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2435 | if (Loc.isValid()) { |
| 2436 | std::pair<FileID, unsigned> Decomposed = SourceMgr.getDecomposedLoc(Loc); |
| 2437 | SourceMgr.SetPreambleFileID(Decomposed.first); |
| 2438 | } |
| 2439 | } |
| 2440 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2441 | return Success; |
| 2442 | } |
| 2443 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2444 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2445 | ASTFileType Type) { |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2446 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2447 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2448 | PerFileData &F = *Chain.back(); |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2449 | if (Prev) |
| 2450 | Prev->NextInSource = &F; |
| 2451 | else |
| 2452 | FirstInSource = &F; |
| 2453 | F.Loaders.push_back(Prev); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2454 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2455 | // Set the AST file name. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2456 | F.FileName = FileName; |
| 2457 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2458 | if (FileName != "-") { |
| 2459 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2460 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2461 | } |
| 2462 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2463 | // Open the AST file. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2464 | // |
| 2465 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2466 | std::string ErrStr; |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 2467 | llvm::error_code ec; |
| 2468 | if (FileName == "-") { |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 2469 | ec = llvm::MemoryBuffer::getSTDIN(F.Buffer); |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 2470 | if (ec) |
| 2471 | ErrStr = ec.message(); |
| 2472 | } else |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2473 | F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr)); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2474 | if (!F.Buffer) { |
| 2475 | Error(ErrStr.c_str()); |
| 2476 | return IgnorePCH; |
| 2477 | } |
| 2478 | |
| 2479 | // Initialize the stream |
| 2480 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2481 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2482 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2483 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2484 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2485 | |
| 2486 | // Sniff for the signature. |
| 2487 | if (Stream.Read(8) != 'C' || |
| 2488 | Stream.Read(8) != 'P' || |
| 2489 | Stream.Read(8) != 'C' || |
| 2490 | Stream.Read(8) != 'H') { |
| 2491 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2492 | return Failure; |
| 2493 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2494 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2495 | while (!Stream.AtEndOfStream()) { |
| 2496 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2497 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2498 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2499 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2500 | return Failure; |
| 2501 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2502 | |
| 2503 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2504 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2505 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2506 | switch (BlockID) { |
| 2507 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2508 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2509 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2510 | return Failure; |
| 2511 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2512 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2513 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2514 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2515 | case Success: |
| 2516 | break; |
| 2517 | |
| 2518 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2519 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2520 | |
| 2521 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2522 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2523 | // AST block, skipping subblocks, to see if there are other |
| 2524 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2525 | |
| 2526 | // Clear out any preallocated source location entries, so that |
| 2527 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2528 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2529 | |
| 2530 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2531 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2532 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2533 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2534 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2535 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2536 | break; |
| 2537 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2538 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2539 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2540 | return Failure; |
| 2541 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2542 | break; |
| 2543 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2544 | } |
| 2545 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2546 | return Success; |
| 2547 | } |
| 2548 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2549 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2550 | PP = &pp; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2551 | |
| 2552 | unsigned TotalNum = 0; |
| 2553 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2554 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2555 | if (TotalNum) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2556 | if (!PP->getPreprocessingRecord()) |
| 2557 | PP->createPreprocessingRecord(); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2558 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2559 | } |
| 2560 | } |
| 2561 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2562 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2563 | Context = &Ctx; |
| 2564 | assert(Context && "Passed null context!"); |
| 2565 | |
| 2566 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2567 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2568 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2569 | PP->setExternalSource(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2570 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2571 | |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2572 | // If we have an update block for the TU waiting, we have to add it before |
| 2573 | // deserializing the decl. |
| 2574 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2575 | if (DCU != DeclContextOffsets.end()) { |
| 2576 | // Insertion could invalidate map, so grab vector. |
| 2577 | DeclContextInfos T; |
| 2578 | T.swap(DCU->second); |
| 2579 | DeclContextOffsets.erase(DCU); |
| 2580 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2581 | } |
| 2582 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2583 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2584 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2585 | |
| 2586 | // Load the special types. |
| 2587 | Context->setBuiltinVaListType( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2588 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2589 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2590 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2591 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2592 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2593 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2594 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2595 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2596 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2597 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2598 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2599 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2600 | if (unsigned FastEnum |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2601 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2602 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2603 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2604 | QualType FileType = GetType(File); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2605 | if (FileType.isNull()) { |
| 2606 | Error("FILE type is NULL"); |
| 2607 | return; |
| 2608 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2609 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2610 | Context->setFILEDecl(Typedef->getDecl()); |
| 2611 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2612 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2613 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2614 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2615 | return; |
| 2616 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2617 | Context->setFILEDecl(Tag->getDecl()); |
| 2618 | } |
| 2619 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2620 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2621 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2622 | if (Jmp_bufType.isNull()) { |
| 2623 | Error("jmp_bug type is NULL"); |
| 2624 | return; |
| 2625 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2626 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2627 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2628 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2629 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2630 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2631 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2632 | return; |
| 2633 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2634 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2635 | } |
| 2636 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2637 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2638 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2639 | if (Sigjmp_bufType.isNull()) { |
| 2640 | Error("sigjmp_buf type is NULL"); |
| 2641 | return; |
| 2642 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2643 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2644 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2645 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2646 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2647 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2648 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2649 | } |
| 2650 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2651 | if (unsigned ObjCIdRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2652 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2653 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2654 | if (unsigned ObjCClassRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2655 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2656 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2657 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2658 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2659 | if (unsigned String |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2660 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2661 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2662 | if (unsigned ObjCSelRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2663 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2664 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2665 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2666 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2667 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2668 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2669 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2670 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2671 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2672 | |
| 2673 | // If there were any CUDA special declarations, deserialize them. |
| 2674 | if (!CUDASpecialDeclRefs.empty()) { |
| 2675 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 2676 | Context->setcudaConfigureCallDecl( |
| 2677 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2678 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2679 | } |
| 2680 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2681 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2682 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2683 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2684 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2685 | FileManager &FileMgr, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2686 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2687 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2688 | std::string ErrStr; |
| 2689 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2690 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2691 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2692 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2693 | return std::string(); |
| 2694 | } |
| 2695 | |
| 2696 | // Initialize the stream |
| 2697 | llvm::BitstreamReader StreamFile; |
| 2698 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2699 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2700 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2701 | Stream.init(StreamFile); |
| 2702 | |
| 2703 | // Sniff for the signature. |
| 2704 | if (Stream.Read(8) != 'C' || |
| 2705 | Stream.Read(8) != 'P' || |
| 2706 | Stream.Read(8) != 'C' || |
| 2707 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2708 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2709 | return std::string(); |
| 2710 | } |
| 2711 | |
| 2712 | RecordData Record; |
| 2713 | while (!Stream.AtEndOfStream()) { |
| 2714 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2715 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2716 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2717 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2718 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2719 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2720 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2721 | case AST_BLOCK_ID: |
| 2722 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2723 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2724 | return std::string(); |
| 2725 | } |
| 2726 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2727 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2728 | default: |
| 2729 | if (Stream.SkipBlock()) { |
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; |
| 2734 | } |
| 2735 | continue; |
| 2736 | } |
| 2737 | |
| 2738 | if (Code == llvm::bitc::END_BLOCK) { |
| 2739 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2740 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2741 | return std::string(); |
| 2742 | } |
| 2743 | continue; |
| 2744 | } |
| 2745 | |
| 2746 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2747 | Stream.ReadAbbrevRecord(); |
| 2748 | continue; |
| 2749 | } |
| 2750 | |
| 2751 | Record.clear(); |
| 2752 | const char *BlobStart = 0; |
| 2753 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2754 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2755 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2756 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2757 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2758 | |
| 2759 | return std::string(); |
| 2760 | } |
| 2761 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2762 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2763 | /// structure. |
| 2764 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2765 | /// This routine parses the language options from the AST file and then gives |
| 2766 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2767 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2768 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2769 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2770 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2771 | if (Listener) { |
| 2772 | LangOptions LangOpts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2773 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2774 | #define PARSE_LANGOPT(Option) \ |
| 2775 | LangOpts.Option = Record[Idx]; \ |
| 2776 | ++Idx |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2777 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2778 | unsigned Idx = 0; |
| 2779 | PARSE_LANGOPT(Trigraphs); |
| 2780 | PARSE_LANGOPT(BCPLComment); |
| 2781 | PARSE_LANGOPT(DollarIdents); |
| 2782 | PARSE_LANGOPT(AsmPreprocessor); |
| 2783 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2784 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2785 | PARSE_LANGOPT(ImplicitInt); |
| 2786 | PARSE_LANGOPT(Digraphs); |
| 2787 | PARSE_LANGOPT(HexFloats); |
| 2788 | PARSE_LANGOPT(C99); |
| 2789 | PARSE_LANGOPT(Microsoft); |
| 2790 | PARSE_LANGOPT(CPlusPlus); |
| 2791 | PARSE_LANGOPT(CPlusPlus0x); |
| 2792 | PARSE_LANGOPT(CXXOperatorNames); |
| 2793 | PARSE_LANGOPT(ObjC1); |
| 2794 | PARSE_LANGOPT(ObjC2); |
| 2795 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 2796 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 2797 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 2798 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 2799 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2800 | PARSE_LANGOPT(PascalStrings); |
| 2801 | PARSE_LANGOPT(WritableStrings); |
| 2802 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2803 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2804 | PARSE_LANGOPT(Exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 2805 | PARSE_LANGOPT(ObjCExceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 2806 | PARSE_LANGOPT(CXXExceptions); |
| 2807 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 2808 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2809 | PARSE_LANGOPT(NeXTRuntime); |
| 2810 | PARSE_LANGOPT(Freestanding); |
| 2811 | PARSE_LANGOPT(NoBuiltin); |
| 2812 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 2813 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2814 | PARSE_LANGOPT(Blocks); |
| 2815 | PARSE_LANGOPT(EmitAllDecls); |
| 2816 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2817 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 2818 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2819 | PARSE_LANGOPT(HeinousExtensions); |
| 2820 | PARSE_LANGOPT(Optimize); |
| 2821 | PARSE_LANGOPT(OptimizeSize); |
| 2822 | PARSE_LANGOPT(Static); |
| 2823 | PARSE_LANGOPT(PICLevel); |
| 2824 | PARSE_LANGOPT(GNUInline); |
| 2825 | PARSE_LANGOPT(NoInline); |
| 2826 | PARSE_LANGOPT(AccessControl); |
| 2827 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2828 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | b1bdced | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 2829 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2830 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2831 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 2832 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2833 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2834 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2835 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 2836 | PARSE_LANGOPT(CUDA); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2837 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2838 | PARSE_LANGOPT(DefaultFPContract); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2839 | // FIXME: Missing ElideConstructors?! |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2840 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2841 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2842 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2843 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2844 | |
| 2845 | return false; |
| 2846 | } |
| 2847 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2848 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2849 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2850 | PerFileData &F = *Chain[I]; |
| 2851 | if (!F.PreprocessorDetailCursor.getBitStreamReader()) |
| 2852 | continue; |
| 2853 | |
| 2854 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 2855 | F.PreprocessorDetailCursor.JumpToBit(F.PreprocessorDetailStartOffset); |
| 2856 | while (LoadPreprocessedEntity(F)) { } |
| 2857 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2858 | } |
| 2859 | |
Douglas Gregor | 0a48029 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 2860 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2861 | PerFileData *F = 0; |
| 2862 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2863 | if (Offset < Chain[I]->SizeInBits) { |
| 2864 | F = Chain[I]; |
| 2865 | break; |
| 2866 | } |
| 2867 | |
| 2868 | Offset -= Chain[I]->SizeInBits; |
| 2869 | } |
| 2870 | |
| 2871 | if (!F) { |
| 2872 | Error("Malformed preprocessed entity offset"); |
| 2873 | return 0; |
| 2874 | } |
| 2875 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2876 | // Keep track of where we are in the stream, then jump back there |
| 2877 | // after reading this entity. |
| 2878 | SavedStreamPosition SavedPosition(F->PreprocessorDetailCursor); |
| 2879 | F->PreprocessorDetailCursor.JumpToBit(Offset); |
| 2880 | return LoadPreprocessedEntity(*F); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2881 | } |
| 2882 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2883 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
| 2884 | HeaderFileInfoTrait Trait(FE->getName()); |
| 2885 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2886 | PerFileData &F = *Chain[I]; |
| 2887 | HeaderFileInfoLookupTable *Table |
| 2888 | = static_cast<HeaderFileInfoLookupTable *>(F.HeaderFileInfoTable); |
| 2889 | if (!Table) |
| 2890 | continue; |
| 2891 | |
| 2892 | // Look in the on-disk hash table for an entry for this file name. |
| 2893 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE->getName(), |
| 2894 | &Trait); |
| 2895 | if (Pos == Table->end()) |
| 2896 | continue; |
| 2897 | |
| 2898 | HeaderFileInfo HFI = *Pos; |
| 2899 | if (Listener) |
| 2900 | Listener->ReadHeaderFileInfo(HFI, FE->getUID()); |
| 2901 | |
| 2902 | return HFI; |
| 2903 | } |
| 2904 | |
| 2905 | return HeaderFileInfo(); |
| 2906 | } |
| 2907 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2908 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2909 | unsigned Idx = 0; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2910 | while (Idx < PragmaDiagMappings.size()) { |
| 2911 | SourceLocation |
| 2912 | Loc = SourceLocation::getFromRawEncoding(PragmaDiagMappings[Idx++]); |
| 2913 | while (1) { |
| 2914 | assert(Idx < PragmaDiagMappings.size() && |
| 2915 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 2916 | if (Idx >= PragmaDiagMappings.size()) |
| 2917 | break; // Something is messed up but at least avoid infinite loop in |
| 2918 | // release build. |
| 2919 | unsigned DiagID = PragmaDiagMappings[Idx++]; |
| 2920 | if (DiagID == (unsigned)-1) |
| 2921 | break; // no more diag/map pairs for this location. |
| 2922 | diag::Mapping Map = (diag::Mapping)PragmaDiagMappings[Idx++]; |
| 2923 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 2924 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2925 | } |
| 2926 | } |
| 2927 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2928 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2929 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2930 | PerFileData *F = 0; |
| 2931 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2932 | F = Chain[N - I - 1]; |
| 2933 | if (Index < F->LocalNumTypes) |
| 2934 | break; |
| 2935 | Index -= F->LocalNumTypes; |
| 2936 | } |
| 2937 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2938 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2942 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2943 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 2944 | /// routine actually reads the record corresponding to the type at the given |
| 2945 | /// location. It is a helper routine for GetType, which deals with reading type |
| 2946 | /// IDs. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2947 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2948 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2949 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2950 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2951 | // Keep track of where we are in the stream, then jump back there |
| 2952 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2953 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2954 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 2955 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 2956 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2957 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 2958 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2959 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2960 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2961 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2962 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2963 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 2964 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2965 | if (Record.size() != 2) { |
| 2966 | Error("Incorrect encoding of extended qualifier type"); |
| 2967 | return QualType(); |
| 2968 | } |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2969 | QualType Base = GetType(Record[0]); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2970 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 2971 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2972 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2973 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2974 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2975 | if (Record.size() != 1) { |
| 2976 | Error("Incorrect encoding of complex type"); |
| 2977 | return QualType(); |
| 2978 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2979 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2980 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2981 | } |
| 2982 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2983 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2984 | if (Record.size() != 1) { |
| 2985 | Error("Incorrect encoding of pointer type"); |
| 2986 | return QualType(); |
| 2987 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2988 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2989 | return Context->getPointerType(PointeeType); |
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_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2993 | if (Record.size() != 1) { |
| 2994 | Error("Incorrect encoding of block 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->getBlockPointerType(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_LVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3002 | if (Record.size() != 1) { |
| 3003 | Error("Incorrect encoding of lvalue reference 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->getLValueReferenceType(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_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3011 | if (Record.size() != 1) { |
| 3012 | Error("Incorrect encoding of rvalue 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->getRValueReferenceType(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_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3020 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3021 | Error("Incorrect encoding of member pointer type"); |
| 3022 | return QualType(); |
| 3023 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3024 | QualType PointeeType = GetType(Record[0]); |
| 3025 | QualType ClassType = GetType(Record[1]); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3026 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3027 | return QualType(); |
| 3028 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3029 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3030 | } |
| 3031 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3032 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3033 | QualType ElementType = GetType(Record[0]); |
| 3034 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3035 | unsigned IndexTypeQuals = Record[2]; |
| 3036 | unsigned Idx = 3; |
| 3037 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3038 | return Context->getConstantArrayType(ElementType, Size, |
| 3039 | ASM, IndexTypeQuals); |
| 3040 | } |
| 3041 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3042 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3043 | QualType ElementType = GetType(Record[0]); |
| 3044 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3045 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3046 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3047 | } |
| 3048 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3049 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3050 | QualType ElementType = GetType(Record[0]); |
| 3051 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3052 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3053 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3054 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 3055 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3056 | ASM, IndexTypeQuals, |
| 3057 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3058 | } |
| 3059 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3060 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3061 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3062 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3063 | return QualType(); |
| 3064 | } |
| 3065 | |
| 3066 | QualType ElementType = GetType(Record[0]); |
| 3067 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3068 | unsigned VecKind = Record[2]; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3069 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3070 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3071 | } |
| 3072 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3073 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3074 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3075 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3076 | return QualType(); |
| 3077 | } |
| 3078 | |
| 3079 | QualType ElementType = GetType(Record[0]); |
| 3080 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3081 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3082 | } |
| 3083 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3084 | case TYPE_FUNCTION_NO_PROTO: { |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3085 | if (Record.size() != 4) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3086 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3087 | return QualType(); |
| 3088 | } |
| 3089 | QualType ResultType = GetType(Record[0]); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3090 | FunctionType::ExtInfo Info(Record[1], Record[2], (CallingConv)Record[3]); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 3091 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3092 | } |
| 3093 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3094 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3095 | QualType ResultType = GetType(Record[0]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3096 | |
| 3097 | FunctionProtoType::ExtProtoInfo EPI; |
| 3098 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
| 3099 | /*regparm*/ Record[2], |
| 3100 | static_cast<CallingConv>(Record[3])); |
| 3101 | |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 3102 | unsigned Idx = 4; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3103 | unsigned NumParams = Record[Idx++]; |
| 3104 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 3105 | for (unsigned I = 0; I != NumParams; ++I) |
| 3106 | ParamTypes.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3107 | |
| 3108 | EPI.Variadic = Record[Idx++]; |
| 3109 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3110 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3111 | EPI.HasExceptionSpec = Record[Idx++]; |
| 3112 | EPI.HasAnyExceptionSpec = Record[Idx++]; |
| 3113 | EPI.NumExceptions = Record[Idx++]; |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 3114 | llvm::SmallVector<QualType, 2> Exceptions; |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3115 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 3116 | Exceptions.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3117 | EPI.Exceptions = Exceptions.data(); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 3118 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3119 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3120 | } |
| 3121 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3122 | case TYPE_UNRESOLVED_USING: |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3123 | return Context->getTypeDeclType( |
| 3124 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 3125 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3126 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3127 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3128 | Error("incorrect encoding of typedef type"); |
| 3129 | return QualType(); |
| 3130 | } |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3131 | TypedefDecl *Decl = cast<TypedefDecl>(GetDecl(Record[0])); |
| 3132 | QualType Canonical = GetType(Record[1]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3133 | if (!Canonical.isNull()) |
| 3134 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3135 | return Context->getTypedefType(Decl, Canonical); |
| 3136 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3137 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3138 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3139 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3140 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3141 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3142 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3143 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3144 | return QualType(); |
| 3145 | } |
| 3146 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3147 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3148 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3149 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3150 | case TYPE_DECLTYPE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3151 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3152 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3153 | case TYPE_AUTO: |
| 3154 | return Context->getAutoType(GetType(Record[0])); |
| 3155 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3156 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3157 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3158 | Error("incorrect encoding of record type"); |
| 3159 | return QualType(); |
| 3160 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3161 | bool IsDependent = Record[0]; |
| 3162 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3163 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3164 | return T; |
| 3165 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3166 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3167 | case TYPE_ENUM: { |
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 enum 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->getEnumType(cast<EnumDecl>(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 | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3177 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3178 | case TYPE_ATTRIBUTED: { |
| 3179 | if (Record.size() != 3) { |
| 3180 | Error("incorrect encoding of attributed type"); |
| 3181 | return QualType(); |
| 3182 | } |
| 3183 | QualType modifiedType = GetType(Record[0]); |
| 3184 | QualType equivalentType = GetType(Record[1]); |
| 3185 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 3186 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 3187 | } |
| 3188 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3189 | case TYPE_PAREN: { |
| 3190 | if (Record.size() != 1) { |
| 3191 | Error("incorrect encoding of paren type"); |
| 3192 | return QualType(); |
| 3193 | } |
| 3194 | QualType InnerType = GetType(Record[0]); |
| 3195 | return Context->getParenType(InnerType); |
| 3196 | } |
| 3197 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3198 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3199 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3200 | Error("incorrect encoding of pack expansion type"); |
| 3201 | return QualType(); |
| 3202 | } |
| 3203 | QualType Pattern = GetType(Record[0]); |
| 3204 | if (Pattern.isNull()) |
| 3205 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3206 | llvm::Optional<unsigned> NumExpansions; |
| 3207 | if (Record[1]) |
| 3208 | NumExpansions = Record[1] - 1; |
| 3209 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3210 | } |
| 3211 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3212 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3213 | unsigned Idx = 0; |
| 3214 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3215 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3216 | QualType NamedType = GetType(Record[Idx++]); |
| 3217 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3220 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3221 | unsigned Idx = 0; |
| 3222 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3223 | return Context->getObjCInterfaceType(ItfD); |
| 3224 | } |
| 3225 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3226 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3227 | unsigned Idx = 0; |
| 3228 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3229 | unsigned NumProtos = Record[Idx++]; |
| 3230 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 3231 | for (unsigned I = 0; I != NumProtos; ++I) |
| 3232 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3233 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3234 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3235 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3236 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3237 | unsigned Idx = 0; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3238 | QualType Pointee = GetType(Record[Idx++]); |
| 3239 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3240 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3241 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3242 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3243 | unsigned Idx = 0; |
| 3244 | QualType Parm = GetType(Record[Idx++]); |
| 3245 | QualType Replacement = GetType(Record[Idx++]); |
| 3246 | return |
| 3247 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3248 | Replacement); |
| 3249 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3250 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3251 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3252 | unsigned Idx = 0; |
| 3253 | QualType Parm = GetType(Record[Idx++]); |
| 3254 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3255 | return Context->getSubstTemplateTypeParmPackType( |
| 3256 | cast<TemplateTypeParmType>(Parm), |
| 3257 | ArgPack); |
| 3258 | } |
| 3259 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3260 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3261 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 3262 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3263 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3264 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3265 | return |
| 3266 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3267 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3268 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3269 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3270 | unsigned Idx = 0; |
| 3271 | unsigned Depth = Record[Idx++]; |
| 3272 | unsigned Index = Record[Idx++]; |
| 3273 | bool Pack = Record[Idx++]; |
| 3274 | IdentifierInfo *Name = GetIdentifierInfo(Record, Idx); |
| 3275 | return Context->getTemplateTypeParmType(Depth, Index, Pack, Name); |
| 3276 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3277 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3278 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3279 | unsigned Idx = 0; |
| 3280 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3281 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3282 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3283 | QualType Canon = GetType(Record[Idx++]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3284 | if (!Canon.isNull()) |
| 3285 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3286 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 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_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +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); |
| 3294 | unsigned NumArgs = Record[Idx++]; |
| 3295 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 3296 | Args.reserve(NumArgs); |
| 3297 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3298 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3299 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3300 | Args.size(), Args.data()); |
| 3301 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3302 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3303 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3304 | unsigned Idx = 0; |
| 3305 | |
| 3306 | // ArrayType |
| 3307 | QualType ElementType = GetType(Record[Idx++]); |
| 3308 | ArrayType::ArraySizeModifier ASM |
| 3309 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3310 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3311 | |
| 3312 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3313 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3314 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3315 | |
| 3316 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3317 | IndexTypeQuals, Brackets); |
| 3318 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3319 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3320 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3321 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3322 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3323 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3324 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3325 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3326 | QualType Canon = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3327 | QualType T; |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3328 | if (Canon.isNull()) |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3329 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3330 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3331 | else |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3332 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
| 3333 | Args.size(), Canon); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3334 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3335 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3336 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3337 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3338 | // Suppress a GCC warning |
| 3339 | return QualType(); |
| 3340 | } |
| 3341 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3342 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3343 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3344 | ASTReader::PerFileData &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3345 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3346 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3347 | unsigned &Idx; |
| 3348 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3349 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3350 | unsigned &I) { |
| 3351 | return Reader.ReadSourceLocation(F, R, I); |
| 3352 | } |
| 3353 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3354 | public: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3355 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3356 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3357 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3358 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3359 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3360 | // We want compile-time assurance that we've enumerated all of |
| 3361 | // these, so unfortunately we have to declare them first, then |
| 3362 | // define them out-of-line. |
| 3363 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3364 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3365 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3366 | #include "clang/AST/TypeLocNodes.def" |
| 3367 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3368 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3369 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3370 | }; |
| 3371 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3372 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3373 | // nothing to do |
| 3374 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3375 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3376 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3377 | if (TL.needsExtraLocalData()) { |
| 3378 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3379 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3380 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3381 | TL.setModeAttr(Record[Idx++]); |
| 3382 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3383 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3384 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3385 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3386 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3387 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3388 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3389 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3390 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3391 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3392 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3393 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3394 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3395 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3396 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3397 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3398 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3399 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3400 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3401 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3402 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3403 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3404 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3405 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3406 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3407 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3408 | TL.setSizeExpr(0); |
| 3409 | } |
| 3410 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3411 | VisitArrayTypeLoc(TL); |
| 3412 | } |
| 3413 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3414 | VisitArrayTypeLoc(TL); |
| 3415 | } |
| 3416 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3417 | VisitArrayTypeLoc(TL); |
| 3418 | } |
| 3419 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3420 | DependentSizedArrayTypeLoc TL) { |
| 3421 | VisitArrayTypeLoc(TL); |
| 3422 | } |
| 3423 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3424 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3425 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3426 | } |
| 3427 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3428 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3429 | } |
| 3430 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3431 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3432 | } |
| 3433 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3434 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3435 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3436 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3437 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | 86acc2a | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 3438 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3439 | } |
| 3440 | } |
| 3441 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3442 | VisitFunctionTypeLoc(TL); |
| 3443 | } |
| 3444 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3445 | VisitFunctionTypeLoc(TL); |
| 3446 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3447 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3448 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3449 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3450 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3451 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3452 | } |
| 3453 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3454 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3455 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3456 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3457 | } |
| 3458 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3459 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3460 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3461 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3462 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3463 | } |
| 3464 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3465 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3466 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3467 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3468 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3469 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3470 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3471 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3472 | } |
| 3473 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3474 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3475 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3476 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3477 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3478 | if (TL.hasAttrOperand()) { |
| 3479 | SourceRange range; |
| 3480 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3481 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3482 | TL.setAttrOperandParensRange(range); |
| 3483 | } |
| 3484 | if (TL.hasAttrExprOperand()) { |
| 3485 | if (Record[Idx++]) |
| 3486 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3487 | else |
| 3488 | TL.setAttrExprOperand(0); |
| 3489 | } else if (TL.hasAttrEnumOperand()) |
| 3490 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3491 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3492 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3493 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3494 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3495 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3496 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3497 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3498 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3499 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3500 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3501 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3502 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3503 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3504 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3505 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3506 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3507 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3508 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3509 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3510 | Reader.GetTemplateArgumentLocInfo(F, |
| 3511 | TL.getTypePtr()->getArg(i).getKind(), |
| 3512 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3513 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3514 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3515 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3516 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3517 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3518 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3519 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3520 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3521 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3522 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3523 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3524 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3525 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3526 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3527 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3528 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3529 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3530 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3531 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3532 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3533 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3534 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3535 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3536 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3537 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3538 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3539 | Reader.GetTemplateArgumentLocInfo(F, |
| 3540 | TL.getTypePtr()->getArg(I).getKind(), |
| 3541 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3542 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3543 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3544 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3545 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3546 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3547 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3548 | } |
| 3549 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3550 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3551 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3552 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3553 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3554 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3555 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3556 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3557 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3558 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3559 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3560 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3561 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3562 | unsigned &Idx) { |
| 3563 | QualType InfoTy = GetType(Record[Idx++]); |
| 3564 | if (InfoTy.isNull()) |
| 3565 | return 0; |
| 3566 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3567 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3568 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3569 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3570 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3571 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3572 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3573 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3574 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3575 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3576 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3577 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3578 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3579 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3580 | switch ((PredefinedTypeIDs)Index) { |
| 3581 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3582 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3583 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3584 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3585 | case PREDEF_TYPE_CHAR_U_ID: |
| 3586 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3587 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3588 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3589 | break; |
| 3590 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3591 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3592 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3593 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3594 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3595 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3596 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3597 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3598 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3599 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3600 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3601 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3602 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3603 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3604 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3605 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3606 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3607 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
| 3608 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
| 3609 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3610 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3611 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3612 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3613 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3614 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3615 | } |
| 3616 | |
| 3617 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3618 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3619 | } |
| 3620 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3621 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3622 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3623 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3624 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3625 | if (TypesLoaded[Index].isNull()) |
| 3626 | return QualType(); |
| 3627 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3628 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3629 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3630 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3631 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3632 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3633 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3634 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3635 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3636 | } |
| 3637 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3638 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3639 | return MakeTypeID(T, |
| 3640 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3641 | } |
| 3642 | |
| 3643 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3644 | if (T.isNull()) |
| 3645 | return TypeIdx(); |
| 3646 | assert(!T.getLocalFastQualifiers()); |
| 3647 | |
| 3648 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3649 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3650 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3651 | // If the type didn't come from the AST file use a specially marked index |
| 3652 | // so that any hash/key comparison fail since no such index is stored |
| 3653 | // in a AST file. |
| 3654 | if (I == TypeIdxs.end()) |
| 3655 | return TypeIdx(-1); |
| 3656 | return I->second; |
| 3657 | } |
| 3658 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3659 | unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const { |
| 3660 | unsigned Result = 0; |
| 3661 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 3662 | Result += Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3663 | |
| 3664 | return Result; |
| 3665 | } |
| 3666 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3667 | TemplateArgumentLocInfo |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3668 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3669 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3670 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3671 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3672 | switch (Kind) { |
| 3673 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3674 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3675 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3676 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3677 | case TemplateArgument::Template: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3678 | SourceRange QualifierRange = ReadSourceRange(F, Record, Index); |
| 3679 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3680 | return TemplateArgumentLocInfo(QualifierRange, TemplateNameLoc, |
| 3681 | SourceLocation()); |
| 3682 | } |
| 3683 | case TemplateArgument::TemplateExpansion: { |
| 3684 | SourceRange QualifierRange = ReadSourceRange(F, Record, Index); |
| 3685 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3686 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
| 3687 | return TemplateArgumentLocInfo(QualifierRange, TemplateNameLoc, |
| 3688 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3689 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3690 | case TemplateArgument::Null: |
| 3691 | case TemplateArgument::Integral: |
| 3692 | case TemplateArgument::Declaration: |
| 3693 | case TemplateArgument::Pack: |
| 3694 | return TemplateArgumentLocInfo(); |
| 3695 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3696 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3697 | return TemplateArgumentLocInfo(); |
| 3698 | } |
| 3699 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3700 | TemplateArgumentLoc |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3701 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3702 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3703 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3704 | |
| 3705 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3706 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3707 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3708 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3709 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3710 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3711 | } |
| 3712 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3713 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3714 | return GetDecl(ID); |
| 3715 | } |
| 3716 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3717 | uint64_t |
| 3718 | ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) { |
| 3719 | if (ID == 0) |
| 3720 | return 0; |
| 3721 | |
| 3722 | --ID; |
| 3723 | uint64_t Offset = 0; |
| 3724 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3725 | if (ID < Chain[I]->LocalNumCXXBaseSpecifiers) |
| 3726 | return Offset + Chain[I]->CXXBaseSpecifiersOffsets[ID]; |
| 3727 | |
| 3728 | ID -= Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3729 | Offset += Chain[I]->SizeInBits; |
| 3730 | } |
| 3731 | |
| 3732 | assert(false && "CXXBaseSpecifiers not found"); |
| 3733 | return 0; |
| 3734 | } |
| 3735 | |
| 3736 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 3737 | // Figure out which AST file contains this offset. |
| 3738 | PerFileData *F = 0; |
| 3739 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3740 | if (Offset < Chain[I]->SizeInBits) { |
| 3741 | F = Chain[I]; |
| 3742 | break; |
| 3743 | } |
| 3744 | |
| 3745 | Offset -= Chain[I]->SizeInBits; |
| 3746 | } |
| 3747 | |
| 3748 | if (!F) { |
| 3749 | Error("Malformed AST file: C++ base specifiers at impossible offset"); |
| 3750 | return 0; |
| 3751 | } |
| 3752 | |
| 3753 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3754 | SavedStreamPosition SavedPosition(Cursor); |
| 3755 | Cursor.JumpToBit(Offset); |
| 3756 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3757 | RecordData Record; |
| 3758 | unsigned Code = Cursor.ReadCode(); |
| 3759 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 3760 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 3761 | Error("Malformed AST file: missing C++ base specifiers"); |
| 3762 | return 0; |
| 3763 | } |
| 3764 | |
| 3765 | unsigned Idx = 0; |
| 3766 | unsigned NumBases = Record[Idx++]; |
| 3767 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 3768 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 3769 | for (unsigned I = 0; I != NumBases; ++I) |
| 3770 | Bases[I] = ReadCXXBaseSpecifier(*F, Record, Idx); |
| 3771 | return Bases; |
| 3772 | } |
| 3773 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3774 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3775 | if (!DeclsLoaded[0]) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 3776 | ReadDeclRecord(0, 1); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3777 | if (DeserializationListener) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3778 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3779 | } |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 3780 | |
| 3781 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 3782 | } |
| 3783 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3784 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3785 | if (ID == 0) |
| 3786 | return 0; |
| 3787 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3788 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3789 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3790 | return 0; |
| 3791 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3792 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3793 | unsigned Index = ID - 1; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3794 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3795 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3796 | if (DeserializationListener) |
| 3797 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3798 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3799 | |
| 3800 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3801 | } |
| 3802 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3803 | /// \brief Resolve the offset of a statement into a statement. |
| 3804 | /// |
| 3805 | /// This operation will read a new statement from the external |
| 3806 | /// source each time it is called, and is meant to be used via a |
| 3807 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3808 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 3809 | // Switch case IDs are per Decl. |
| 3810 | ClearSwitchCaseIDs(); |
| 3811 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3812 | // Offset here is a global offset across the entire chain. |
| 3813 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3814 | PerFileData &F = *Chain[N - I - 1]; |
| 3815 | if (Offset < F.SizeInBits) { |
| 3816 | // Since we know that this statement is part of a decl, make sure to use |
| 3817 | // the decl cursor to read it. |
| 3818 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3819 | return ReadStmtFromStream(F); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3820 | } |
| 3821 | Offset -= F.SizeInBits; |
| 3822 | } |
| 3823 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 3824 | } |
| 3825 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3826 | bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3827 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3828 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3829 | assert(DC->hasExternalLexicalStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3830 | "DeclContext has no lexical decls in storage"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3831 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3832 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 3833 | // at least. |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3834 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 3835 | // so make a copy of the vector. |
| 3836 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3837 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3838 | I != E; ++I) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3839 | // IDs can be 0 if this context doesn't contain declarations. |
| 3840 | if (!I->LexicalDecls) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3841 | continue; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3842 | |
| 3843 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3844 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 3845 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 3846 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 3847 | continue; |
| 3848 | |
| 3849 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3850 | assert(D && "Null decl in lexical decls"); |
| 3851 | Decls.push_back(D); |
| 3852 | } |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3853 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3854 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3855 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3856 | return false; |
| 3857 | } |
| 3858 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3859 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3860 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3861 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3862 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3863 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3864 | if (!Name) |
| 3865 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 3866 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3867 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3868 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 8b12273 | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 3869 | // 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] | 3870 | // and namespaces. For any given name, the last available results replace |
| 3871 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3872 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3873 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3874 | I != E; ++I) { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3875 | if (!I->NameLookupTableData) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3876 | continue; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3877 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3878 | ASTDeclContextNameLookupTable *LookupTable = |
| 3879 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3880 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 3881 | if (Pos == LookupTable->end()) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3882 | continue; |
| 3883 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3884 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 3885 | for (; Data.first != Data.second; ++Data.first) |
| 3886 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3887 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3888 | } |
| 3889 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3890 | ++NumVisibleDeclContextsRead; |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3891 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3892 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3893 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3894 | } |
| 3895 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 3896 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 3897 | assert(DC->hasExternalVisibleStorage() && |
| 3898 | "DeclContext has no visible decls in storage"); |
| 3899 | |
| 3900 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 3901 | // There might be visible decls in multiple parts of the chain, for the TU |
| 3902 | // and namespaces. |
| 3903 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 3904 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3905 | I != E; ++I) { |
| 3906 | if (!I->NameLookupTableData) |
| 3907 | continue; |
| 3908 | |
| 3909 | ASTDeclContextNameLookupTable *LookupTable = |
| 3910 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3911 | for (ASTDeclContextNameLookupTable::item_iterator |
| 3912 | ItemI = LookupTable->item_begin(), |
| 3913 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 3914 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 3915 | = *ItemI; |
| 3916 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 3917 | Decls.clear(); |
| 3918 | for (; Data.first != Data.second; ++Data.first) |
| 3919 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 3920 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 3921 | } |
| 3922 | } |
| 3923 | } |
| 3924 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3925 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3926 | assert(Consumer); |
| 3927 | while (!InterestingDecls.empty()) { |
| 3928 | DeclGroupRef DG(InterestingDecls.front()); |
| 3929 | InterestingDecls.pop_front(); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3930 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3931 | } |
| 3932 | } |
| 3933 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3934 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 3935 | this->Consumer = Consumer; |
| 3936 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3937 | if (!Consumer) |
| 3938 | return; |
| 3939 | |
| 3940 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3941 | // Force deserialization of this decl, which will cause it to be queued for |
| 3942 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 3943 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3944 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 3945 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3946 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3947 | } |
| 3948 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3949 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3950 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3951 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3952 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3953 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3954 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3955 | unsigned NumDeclsLoaded |
| 3956 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 3957 | (Decl *)0); |
| 3958 | unsigned NumIdentifiersLoaded |
| 3959 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 3960 | IdentifiersLoaded.end(), |
| 3961 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3962 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3963 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 3964 | SelectorsLoaded.end(), |
| 3965 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 3966 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3967 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 3968 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 3969 | if (TotalNumSLocEntries) |
| 3970 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 3971 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 3972 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3973 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3974 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3975 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 3976 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 3977 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3978 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3979 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 3980 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3981 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3982 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3983 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 3984 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3985 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3986 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3987 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 3988 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3989 | if (TotalNumStatements) |
| 3990 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 3991 | NumStatementsRead, TotalNumStatements, |
| 3992 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 3993 | if (TotalNumMacros) |
| 3994 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 3995 | NumMacrosRead, TotalNumMacros, |
| 3996 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 3997 | if (TotalLexicalDeclContexts) |
| 3998 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 3999 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4000 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4001 | * 100)); |
| 4002 | if (TotalVisibleDeclContexts) |
| 4003 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4004 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4005 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4006 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4007 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4008 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4009 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4010 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4011 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4012 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4013 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4014 | std::fprintf(stderr, "\n"); |
| 4015 | } |
| 4016 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4017 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4018 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4019 | S.ExternalSource = this; |
| 4020 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4021 | // Makes sure any declarations that were deserialized "too early" |
| 4022 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4023 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4024 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4025 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4026 | |
| 4027 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4028 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4029 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4030 | |
| 4031 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4032 | // them to Sema's list of tentative definitions. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4033 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4034 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4035 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4036 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 4037 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4038 | // If there were any unused file scoped decls, deserialize them and add to |
| 4039 | // Sema's list of unused file scoped decls. |
| 4040 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4041 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4042 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 4043 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4044 | |
| 4045 | // If there were any locally-scoped external declarations, |
| 4046 | // deserialize them and add them to Sema's table of locally-scoped |
| 4047 | // external declarations. |
| 4048 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4049 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4050 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 4051 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4052 | |
| 4053 | // If there were any ext_vector type declarations, deserialize them |
| 4054 | // and add them to Sema's vector of such declarations. |
| 4055 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 4056 | SemaObj->ExtVectorDecls.push_back( |
| 4057 | cast<TypedefDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4058 | |
| 4059 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 4060 | // Can we cut them down before writing them ? |
| 4061 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4062 | // If there were any dynamic classes declarations, deserialize them |
| 4063 | // and add them to Sema's vector of such declarations. |
| 4064 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 4065 | SemaObj->DynamicClasses.push_back( |
| 4066 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4067 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4068 | // Load the offsets of the declarations that Sema references. |
| 4069 | // They will be lazily deserialized when needed. |
| 4070 | if (!SemaDeclRefs.empty()) { |
| 4071 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 4072 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4073 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 4074 | } |
| 4075 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4076 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 4077 | |
| 4078 | // If there are @selector references added them to its pool. This is for |
| 4079 | // implementation of -Wselector. |
| 4080 | if (!F->ReferencedSelectorsData.empty()) { |
| 4081 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 4082 | unsigned I = 0; |
| 4083 | while (I < DataSize) { |
| 4084 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 4085 | SourceLocation SelLoc = ReadSourceLocation( |
| 4086 | *F, F->ReferencedSelectorsData, I); |
| 4087 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | // If there were any pending implicit instantiations, deserialize them |
| 4092 | // and add them to Sema's queue of such instantiations. |
| 4093 | assert(F->PendingInstantiations.size() % 2 == 0 && |
| 4094 | "Expected pairs of entries"); |
| 4095 | for (unsigned Idx = 0, N = F->PendingInstantiations.size(); Idx < N;) { |
| 4096 | ValueDecl *D=cast<ValueDecl>(GetDecl(F->PendingInstantiations[Idx++])); |
| 4097 | SourceLocation Loc = ReadSourceLocation(*F, F->PendingInstantiations,Idx); |
| 4098 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 4099 | } |
| 4100 | } |
| 4101 | |
| 4102 | // The two special data sets below always come from the most recent PCH, |
| 4103 | // which is at the front of the chain. |
| 4104 | PerFileData &F = *Chain.front(); |
| 4105 | |
| 4106 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 4107 | // Sema's list of weak undeclared identifiers. |
| 4108 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 4109 | unsigned Idx = 0; |
| 4110 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 4111 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4112 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4113 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 4114 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 4115 | Sema::WeakInfo WI(AliasId, Loc); |
| 4116 | WI.setUsed(Used); |
| 4117 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 4118 | } |
| 4119 | } |
| 4120 | |
| 4121 | // If there were any VTable uses, deserialize the information and add it |
| 4122 | // to Sema's vector and map of VTable uses. |
| 4123 | if (!VTableUses.empty()) { |
| 4124 | unsigned Idx = 0; |
| 4125 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 4126 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4127 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 4128 | bool DefinitionRequired = VTableUses[Idx++]; |
| 4129 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 4130 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4131 | } |
| 4132 | } |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4133 | |
| 4134 | if (!FPPragmaOptions.empty()) { |
| 4135 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4136 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4137 | } |
| 4138 | |
| 4139 | if (!OpenCLExtensions.empty()) { |
| 4140 | unsigned I = 0; |
| 4141 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4142 | #include "clang/Basic/OpenCLExtensions.def" |
| 4143 | |
| 4144 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4145 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4146 | } |
| 4147 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4148 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4149 | // Try to find this name within our on-disk hash tables. We start with the |
| 4150 | // 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] | 4151 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4152 | ASTIdentifierLookupTable *IdTable |
| 4153 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4154 | if (!IdTable) |
| 4155 | continue; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4156 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4157 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4158 | if (Pos == IdTable->end()) |
| 4159 | continue; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4160 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4161 | // Dereferencing the iterator has the effect of building the |
| 4162 | // IdentifierInfo node and populating it with the various |
| 4163 | // declarations it needs. |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4164 | return *Pos; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4165 | } |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4166 | return 0; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4167 | } |
| 4168 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4169 | namespace clang { |
| 4170 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4171 | /// identifiers stored within a set of AST files. |
| 4172 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4173 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4174 | const ASTReader &Reader; |
| 4175 | |
| 4176 | /// \brief The current index into the chain of AST files stored in |
| 4177 | /// the AST reader. |
| 4178 | unsigned Index; |
| 4179 | |
| 4180 | /// \brief The current position within the identifier lookup table |
| 4181 | /// of the current AST file. |
| 4182 | ASTIdentifierLookupTable::key_iterator Current; |
| 4183 | |
| 4184 | /// \brief The end position within the identifier lookup table of |
| 4185 | /// the current AST file. |
| 4186 | ASTIdentifierLookupTable::key_iterator End; |
| 4187 | |
| 4188 | public: |
| 4189 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4190 | |
| 4191 | virtual llvm::StringRef Next(); |
| 4192 | }; |
| 4193 | } |
| 4194 | |
| 4195 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 4196 | : Reader(Reader), Index(Reader.Chain.size() - 1) { |
| 4197 | ASTIdentifierLookupTable *IdTable |
| 4198 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4199 | Current = IdTable->key_begin(); |
| 4200 | End = IdTable->key_end(); |
| 4201 | } |
| 4202 | |
| 4203 | llvm::StringRef ASTIdentifierIterator::Next() { |
| 4204 | while (Current == End) { |
| 4205 | // If we have exhausted all of our AST files, we're done. |
| 4206 | if (Index == 0) |
| 4207 | return llvm::StringRef(); |
| 4208 | |
| 4209 | --Index; |
| 4210 | ASTIdentifierLookupTable *IdTable |
| 4211 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4212 | Current = IdTable->key_begin(); |
| 4213 | End = IdTable->key_end(); |
| 4214 | } |
| 4215 | |
| 4216 | // We have any identifiers remaining in the current AST file; return |
| 4217 | // the next one. |
| 4218 | std::pair<const char*, unsigned> Key = *Current; |
| 4219 | ++Current; |
| 4220 | return llvm::StringRef(Key.first, Key.second); |
| 4221 | } |
| 4222 | |
| 4223 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4224 | return new ASTIdentifierIterator(*this); |
| 4225 | } |
| 4226 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4227 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4228 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4229 | // Find this selector in a hash table. We want to find the most recent entry. |
| 4230 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4231 | PerFileData &F = *Chain[I]; |
| 4232 | if (!F.SelectorLookupTable) |
| 4233 | continue; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4234 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4235 | ASTSelectorLookupTable *PoolTable |
| 4236 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 4237 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4238 | if (Pos != PoolTable->end()) { |
| 4239 | ++NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4240 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4241 | // disable this tracking when called via LoadSelector. |
| 4242 | // Also, should entries without methods count as misses? |
| 4243 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4244 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4245 | if (DeserializationListener) |
| 4246 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 4247 | return std::make_pair(Data.Instance, Data.Factory); |
| 4248 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4249 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4250 | |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4251 | ++NumMethodPoolMisses; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4252 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4253 | } |
| 4254 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4255 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4256 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4257 | ReadMethodPool(Sel); |
| 4258 | } |
| 4259 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4260 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4261 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4262 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4263 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4264 | if (DeserializationListener) |
| 4265 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4266 | } |
| 4267 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4268 | /// \brief Set the globally-visible declarations associated with the given |
| 4269 | /// identifier. |
| 4270 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4271 | /// 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] | 4272 | /// 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] | 4273 | /// them. |
| 4274 | /// |
| 4275 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4276 | /// declarations. |
| 4277 | /// |
| 4278 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4279 | /// visible at global scope. |
| 4280 | /// |
| 4281 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4282 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4283 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4284 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4285 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4286 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 4287 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4288 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4289 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4290 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4291 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4292 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4293 | return; |
| 4294 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4295 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4296 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4297 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4298 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4299 | if (SemaObj->TUScope) { |
| 4300 | // Introduce this declaration into the translation-unit scope |
| 4301 | // and add it to the declaration chain for this identifier, so |
| 4302 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4303 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4304 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4305 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4306 | } else { |
| 4307 | // Queue this declaration so that it will be added to the |
| 4308 | // translation unit scope and identifier's declaration chain |
| 4309 | // once a Sema object is known. |
| 4310 | PreloadedDecls.push_back(D); |
| 4311 | } |
| 4312 | } |
| 4313 | } |
| 4314 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4315 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4316 | if (ID == 0) |
| 4317 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4318 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4319 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4320 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4321 | return 0; |
| 4322 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4323 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4324 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4325 | ID -= 1; |
| 4326 | if (!IdentifiersLoaded[ID]) { |
| 4327 | unsigned Index = ID; |
| 4328 | const char *Str = 0; |
| 4329 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4330 | PerFileData *F = Chain[N - I - 1]; |
| 4331 | if (Index < F->LocalNumIdentifiers) { |
| 4332 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 4333 | Str = F->IdentifierTableData + Offset; |
| 4334 | break; |
| 4335 | } |
| 4336 | Index -= F->LocalNumIdentifiers; |
| 4337 | } |
| 4338 | assert(Str && "Broken Chain"); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4339 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4340 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4341 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4342 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4343 | // unsigned integers. This is important to avoid integer overflow when |
| 4344 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4345 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4346 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4347 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4348 | IdentifiersLoaded[ID] |
Kovarththanan Rajaratnam | 811f426 | 2010-03-12 10:32:27 +0000 | [diff] [blame] | 4349 | = &PP->getIdentifierTable().get(Str, StrLen); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4350 | if (DeserializationListener) |
| 4351 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4352 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4353 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4354 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4355 | } |
| 4356 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4357 | void ASTReader::ReadSLocEntry(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4358 | ReadSLocEntryRecord(ID); |
| 4359 | } |
| 4360 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4361 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4362 | if (ID == 0) |
| 4363 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4364 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4365 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4366 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4367 | return Selector(); |
| 4368 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4369 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4370 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4371 | // Load this selector from the selector table. |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4372 | unsigned Idx = ID - 1; |
| 4373 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4374 | PerFileData &F = *Chain[N - I - 1]; |
| 4375 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4376 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4377 | SelectorsLoaded[ID - 1] = |
| 4378 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 4379 | if (DeserializationListener) |
| 4380 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 4381 | break; |
| 4382 | } |
| 4383 | Idx -= F.LocalNumSelectors; |
| 4384 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4385 | } |
| 4386 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4387 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4388 | } |
| 4389 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4390 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4391 | return DecodeSelector(ID); |
| 4392 | } |
| 4393 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4394 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4395 | // ID 0 (the null selector) is considered an external selector. |
| 4396 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4397 | } |
| 4398 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4399 | DeclarationName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4400 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4401 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4402 | switch (Kind) { |
| 4403 | case DeclarationName::Identifier: |
| 4404 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 4405 | |
| 4406 | case DeclarationName::ObjCZeroArgSelector: |
| 4407 | case DeclarationName::ObjCOneArgSelector: |
| 4408 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 4409 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4410 | |
| 4411 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4412 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4413 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4414 | |
| 4415 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4416 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4417 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4418 | |
| 4419 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4420 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4421 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4422 | |
| 4423 | case DeclarationName::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4424 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4425 | (OverloadedOperatorKind)Record[Idx++]); |
| 4426 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4427 | case DeclarationName::CXXLiteralOperatorName: |
| 4428 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 4429 | GetIdentifierInfo(Record, Idx)); |
| 4430 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4431 | case DeclarationName::CXXUsingDirective: |
| 4432 | return DeclarationName::getUsingDirectiveName(); |
| 4433 | } |
| 4434 | |
| 4435 | // Required to silence GCC warning |
| 4436 | return DeclarationName(); |
| 4437 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4438 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4439 | void ASTReader::ReadDeclarationNameLoc(PerFileData &F, |
| 4440 | DeclarationNameLoc &DNLoc, |
| 4441 | DeclarationName Name, |
| 4442 | const RecordData &Record, unsigned &Idx) { |
| 4443 | switch (Name.getNameKind()) { |
| 4444 | case DeclarationName::CXXConstructorName: |
| 4445 | case DeclarationName::CXXDestructorName: |
| 4446 | case DeclarationName::CXXConversionFunctionName: |
| 4447 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4448 | break; |
| 4449 | |
| 4450 | case DeclarationName::CXXOperatorName: |
| 4451 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4452 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4453 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4454 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4455 | break; |
| 4456 | |
| 4457 | case DeclarationName::CXXLiteralOperatorName: |
| 4458 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4459 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4460 | break; |
| 4461 | |
| 4462 | case DeclarationName::Identifier: |
| 4463 | case DeclarationName::ObjCZeroArgSelector: |
| 4464 | case DeclarationName::ObjCOneArgSelector: |
| 4465 | case DeclarationName::ObjCMultiArgSelector: |
| 4466 | case DeclarationName::CXXUsingDirective: |
| 4467 | break; |
| 4468 | } |
| 4469 | } |
| 4470 | |
| 4471 | void ASTReader::ReadDeclarationNameInfo(PerFileData &F, |
| 4472 | DeclarationNameInfo &NameInfo, |
| 4473 | const RecordData &Record, unsigned &Idx) { |
| 4474 | NameInfo.setName(ReadDeclarationName(Record, Idx)); |
| 4475 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4476 | DeclarationNameLoc DNLoc; |
| 4477 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4478 | NameInfo.setInfo(DNLoc); |
| 4479 | } |
| 4480 | |
| 4481 | void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info, |
| 4482 | const RecordData &Record, unsigned &Idx) { |
| 4483 | Info.NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4484 | Info.NNSRange = ReadSourceRange(F, Record, Idx); |
| 4485 | unsigned NumTPLists = Record[Idx++]; |
| 4486 | Info.NumTemplParamLists = NumTPLists; |
| 4487 | if (NumTPLists) { |
| 4488 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 4489 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4490 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4491 | } |
| 4492 | } |
| 4493 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4494 | TemplateName |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4495 | ASTReader::ReadTemplateName(PerFileData &F, const RecordData &Record, |
| 4496 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4497 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4498 | switch (Kind) { |
| 4499 | case TemplateName::Template: |
| 4500 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 4501 | |
| 4502 | case TemplateName::OverloadedTemplate: { |
| 4503 | unsigned size = Record[Idx++]; |
| 4504 | UnresolvedSet<8> Decls; |
| 4505 | while (size--) |
| 4506 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 4507 | |
| 4508 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 4509 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4510 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4511 | case TemplateName::QualifiedTemplate: { |
| 4512 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4513 | bool hasTemplKeyword = Record[Idx++]; |
| 4514 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 4515 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 4516 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4517 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4518 | case TemplateName::DependentTemplate: { |
| 4519 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4520 | if (Record[Idx++]) // isIdentifier |
| 4521 | return Context->getDependentTemplateName(NNS, |
| 4522 | GetIdentifierInfo(Record, Idx)); |
| 4523 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4524 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4525 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4526 | |
| 4527 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4528 | TemplateTemplateParmDecl *Param |
| 4529 | = cast_or_null<TemplateTemplateParmDecl>(GetDecl(Record[Idx++])); |
| 4530 | if (!Param) |
| 4531 | return TemplateName(); |
| 4532 | |
| 4533 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 4534 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 4535 | return TemplateName(); |
| 4536 | |
| 4537 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 4538 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4539 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4540 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4541 | assert(0 && "Unhandled template name kind!"); |
| 4542 | return TemplateName(); |
| 4543 | } |
| 4544 | |
| 4545 | TemplateArgument |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4546 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4547 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4548 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 4549 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4550 | case TemplateArgument::Null: |
| 4551 | return TemplateArgument(); |
| 4552 | case TemplateArgument::Type: |
| 4553 | return TemplateArgument(GetType(Record[Idx++])); |
| 4554 | case TemplateArgument::Declaration: |
| 4555 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4556 | case TemplateArgument::Integral: { |
| 4557 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 4558 | QualType T = GetType(Record[Idx++]); |
| 4559 | return TemplateArgument(Value, T); |
| 4560 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4561 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4562 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4563 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4564 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4565 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 4566 | if (unsigned NumExpansions = Record[Idx++]) |
| 4567 | NumTemplateExpansions = NumExpansions - 1; |
| 4568 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4569 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4570 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4571 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4572 | case TemplateArgument::Pack: { |
| 4573 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4574 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 4575 | for (unsigned I = 0; I != NumArgs; ++I) |
| 4576 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 4577 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4578 | } |
| 4579 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4580 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4581 | assert(0 && "Unhandled template argument kind!"); |
| 4582 | return TemplateArgument(); |
| 4583 | } |
| 4584 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4585 | TemplateParameterList * |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4586 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 4587 | const RecordData &Record, unsigned &Idx) { |
| 4588 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 4589 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 4590 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4591 | |
| 4592 | unsigned NumParams = Record[Idx++]; |
| 4593 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 4594 | Params.reserve(NumParams); |
| 4595 | while (NumParams--) |
| 4596 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4597 | |
| 4598 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4599 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 4600 | Params.data(), Params.size(), RAngleLoc); |
| 4601 | return TemplateParams; |
| 4602 | } |
| 4603 | |
| 4604 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4605 | ASTReader:: |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4606 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4607 | PerFileData &F, const RecordData &Record, |
| 4608 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4609 | unsigned NumTemplateArgs = Record[Idx++]; |
| 4610 | TemplArgs.reserve(NumTemplateArgs); |
| 4611 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4612 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4613 | } |
| 4614 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4615 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4616 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4617 | const RecordData &Record, unsigned &Idx) { |
| 4618 | unsigned NumDecls = Record[Idx++]; |
| 4619 | while (NumDecls--) { |
| 4620 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 4621 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 4622 | Set.addDecl(D, AS); |
| 4623 | } |
| 4624 | } |
| 4625 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4626 | CXXBaseSpecifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4627 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4628 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4629 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 4630 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 4631 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4632 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4633 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4634 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4635 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4636 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4637 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4638 | Result.setInheritConstructors(inheritConstructors); |
| 4639 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4640 | } |
| 4641 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4642 | std::pair<CXXCtorInitializer **, unsigned> |
| 4643 | ASTReader::ReadCXXCtorInitializers(PerFileData &F, const RecordData &Record, |
| 4644 | unsigned &Idx) { |
| 4645 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4646 | unsigned NumInitializers = Record[Idx++]; |
| 4647 | if (NumInitializers) { |
| 4648 | ASTContext &C = *getContext(); |
| 4649 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4650 | CtorInitializers |
| 4651 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4652 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 4653 | TypeSourceInfo *BaseClassInfo = 0; |
| 4654 | bool IsBaseVirtual = false; |
| 4655 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4656 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4657 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4658 | bool IsBaseInitializer = Record[Idx++]; |
| 4659 | if (IsBaseInitializer) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4660 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4661 | IsBaseVirtual = Record[Idx++]; |
| 4662 | } else { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4663 | bool IsIndirectMemberInitializer = Record[Idx++]; |
| 4664 | if (IsIndirectMemberInitializer) |
| 4665 | IndirectMember = cast<IndirectFieldDecl>(GetDecl(Record[Idx++])); |
| 4666 | else |
| 4667 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4668 | } |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 4669 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4670 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4671 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 4672 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4673 | bool IsWritten = Record[Idx++]; |
| 4674 | unsigned SourceOrderOrNumArrayIndices; |
| 4675 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 4676 | if (IsWritten) { |
| 4677 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4678 | } else { |
| 4679 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4680 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 4681 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 4682 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 4683 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4684 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4685 | CXXCtorInitializer *BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4686 | if (IsBaseInitializer) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4687 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 4688 | LParenLoc, Init, RParenLoc, |
| 4689 | MemberOrEllipsisLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4690 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4691 | if (Member) |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4692 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 4693 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4694 | else |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4695 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 4696 | MemberOrEllipsisLoc, LParenLoc, |
| 4697 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4698 | } else { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4699 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 4700 | LParenLoc, Init, RParenLoc, |
| 4701 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4702 | } |
| 4703 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 4704 | if (IsWritten) |
| 4705 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4706 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4707 | } |
| 4708 | } |
| 4709 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4710 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4711 | } |
| 4712 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4713 | NestedNameSpecifier * |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4714 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4715 | unsigned N = Record[Idx++]; |
| 4716 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 4717 | for (unsigned I = 0; I != N; ++I) { |
| 4718 | NestedNameSpecifier::SpecifierKind Kind |
| 4719 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4720 | switch (Kind) { |
| 4721 | case NestedNameSpecifier::Identifier: { |
| 4722 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 4723 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 4724 | break; |
| 4725 | } |
| 4726 | |
| 4727 | case NestedNameSpecifier::Namespace: { |
| 4728 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 4729 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 4730 | break; |
| 4731 | } |
| 4732 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 4733 | case NestedNameSpecifier::NamespaceAlias: { |
| 4734 | NamespaceAliasDecl *Alias |
| 4735 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
| 4736 | NNS = NestedNameSpecifier::Create(*Context, Prev, Alias); |
| 4737 | break; |
| 4738 | } |
| 4739 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4740 | case NestedNameSpecifier::TypeSpec: |
| 4741 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4742 | const Type *T = GetType(Record[Idx++]).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 4743 | if (!T) |
| 4744 | return 0; |
| 4745 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4746 | bool Template = Record[Idx++]; |
| 4747 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 4748 | break; |
| 4749 | } |
| 4750 | |
| 4751 | case NestedNameSpecifier::Global: { |
| 4752 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4753 | // No associated value, and there can't be a prefix. |
| 4754 | break; |
| 4755 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4756 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 4757 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4758 | } |
| 4759 | return NNS; |
| 4760 | } |
| 4761 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4762 | NestedNameSpecifierLoc |
| 4763 | ASTReader::ReadNestedNameSpecifierLoc(PerFileData &F, const RecordData &Record, |
| 4764 | unsigned &Idx) { |
| 4765 | unsigned N = Record[Idx++]; |
| 4766 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 4767 | llvm::SmallVector<char, 32> LocationData; |
| 4768 | for (unsigned I = 0; I != N; ++I) { |
| 4769 | NestedNameSpecifier::SpecifierKind Kind |
| 4770 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4771 | switch (Kind) { |
| 4772 | case NestedNameSpecifier::Identifier: { |
| 4773 | // Nested-name-specifier |
| 4774 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 4775 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 4776 | |
| 4777 | // Location information |
| 4778 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 4779 | unsigned RawStart = Range.getBegin().getRawEncoding(); |
| 4780 | unsigned RawEnd = Range.getEnd().getRawEncoding(); |
| 4781 | LocationData.append(reinterpret_cast<char*>(&RawStart), |
| 4782 | reinterpret_cast<char*>(&RawStart) +sizeof(unsigned)); |
| 4783 | LocationData.append(reinterpret_cast<char*>(&RawEnd), |
| 4784 | reinterpret_cast<char*>(&RawEnd) + sizeof(unsigned)); |
| 4785 | break; |
| 4786 | } |
| 4787 | |
| 4788 | case NestedNameSpecifier::Namespace: { |
| 4789 | // Nested-name-specifier |
| 4790 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 4791 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 4792 | |
| 4793 | // Location information |
| 4794 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 4795 | unsigned RawStart = Range.getBegin().getRawEncoding(); |
| 4796 | unsigned RawEnd = Range.getEnd().getRawEncoding(); |
| 4797 | LocationData.append(reinterpret_cast<char*>(&RawStart), |
| 4798 | reinterpret_cast<char*>(&RawStart) +sizeof(unsigned)); |
| 4799 | LocationData.append(reinterpret_cast<char*>(&RawEnd), |
| 4800 | reinterpret_cast<char*>(&RawEnd) + sizeof(unsigned)); |
| 4801 | break; |
| 4802 | } |
| 4803 | |
| 4804 | case NestedNameSpecifier::NamespaceAlias: { |
| 4805 | // Nested-name-specifier |
| 4806 | NamespaceAliasDecl *Alias |
| 4807 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
| 4808 | NNS = NestedNameSpecifier::Create(*Context, Prev, Alias); |
| 4809 | |
| 4810 | // Location information |
| 4811 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 4812 | unsigned RawStart = Range.getBegin().getRawEncoding(); |
| 4813 | unsigned RawEnd = Range.getEnd().getRawEncoding(); |
| 4814 | LocationData.append(reinterpret_cast<char*>(&RawStart), |
| 4815 | reinterpret_cast<char*>(&RawStart) +sizeof(unsigned)); |
| 4816 | LocationData.append(reinterpret_cast<char*>(&RawEnd), |
| 4817 | reinterpret_cast<char*>(&RawEnd) + sizeof(unsigned)); |
| 4818 | |
| 4819 | break; |
| 4820 | } |
| 4821 | |
| 4822 | case NestedNameSpecifier::TypeSpec: |
| 4823 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 4824 | // Nested-name-specifier |
| 4825 | bool Template = Record[Idx++]; |
| 4826 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 4827 | if (!T) |
| 4828 | return NestedNameSpecifierLoc(); |
| 4829 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, |
| 4830 | T->getType().getTypePtr()); |
| 4831 | |
| 4832 | // Location information. |
| 4833 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 4834 | unsigned RawLocation = ColonColonLoc.getRawEncoding(); |
| 4835 | void *OpaqueTypeData = T->getTypeLoc().getOpaqueData(); |
| 4836 | LocationData.append(reinterpret_cast<char*>(&OpaqueTypeData), |
| 4837 | (reinterpret_cast<char*>(&OpaqueTypeData) |
| 4838 | + sizeof(void *))); |
| 4839 | LocationData.append(reinterpret_cast<char*>(&RawLocation), |
| 4840 | (reinterpret_cast<char*>(&RawLocation) + |
| 4841 | sizeof(unsigned))); |
| 4842 | break; |
| 4843 | } |
| 4844 | |
| 4845 | case NestedNameSpecifier::Global: { |
| 4846 | // Nested-name-specifier |
| 4847 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4848 | |
| 4849 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 4850 | unsigned RawLocation = ColonColonLoc.getRawEncoding(); |
| 4851 | LocationData.append(reinterpret_cast<char*>(&RawLocation), |
| 4852 | (reinterpret_cast<char*>(&RawLocation) + |
| 4853 | sizeof(unsigned))); |
| 4854 | break; |
| 4855 | } |
| 4856 | } |
| 4857 | Prev = NNS; |
| 4858 | } |
| 4859 | |
| 4860 | void *Mem = Context->Allocate(LocationData.size(), llvm::alignOf<void*>()); |
| 4861 | memcpy(Mem, LocationData.data(), LocationData.size()); |
| 4862 | return NestedNameSpecifierLoc(NNS, Mem); |
| 4863 | } |
| 4864 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4865 | SourceRange |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4866 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 4867 | unsigned &Idx) { |
| 4868 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 4869 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 4870 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4871 | } |
| 4872 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4873 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4874 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4875 | unsigned BitWidth = Record[Idx++]; |
| 4876 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 4877 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 4878 | Idx += NumWords; |
| 4879 | return Result; |
| 4880 | } |
| 4881 | |
| 4882 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4883 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4884 | bool isUnsigned = Record[Idx++]; |
| 4885 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 4886 | } |
| 4887 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4888 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4889 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4890 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 4891 | } |
| 4892 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4893 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4894 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4895 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 4896 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4897 | Idx += Len; |
| 4898 | return Result; |
| 4899 | } |
| 4900 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4901 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4902 | unsigned &Idx) { |
| 4903 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 4904 | return CXXTemporary::Create(*Context, Decl); |
| 4905 | } |
| 4906 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4907 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 4908 | return Diag(SourceLocation(), DiagID); |
| 4909 | } |
| 4910 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4911 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4912 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4913 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4914 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4915 | /// \brief Retrieve the identifier table associated with the |
| 4916 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4917 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4918 | assert(PP && "Forgot to set Preprocessor ?"); |
| 4919 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4920 | } |
| 4921 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4922 | /// \brief Record that the given ID maps to the given switch-case |
| 4923 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4924 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4925 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 4926 | SwitchCaseStmts[ID] = SC; |
| 4927 | } |
| 4928 | |
| 4929 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4930 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4931 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 4932 | return SwitchCaseStmts[ID]; |
| 4933 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4934 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4935 | void ASTReader::ClearSwitchCaseIDs() { |
| 4936 | SwitchCaseStmts.clear(); |
| 4937 | } |
| 4938 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4939 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4940 | assert(NumCurrentElementsDeserializing && |
| 4941 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 4942 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4943 | // If any identifiers with corresponding top-level declarations have |
| 4944 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4945 | while (!PendingIdentifierInfos.empty()) { |
| 4946 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 4947 | PendingIdentifierInfos.front().DeclIDs, true); |
| 4948 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4949 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4950 | |
Argyrios Kyrtzidis | 0895d15 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 4951 | // Ready to load previous declarations of Decls that were delayed. |
| 4952 | while (!PendingPreviousDecls.empty()) { |
| 4953 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 4954 | PendingPreviousDecls.front().second); |
| 4955 | PendingPreviousDecls.pop_front(); |
| 4956 | } |
| 4957 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4958 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 4959 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4960 | if (Consumer) |
| 4961 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 4962 | |
| 4963 | assert(PendingForwardRefs.size() == 0 && |
| 4964 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4965 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4966 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4967 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4968 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4969 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4970 | const char *isysroot, bool DisableValidation, |
| 4971 | bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4972 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 4973 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 4974 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
| 4975 | Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4976 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 4977 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), NextSLocOffset(0), |
| 4978 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 4979 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 4980 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 4981 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
| 4982 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 4983 | NumCurrentElementsDeserializing(0) |
| 4984 | { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4985 | RelocatablePCH = false; |
| 4986 | } |
| 4987 | |
| 4988 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 4989 | Diagnostic &Diags, const char *isysroot, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4990 | bool DisableValidation, bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4991 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
| 4992 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4993 | isysroot(isysroot), DisableValidation(DisableValidation), |
| 4994 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 4995 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4996 | NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0), |
| 4997 | NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), |
| 4998 | NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
| 4999 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 5000 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 5001 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5002 | RelocatablePCH = false; |
| 5003 | } |
| 5004 | |
| 5005 | ASTReader::~ASTReader() { |
| 5006 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 5007 | delete Chain[e - i - 1]; |
| 5008 | // Delete all visible decl lookup tables |
| 5009 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 5010 | E = DeclContextOffsets.end(); |
| 5011 | I != E; ++I) { |
| 5012 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 5013 | J != F; ++J) { |
| 5014 | if (J->NameLookupTableData) |
| 5015 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 5016 | J->NameLookupTableData); |
| 5017 | } |
| 5018 | } |
| 5019 | for (DeclContextVisibleUpdatesPending::iterator |
| 5020 | I = PendingVisibleUpdates.begin(), |
| 5021 | E = PendingVisibleUpdates.end(); |
| 5022 | I != E; ++I) { |
| 5023 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5024 | F = I->second.end(); |
| 5025 | J != F; ++J) |
| 5026 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 5027 | } |
| 5028 | } |
| 5029 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 5030 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
| 5031 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5032 | LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), |
| 5033 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5034 | MacroDefinitionOffsets(0), |
| 5035 | LocalNumHeaderFileInfos(0), HeaderFileInfoTableData(0), |
| 5036 | HeaderFileInfoTable(0), |
| 5037 | LocalNumSelectors(0), SelectorOffsets(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5038 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5039 | DeclOffsets(0), LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
| 5040 | LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 5041 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5042 | {} |
| 5043 | |
| 5044 | ASTReader::PerFileData::~PerFileData() { |
| 5045 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5046 | delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5047 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 5048 | } |