Sebastian Redl | 904c9c8 | 2010-08-18 23:57:11 +0000 | [diff] [blame] | 1 | //===--- ASTReader.cpp - AST File Reader ------------------------*- C++ -*-===// |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 10 | // This file defines the ASTReader class, which reads AST files. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 13 | |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTReader.h" |
| 15 | #include "clang/Serialization/ASTDeserializationListener.h" |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 16 | #include "ASTCommon.h" |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 17 | #include "clang/Frontend/FrontendDiagnostic.h" |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/Utils.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 19 | #include "clang/Sema/Sema.h" |
John McCall | 5f1e094 | 2010-08-24 08:50:51 +0000 | [diff] [blame] | 20 | #include "clang/Sema/Scope.h" |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 21 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 22 | #include "clang/AST/ASTContext.h" |
John McCall | 2a7fb27 | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 24 | #include "clang/AST/Expr.h" |
John McCall | 7a1fad3 | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 26 | #include "clang/AST/NestedNameSpecifier.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 27 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 28 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 29 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 30 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 31 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 32 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 33 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 34 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 35 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 36 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 37 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 38 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 39 | #include "clang/Basic/Version.h" |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 40 | #include "clang/Basic/VersionTuple.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 41 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 42 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 43 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 44 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 45 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 46 | #include "llvm/Support/Path.h" |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 47 | #include "llvm/Support/system_error.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 48 | #include <algorithm> |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 49 | #include <iterator> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 50 | #include <cstdio> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 51 | #include <sys/stat.h> |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 52 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 53 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 54 | using namespace clang::serialization; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 55 | |
| 56 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 57 | // PCH validator implementation |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 58 | //===----------------------------------------------------------------------===// |
| 59 | |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 60 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 61 | |
| 62 | bool |
| 63 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 64 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 65 | #define PARSE_LANGOPT_BENIGN(Option) |
| 66 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 67 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 68 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 69 | return true; \ |
| 70 | } |
| 71 | |
| 72 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 73 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 74 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 75 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 76 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 77 | PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 78 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 79 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 80 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 81 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
Peter Collingbourne | 7e7fbd0 | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 82 | PARSE_LANGOPT_IMPORTANT(C1X, diag::warn_pch_c1x); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 83 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 84 | PARSE_LANGOPT_BENIGN(MSCVersion); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 85 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 86 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 87 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 88 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 89 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 90 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 91 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 92 | PARSE_LANGOPT_IMPORTANT(AppleKext, diag::warn_pch_apple_kext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 93 | PARSE_LANGOPT_IMPORTANT(ObjCDefaultSynthProperties, |
| 94 | diag::warn_pch_objc_auto_properties); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 95 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 96 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 97 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 98 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 99 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 100 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 101 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 102 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 103 | PARSE_LANGOPT_IMPORTANT(ObjCExceptions, diag::warn_pch_objc_exceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 104 | PARSE_LANGOPT_IMPORTANT(CXXExceptions, diag::warn_pch_cxx_exceptions); |
| 105 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 106 | PARSE_LANGOPT_IMPORTANT(MSBitfields, diag::warn_pch_ms_bitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 107 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 108 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 109 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 110 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 111 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 112 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 113 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 114 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 115 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 116 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 117 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 118 | diag::warn_pch_heinous_extensions); |
| 119 | // FIXME: Most of the options below are benign if the macro wasn't |
| 120 | // used. Unfortunately, this means that a PCH compiled without |
| 121 | // optimization can't be used with optimization turned on, even |
| 122 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 123 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 124 | // doesn't matter. We could consider making this some special kind |
| 125 | // of check. |
| 126 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 127 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 128 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 129 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 130 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 131 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
Chandler Carruth | 0d2d1bc | 2011-04-23 20:05:38 +0000 | [diff] [blame^] | 132 | PARSE_LANGOPT_IMPORTANT(Deprecated, diag::warn_pch_deprecated); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 133 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 134 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 135 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 136 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 137 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 139 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 140 | return true; |
| 141 | } |
| 142 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 143 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 144 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 145 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 146 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 147 | PARSE_LANGOPT_IMPORTANT(CUDA, diag::warn_pch_cuda); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 148 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 149 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 150 | PARSE_LANGOPT_BENIGN(SpellChecking); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 151 | PARSE_LANGOPT_BENIGN(DefaultFPContract); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 152 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 153 | #undef PARSE_LANGOPT_BENIGN |
| 154 | |
| 155 | return false; |
| 156 | } |
| 157 | |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 158 | bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) { |
| 159 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 160 | return false; |
| 161 | |
| 162 | Reader.Diag(diag::warn_pch_target_triple) |
| 163 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 164 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 167 | namespace { |
| 168 | struct EmptyStringRef { |
| 169 | bool operator ()(llvm::StringRef r) const { return r.empty(); } |
| 170 | }; |
| 171 | struct EmptyBlock { |
| 172 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 173 | }; |
| 174 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 175 | |
| 176 | static bool EqualConcatenations(llvm::SmallVector<llvm::StringRef, 2> L, |
| 177 | PCHPredefinesBlocks R) { |
| 178 | // First, sum up the lengths. |
| 179 | unsigned LL = 0, RL = 0; |
| 180 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 181 | LL += L[I].size(); |
| 182 | } |
| 183 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 184 | RL += R[I].Data.size(); |
| 185 | } |
| 186 | if (LL != RL) |
| 187 | return false; |
| 188 | if (LL == 0 && RL == 0) |
| 189 | return true; |
| 190 | |
| 191 | // Kick out empty parts, they confuse the algorithm below. |
| 192 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 193 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 194 | |
| 195 | // Do it the hard way. At this point, both vectors must be non-empty. |
| 196 | llvm::StringRef LR = L[0], RR = R[0].Data; |
| 197 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 198 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 199 | for (;;) { |
| 200 | // Compare the current pieces. |
| 201 | if (LR.size() == RR.size()) { |
| 202 | // If they're the same length, it's pretty easy. |
| 203 | if (LR != RR) |
| 204 | return false; |
| 205 | // Both pieces are done, advance. |
| 206 | ++LI; |
| 207 | ++RI; |
| 208 | // If either string is done, they're both done, since they're the same |
| 209 | // length. |
| 210 | if (LI == LN) { |
| 211 | assert(RI == RN && "Strings not the same length after all?"); |
| 212 | return true; |
| 213 | } |
| 214 | LR = L[LI]; |
| 215 | RR = R[RI].Data; |
| 216 | } else if (LR.size() < RR.size()) { |
| 217 | // Right piece is longer. |
| 218 | if (!RR.startswith(LR)) |
| 219 | return false; |
| 220 | ++LI; |
| 221 | assert(LI != LN && "Strings not the same length after all?"); |
| 222 | RR = RR.substr(LR.size()); |
| 223 | LR = L[LI]; |
| 224 | } else { |
| 225 | // Left piece is longer. |
| 226 | if (!LR.startswith(RR)) |
| 227 | return false; |
| 228 | ++RI; |
| 229 | assert(RI != RN && "Strings not the same length after all?"); |
| 230 | LR = LR.substr(RR.size()); |
| 231 | RR = R[RI].Data; |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | static std::pair<FileID, llvm::StringRef::size_type> |
| 237 | FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) { |
| 238 | std::pair<FileID, llvm::StringRef::size_type> Res; |
| 239 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 240 | Res.second = Buffers[I].Data.find(MacroDef); |
| 241 | if (Res.second != llvm::StringRef::npos) { |
| 242 | Res.first = Buffers[I].BufferID; |
| 243 | break; |
| 244 | } |
| 245 | } |
| 246 | return Res; |
| 247 | } |
| 248 | |
| 249 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 250 | llvm::StringRef OriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 251 | std::string &SuggestedPredefines, |
| 252 | FileManager &FileMgr) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 253 | // We are in the context of an implicit include, so the predefines buffer will |
| 254 | // have a #include entry for the PCH file itself (as normalized by the |
| 255 | // preprocessor initialization). Find it and skip over it in the checking |
| 256 | // below. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 257 | llvm::SmallString<256> PCHInclude; |
| 258 | PCHInclude += "#include \""; |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 259 | PCHInclude += NormalizeDashIncludePath(OriginalFileName, FileMgr); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 260 | PCHInclude += "\"\n"; |
| 261 | std::pair<llvm::StringRef,llvm::StringRef> Split = |
| 262 | llvm::StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 263 | llvm::StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 264 | if (Left == PP.getPredefines()) { |
| 265 | Error("Missing PCH include entry!"); |
| 266 | return true; |
| 267 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 268 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 269 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 270 | // command line, we're done. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 271 | llvm::SmallVector<llvm::StringRef, 2> CommandLine; |
| 272 | CommandLine.push_back(Left); |
| 273 | CommandLine.push_back(Right); |
| 274 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 275 | return false; |
| 276 | |
| 277 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 278 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 279 | // The predefines buffers are different. Determine what the differences are, |
| 280 | // and whether they require us to reject the PCH file. |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 281 | llvm::SmallVector<llvm::StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 282 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 283 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 284 | |
| 285 | llvm::SmallVector<llvm::StringRef, 8> CmdLineLines; |
| 286 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 287 | |
| 288 | // Pick out implicit #includes after the PCH and don't consider them for |
| 289 | // validation; we will insert them into SuggestedPredefines so that the |
| 290 | // preprocessor includes them. |
| 291 | std::string IncludesAfterPCH; |
| 292 | llvm::SmallVector<llvm::StringRef, 8> AfterPCHLines; |
| 293 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 294 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 295 | if (AfterPCHLines[i].startswith("#include ")) { |
| 296 | IncludesAfterPCH += AfterPCHLines[i]; |
| 297 | IncludesAfterPCH += '\n'; |
| 298 | } else { |
| 299 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | // Make sure we add the includes last into SuggestedPredefines before we |
| 304 | // exit this function. |
| 305 | struct AddIncludesRAII { |
| 306 | std::string &SuggestedPredefines; |
| 307 | std::string &IncludesAfterPCH; |
| 308 | |
| 309 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 310 | std::string &IncludesAfterPCH) |
| 311 | : SuggestedPredefines(SuggestedPredefines), |
| 312 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 313 | ~AddIncludesRAII() { |
| 314 | SuggestedPredefines += IncludesAfterPCH; |
| 315 | } |
| 316 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 317 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 318 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 319 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 320 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 321 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 322 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 323 | // Determine which predefines that were used to build the PCH file are missing |
| 324 | // from the command line. |
| 325 | std::vector<llvm::StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 326 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 327 | CmdLineLines.begin(), CmdLineLines.end(), |
| 328 | std::back_inserter(MissingPredefines)); |
| 329 | |
| 330 | bool MissingDefines = false; |
| 331 | bool ConflictingDefines = false; |
| 332 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 333 | llvm::StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 334 | if (Missing.startswith("#include ")) { |
| 335 | // An -include was specified when generating the PCH; it is included in |
| 336 | // the PCH, just ignore it. |
| 337 | continue; |
| 338 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 339 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 340 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 341 | return true; |
| 342 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 343 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 344 | // This is a macro definition. Determine the name of the macro we're |
| 345 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 346 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 347 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 348 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 349 | assert(EndOfMacroName != std::string::npos && |
| 350 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 351 | llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 352 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 353 | // Determine whether this macro was given a different definition on the |
| 354 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 355 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 356 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 357 | llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 358 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 359 | MacroDefStart); |
| 360 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 361 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 362 | // Different macro; we're done. |
| 363 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 365 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 366 | |
| 367 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 368 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 369 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 370 | (*ConflictPos)[MacroDefLen] != '(') |
| 371 | continue; // Longer macro name; keep trying. |
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 | // We found a conflicting macro definition. |
| 374 | break; |
| 375 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 376 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 377 | if (ConflictPos != CmdLineLines.end()) { |
| 378 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 379 | << MacroName; |
| 380 | |
| 381 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 382 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 383 | FindMacro(Buffers, Missing); |
| 384 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 385 | SourceLocation PCHMissingLoc = |
| 386 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 387 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 388 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 389 | |
| 390 | ConflictingDefines = true; |
| 391 | continue; |
| 392 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 393 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 394 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 395 | // 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] | 396 | if (ConflictingDefines) |
| 397 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 399 | if (!MissingDefines) { |
| 400 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 401 | MissingDefines = true; |
| 402 | } |
| 403 | |
| 404 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 405 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 406 | FindMacro(Buffers, Missing); |
| 407 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 408 | SourceLocation PCHMissingLoc = |
| 409 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 410 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 411 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 412 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 413 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 414 | if (ConflictingDefines) |
| 415 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 416 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 417 | // Determine what predefines were introduced based on command-line |
| 418 | // parameters that were not present when building the PCH |
| 419 | // file. Extra #defines are okay, so long as the identifiers being |
| 420 | // defined were not used within the precompiled header. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 421 | std::vector<llvm::StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 422 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 423 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 424 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 425 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 426 | llvm::StringRef &Extra = ExtraPredefines[I]; |
| 427 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 428 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 429 | return true; |
| 430 | } |
| 431 | |
| 432 | // This is an extra macro definition. Determine the name of the |
| 433 | // macro we're defining. |
| 434 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 435 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 436 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 437 | assert(EndOfMacroName != std::string::npos && |
| 438 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 439 | llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 440 | |
| 441 | // Check whether this name was used somewhere in the PCH file. If |
| 442 | // so, defining it as a macro could change behavior, so we reject |
| 443 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 444 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 445 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 446 | return true; |
| 447 | } |
| 448 | |
| 449 | // Add this definition to the suggested predefines buffer. |
| 450 | SuggestedPredefines += Extra; |
| 451 | SuggestedPredefines += '\n'; |
| 452 | } |
| 453 | |
| 454 | // If we get here, it's because the predefines buffer had compatible |
| 455 | // contents. Accept the PCH file. |
| 456 | return false; |
| 457 | } |
| 458 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 459 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 460 | unsigned ID) { |
| 461 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 462 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | void PCHValidator::ReadCounter(unsigned Value) { |
| 466 | PP.setCounterValue(Value); |
| 467 | } |
| 468 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 469 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 470 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 471 | //===----------------------------------------------------------------------===// |
| 472 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 473 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 474 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 475 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 476 | } |
| 477 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 478 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 479 | namespace { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 480 | class ASTSelectorLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 481 | ASTReader &Reader; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 482 | |
| 483 | public: |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 484 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 485 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 486 | ObjCMethodList Instance, Factory; |
| 487 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 488 | |
| 489 | typedef Selector external_key_type; |
| 490 | typedef external_key_type internal_key_type; |
| 491 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 492 | explicit ASTSelectorLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 493 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 494 | static bool EqualKey(const internal_key_type& a, |
| 495 | const internal_key_type& b) { |
| 496 | return a == b; |
| 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 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 500 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 501 | } |
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 | // This hopefully will just get inlined and removed by the optimizer. |
| 504 | static const internal_key_type& |
| 505 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 507 | static std::pair<unsigned, unsigned> |
| 508 | ReadKeyDataLength(const unsigned char*& d) { |
| 509 | using namespace clang::io; |
| 510 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 511 | unsigned DataLen = ReadUnalignedLE16(d); |
| 512 | return std::make_pair(KeyLen, DataLen); |
| 513 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 514 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 515 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 516 | using namespace clang::io; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 517 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 518 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 | IdentifierInfo *FirstII |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 520 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 521 | if (N == 0) |
| 522 | return SelTable.getNullarySelector(FirstII); |
| 523 | else if (N == 1) |
| 524 | return SelTable.getUnarySelector(FirstII); |
| 525 | |
| 526 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 527 | Args.push_back(FirstII); |
| 528 | for (unsigned I = 1; I != N; ++I) |
| 529 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 530 | |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 531 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 532 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 534 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 535 | using namespace clang::io; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 536 | |
| 537 | data_type Result; |
| 538 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 539 | Result.ID = ReadUnalignedLE32(d); |
| 540 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 541 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 542 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 543 | // Load instance methods |
| 544 | ObjCMethodList *Prev = 0; |
| 545 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 546 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 547 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 548 | if (!Result.Instance.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 549 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 550 | Result.Instance.Method = Method; |
| 551 | Prev = &Result.Instance; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 552 | continue; |
| 553 | } |
| 554 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 555 | ObjCMethodList *Mem = |
| 556 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 557 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 558 | Prev = Prev->Next; |
| 559 | } |
| 560 | |
| 561 | // Load factory methods |
| 562 | Prev = 0; |
| 563 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 564 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 565 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 566 | if (!Result.Factory.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 567 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 568 | Result.Factory.Method = Method; |
| 569 | Prev = &Result.Factory; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 570 | continue; |
| 571 | } |
| 572 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 573 | ObjCMethodList *Mem = |
| 574 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 575 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 576 | Prev = Prev->Next; |
| 577 | } |
| 578 | |
| 579 | return Result; |
| 580 | } |
| 581 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 582 | |
| 583 | } // end anonymous namespace |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 584 | |
| 585 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 586 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 587 | ASTSelectorLookupTable; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 588 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 589 | namespace clang { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 590 | class ASTIdentifierLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 591 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 592 | ASTReader::PerFileData &F; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 593 | |
| 594 | // If we know the IdentifierInfo in advance, it is here and we will |
| 595 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 596 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 597 | IdentifierInfo *KnownII; |
| 598 | |
| 599 | public: |
| 600 | typedef IdentifierInfo * data_type; |
| 601 | |
| 602 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 603 | |
| 604 | typedef external_key_type internal_key_type; |
| 605 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 606 | ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 607 | IdentifierInfo *II = 0) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 608 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 609 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 610 | static bool EqualKey(const internal_key_type& a, |
| 611 | const internal_key_type& b) { |
| 612 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 613 | : false; |
| 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 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 617 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 618 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 619 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 620 | // This hopefully will just get inlined and removed by the optimizer. |
| 621 | static const internal_key_type& |
| 622 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 623 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 624 | // This hopefully will just get inlined and removed by the optimizer. |
| 625 | static const external_key_type& |
| 626 | GetExternalKey(const internal_key_type& x) { return x; } |
| 627 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 628 | static std::pair<unsigned, unsigned> |
| 629 | ReadKeyDataLength(const unsigned char*& d) { |
| 630 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 631 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 632 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 633 | return std::make_pair(KeyLen, DataLen); |
| 634 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 636 | static std::pair<const char*, unsigned> |
| 637 | ReadKey(const unsigned char* d, unsigned n) { |
| 638 | assert(n >= 2 && d[n-1] == '\0'); |
| 639 | return std::make_pair((const char*) d, n-1); |
| 640 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 641 | |
| 642 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 643 | const unsigned char* d, |
| 644 | unsigned DataLen) { |
| 645 | using namespace clang::io; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 646 | IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 647 | bool IsInteresting = ID & 0x01; |
| 648 | |
| 649 | // Wipe out the "is interesting" bit. |
| 650 | ID = ID >> 1; |
| 651 | |
| 652 | if (!IsInteresting) { |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 653 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 654 | // and associate it with the persistent ID. |
| 655 | IdentifierInfo *II = KnownII; |
| 656 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 657 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 658 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 659 | II->setIsFromAST(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 660 | return II; |
| 661 | } |
| 662 | |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 663 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 664 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 665 | Bits >>= 1; |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 666 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 667 | Bits >>= 1; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 668 | bool Poisoned = Bits & 0x01; |
| 669 | Bits >>= 1; |
| 670 | bool ExtensionToken = Bits & 0x01; |
| 671 | Bits >>= 1; |
| 672 | bool hasMacroDefinition = Bits & 0x01; |
| 673 | Bits >>= 1; |
| 674 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 675 | Bits >>= 10; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 677 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 678 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 679 | |
| 680 | // Build the IdentifierInfo itself and link the identifier ID with |
| 681 | // the new IdentifierInfo. |
| 682 | IdentifierInfo *II = KnownII; |
| 683 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 684 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 685 | Reader.SetIdentifierInfo(ID, II); |
| 686 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 687 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 688 | // Token IDs are read-only. |
| 689 | if (HasRevertedTokenIDToIdentifier) |
| 690 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 691 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 693 | "Incorrect extension token flag"); |
| 694 | (void)ExtensionToken; |
| 695 | II->setIsPoisoned(Poisoned); |
| 696 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 697 | "Incorrect C++ operator keyword flag"); |
| 698 | (void)CPlusPlusOperatorKeyword; |
| 699 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 700 | // If this identifier is a macro, deserialize the macro |
| 701 | // definition. |
| 702 | if (hasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 703 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 704 | Reader.SetIdentifierIsMacro(II, F, Offset); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 705 | DataLen -= 4; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 706 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 707 | |
| 708 | // Read all of the declarations visible at global scope with this |
| 709 | // name. |
Chris Lattner | 6bf690f | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 710 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 711 | if (DataLen > 0) { |
| 712 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 713 | for (; DataLen > 0; DataLen -= 4) |
| 714 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 715 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 716 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 717 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 718 | II->setIsFromAST(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 719 | return II; |
| 720 | } |
| 721 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | |
| 723 | } // end anonymous namespace |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 724 | |
| 725 | /// \brief The on-disk hash table used to contain information about |
| 726 | /// all of the identifiers in the program. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 727 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 728 | ASTIdentifierLookupTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 729 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 730 | namespace { |
| 731 | class ASTDeclContextNameLookupTrait { |
| 732 | ASTReader &Reader; |
| 733 | |
| 734 | public: |
| 735 | /// \brief Pair of begin/end iterators for DeclIDs. |
| 736 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 737 | |
| 738 | /// \brief Special internal key for declaration names. |
| 739 | /// The hash table creates keys for comparison; we do not create |
| 740 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 741 | struct DeclNameKey { |
| 742 | DeclarationName::NameKind Kind; |
| 743 | uint64_t Data; |
| 744 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 745 | }; |
| 746 | |
| 747 | typedef DeclarationName external_key_type; |
| 748 | typedef DeclNameKey internal_key_type; |
| 749 | |
| 750 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
| 751 | |
| 752 | static bool EqualKey(const internal_key_type& a, |
| 753 | const internal_key_type& b) { |
| 754 | return a.Kind == b.Kind && a.Data == b.Data; |
| 755 | } |
| 756 | |
| 757 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 758 | llvm::FoldingSetNodeID ID; |
| 759 | ID.AddInteger(Key.Kind); |
| 760 | |
| 761 | switch (Key.Kind) { |
| 762 | case DeclarationName::Identifier: |
| 763 | case DeclarationName::CXXLiteralOperatorName: |
| 764 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 765 | break; |
| 766 | case DeclarationName::ObjCZeroArgSelector: |
| 767 | case DeclarationName::ObjCOneArgSelector: |
| 768 | case DeclarationName::ObjCMultiArgSelector: |
| 769 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 770 | break; |
| 771 | case DeclarationName::CXXConstructorName: |
| 772 | case DeclarationName::CXXDestructorName: |
| 773 | case DeclarationName::CXXConversionFunctionName: |
| 774 | ID.AddInteger((TypeID)Key.Data); |
| 775 | break; |
| 776 | case DeclarationName::CXXOperatorName: |
| 777 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 778 | break; |
| 779 | case DeclarationName::CXXUsingDirective: |
| 780 | break; |
| 781 | } |
| 782 | |
| 783 | return ID.ComputeHash(); |
| 784 | } |
| 785 | |
| 786 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 787 | DeclNameKey Key; |
| 788 | Key.Kind = Name.getNameKind(); |
| 789 | switch (Name.getNameKind()) { |
| 790 | case DeclarationName::Identifier: |
| 791 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 792 | break; |
| 793 | case DeclarationName::ObjCZeroArgSelector: |
| 794 | case DeclarationName::ObjCOneArgSelector: |
| 795 | case DeclarationName::ObjCMultiArgSelector: |
| 796 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 797 | break; |
| 798 | case DeclarationName::CXXConstructorName: |
| 799 | case DeclarationName::CXXDestructorName: |
| 800 | case DeclarationName::CXXConversionFunctionName: |
| 801 | Key.Data = Reader.GetTypeID(Name.getCXXNameType()); |
| 802 | break; |
| 803 | case DeclarationName::CXXOperatorName: |
| 804 | Key.Data = Name.getCXXOverloadedOperator(); |
| 805 | break; |
| 806 | case DeclarationName::CXXLiteralOperatorName: |
| 807 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 808 | break; |
| 809 | case DeclarationName::CXXUsingDirective: |
| 810 | break; |
| 811 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 812 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 813 | return Key; |
| 814 | } |
| 815 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 816 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 817 | ASTContext *Context = Reader.getContext(); |
| 818 | switch (Key.Kind) { |
| 819 | case DeclarationName::Identifier: |
| 820 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 821 | |
| 822 | case DeclarationName::ObjCZeroArgSelector: |
| 823 | case DeclarationName::ObjCOneArgSelector: |
| 824 | case DeclarationName::ObjCMultiArgSelector: |
| 825 | return DeclarationName(Selector(Key.Data)); |
| 826 | |
| 827 | case DeclarationName::CXXConstructorName: |
| 828 | return Context->DeclarationNames.getCXXConstructorName( |
| 829 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 830 | |
| 831 | case DeclarationName::CXXDestructorName: |
| 832 | return Context->DeclarationNames.getCXXDestructorName( |
| 833 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 834 | |
| 835 | case DeclarationName::CXXConversionFunctionName: |
| 836 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 837 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 838 | |
| 839 | case DeclarationName::CXXOperatorName: |
| 840 | return Context->DeclarationNames.getCXXOperatorName( |
| 841 | (OverloadedOperatorKind)Key.Data); |
| 842 | |
| 843 | case DeclarationName::CXXLiteralOperatorName: |
| 844 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 845 | (IdentifierInfo*)Key.Data); |
| 846 | |
| 847 | case DeclarationName::CXXUsingDirective: |
| 848 | return DeclarationName::getUsingDirectiveName(); |
| 849 | } |
| 850 | |
| 851 | llvm_unreachable("Invalid Name Kind ?"); |
| 852 | } |
| 853 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 854 | static std::pair<unsigned, unsigned> |
| 855 | ReadKeyDataLength(const unsigned char*& d) { |
| 856 | using namespace clang::io; |
| 857 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 858 | unsigned DataLen = ReadUnalignedLE16(d); |
| 859 | return std::make_pair(KeyLen, DataLen); |
| 860 | } |
| 861 | |
| 862 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 863 | using namespace clang::io; |
| 864 | |
| 865 | DeclNameKey Key; |
| 866 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 867 | switch (Key.Kind) { |
| 868 | case DeclarationName::Identifier: |
| 869 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 870 | break; |
| 871 | case DeclarationName::ObjCZeroArgSelector: |
| 872 | case DeclarationName::ObjCOneArgSelector: |
| 873 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 874 | Key.Data = |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 875 | (uint64_t)Reader.DecodeSelector(ReadUnalignedLE32(d)).getAsOpaquePtr(); |
| 876 | break; |
| 877 | case DeclarationName::CXXConstructorName: |
| 878 | case DeclarationName::CXXDestructorName: |
| 879 | case DeclarationName::CXXConversionFunctionName: |
| 880 | Key.Data = ReadUnalignedLE32(d); // TypeID |
| 881 | break; |
| 882 | case DeclarationName::CXXOperatorName: |
| 883 | Key.Data = *d++; // OverloadedOperatorKind |
| 884 | break; |
| 885 | case DeclarationName::CXXLiteralOperatorName: |
| 886 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 887 | break; |
| 888 | case DeclarationName::CXXUsingDirective: |
| 889 | break; |
| 890 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 891 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 892 | return Key; |
| 893 | } |
| 894 | |
| 895 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 896 | unsigned DataLen) { |
| 897 | using namespace clang::io; |
| 898 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 899 | DeclID *Start = (DeclID *)d; |
| 900 | return std::make_pair(Start, Start + NumDecls); |
| 901 | } |
| 902 | }; |
| 903 | |
| 904 | } // end anonymous namespace |
| 905 | |
| 906 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 907 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 908 | ASTDeclContextNameLookupTable; |
| 909 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 910 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 911 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 912 | DeclContextInfo &Info) { |
| 913 | SavedStreamPosition SavedPosition(Cursor); |
| 914 | // First the lexical decls. |
| 915 | if (Offsets.first != 0) { |
| 916 | Cursor.JumpToBit(Offsets.first); |
| 917 | |
| 918 | RecordData Record; |
| 919 | const char *Blob; |
| 920 | unsigned BlobLen; |
| 921 | unsigned Code = Cursor.ReadCode(); |
| 922 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 923 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 924 | Error("Expected lexical block"); |
| 925 | return true; |
| 926 | } |
| 927 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 928 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 929 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 930 | } else { |
| 931 | Info.LexicalDecls = 0; |
| 932 | Info.NumLexicalDecls = 0; |
| 933 | } |
| 934 | |
| 935 | // Now the lookup table. |
| 936 | if (Offsets.second != 0) { |
| 937 | Cursor.JumpToBit(Offsets.second); |
| 938 | |
| 939 | RecordData Record; |
| 940 | const char *Blob; |
| 941 | unsigned BlobLen; |
| 942 | unsigned Code = Cursor.ReadCode(); |
| 943 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 944 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 945 | Error("Expected visible lookup table block"); |
| 946 | return true; |
| 947 | } |
| 948 | Info.NameLookupTableData |
| 949 | = ASTDeclContextNameLookupTable::Create( |
| 950 | (const unsigned char *)Blob + Record[0], |
| 951 | (const unsigned char *)Blob, |
| 952 | ASTDeclContextNameLookupTrait(*this)); |
Sebastian Redl | 0ea8f7f | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 953 | } else { |
| 954 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | return false; |
| 958 | } |
| 959 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 960 | void ASTReader::Error(const char *Msg) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 961 | Diag(diag::err_fe_pch_malformed) << Msg; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 962 | } |
| 963 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 964 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 965 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 966 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 967 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 968 | ActualOriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 969 | SuggestedPredefines, |
| 970 | FileMgr); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 971 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 974 | //===----------------------------------------------------------------------===// |
| 975 | // Source Manager Deserialization |
| 976 | //===----------------------------------------------------------------------===// |
| 977 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 978 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 979 | /// \returns true if there was an error. |
| 980 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 981 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 982 | unsigned Idx = 0; |
| 983 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 984 | |
| 985 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 986 | std::map<int, int> FileIDs; |
| 987 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 988 | // Extract the file name |
| 989 | unsigned FilenameLen = Record[Idx++]; |
| 990 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 991 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 992 | MaybeAddSystemRootToFilename(Filename); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 993 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 994 | Filename.size()); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | // Parse the line entries |
| 998 | std::vector<LineEntry> Entries; |
| 999 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1000 | int FID = Record[Idx++]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1001 | |
| 1002 | // Extract the line entries |
| 1003 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1004 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1005 | Entries.clear(); |
| 1006 | Entries.reserve(NumEntries); |
| 1007 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1008 | unsigned FileOffset = Record[Idx++]; |
| 1009 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1010 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1011 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1012 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1013 | unsigned IncludeOffset = Record[Idx++]; |
| 1014 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1015 | FileKind, IncludeOffset)); |
| 1016 | } |
| 1017 | LineTable.AddEntry(FID, Entries); |
| 1018 | } |
| 1019 | |
| 1020 | return false; |
| 1021 | } |
| 1022 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1023 | namespace { |
| 1024 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1025 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1026 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1027 | const ino_t ino; |
| 1028 | const dev_t dev; |
| 1029 | const mode_t mode; |
| 1030 | const time_t mtime; |
| 1031 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1032 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1033 | 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] | 1034 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1035 | }; |
| 1036 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1037 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1038 | public: |
| 1039 | typedef const char *external_key_type; |
| 1040 | typedef const char *internal_key_type; |
| 1041 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1042 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1043 | |
| 1044 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1045 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1049 | |
| 1050 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1051 | return strcmp(a, b) == 0; |
| 1052 | } |
| 1053 | |
| 1054 | static std::pair<unsigned, unsigned> |
| 1055 | ReadKeyDataLength(const unsigned char*& d) { |
| 1056 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1057 | unsigned DataLen = (unsigned) *d++; |
| 1058 | return std::make_pair(KeyLen + 1, DataLen); |
| 1059 | } |
| 1060 | |
| 1061 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1062 | return (const char *)d; |
| 1063 | } |
| 1064 | |
| 1065 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1066 | unsigned /*DataLen*/) { |
| 1067 | using namespace clang::io; |
| 1068 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1069 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1070 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1071 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1072 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1073 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1074 | return data_type(ino, dev, mode, mtime, size); |
| 1075 | } |
| 1076 | }; |
| 1077 | |
| 1078 | /// \brief stat() cache for precompiled headers. |
| 1079 | /// |
| 1080 | /// This cache is very similar to the stat cache used by pretokenized |
| 1081 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1082 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1083 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1084 | CacheTy *Cache; |
| 1085 | |
| 1086 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1087 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1088 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1089 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1090 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1091 | Cache = CacheTy::Create(Buckets, Base); |
| 1092 | } |
| 1093 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1094 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1095 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1096 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1097 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1098 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1099 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1100 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1101 | // 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] | 1102 | if (I == Cache->end()) { |
| 1103 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1104 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1105 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1107 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1108 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1109 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1110 | StatBuf.st_ino = Data.ino; |
| 1111 | StatBuf.st_dev = Data.dev; |
| 1112 | StatBuf.st_mtime = Data.mtime; |
| 1113 | StatBuf.st_mode = Data.mode; |
| 1114 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1115 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1116 | } |
| 1117 | }; |
| 1118 | } // end anonymous namespace |
| 1119 | |
| 1120 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1121 | /// \brief Read a source manager block |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1122 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1123 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1124 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1125 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1126 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1127 | // Set the source-location entry cursor to the current position in |
| 1128 | // the stream. This cursor will be used to read the contents of the |
| 1129 | // source manager block initially, and then lazily read |
| 1130 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1131 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1132 | |
| 1133 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1134 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1135 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1136 | return Failure; |
| 1137 | } |
| 1138 | |
| 1139 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1140 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1141 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1142 | return Failure; |
| 1143 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1144 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1145 | RecordData Record; |
| 1146 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1147 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1148 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1149 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1150 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1151 | return Failure; |
| 1152 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1153 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1154 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1155 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1156 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1157 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1158 | SLocEntryCursor.ReadSubBlockID(); |
| 1159 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1160 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1161 | return Failure; |
| 1162 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1163 | continue; |
| 1164 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1165 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1166 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1167 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1168 | continue; |
| 1169 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1170 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1171 | // Read a record. |
| 1172 | const char *BlobStart; |
| 1173 | unsigned BlobLen; |
| 1174 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1175 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1176 | default: // Default behavior: ignore. |
| 1177 | break; |
| 1178 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1179 | case SM_LINE_TABLE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1180 | if (ParseLineTable(F, Record)) |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1181 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1182 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1183 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1184 | case SM_SLOC_FILE_ENTRY: |
| 1185 | case SM_SLOC_BUFFER_ENTRY: |
| 1186 | case SM_SLOC_INSTANTIATION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1187 | // Once we hit one of the source location entries, we're done. |
| 1188 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1193 | /// \brief If a header file is not found at the path that we expect it to be |
| 1194 | /// and the PCH file was moved from its original location, try to resolve the |
| 1195 | /// file by assuming that header+PCH were moved together and the header is in |
| 1196 | /// the same place relative to the PCH. |
| 1197 | static std::string |
| 1198 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1199 | const std::string &OriginalDir, |
| 1200 | const std::string &CurrDir) { |
| 1201 | assert(OriginalDir != CurrDir && |
| 1202 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1203 | using namespace llvm::sys; |
| 1204 | llvm::SmallString<128> filePath(Filename); |
| 1205 | fs::make_absolute(filePath); |
| 1206 | assert(path::is_absolute(OriginalDir)); |
| 1207 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1208 | |
| 1209 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1210 | fileDirE = path::end(path::parent_path(filePath)); |
| 1211 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1212 | origDirE = path::end(OriginalDir); |
| 1213 | // Skip the common path components from filePath and OriginalDir. |
| 1214 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1215 | *fileDirI == *origDirI) { |
| 1216 | ++fileDirI; |
| 1217 | ++origDirI; |
| 1218 | } |
| 1219 | for (; origDirI != origDirE; ++origDirI) |
| 1220 | path::append(currPCHPath, ".."); |
| 1221 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1222 | path::append(currPCHPath, path::filename(Filename)); |
| 1223 | return currPCHPath.str(); |
| 1224 | } |
| 1225 | |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1226 | /// \brief Get a cursor that's correctly positioned for reading the source |
| 1227 | /// location entry with the given ID. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1228 | ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1229 | assert(ID != 0 && ID <= TotalNumSLocEntries && |
| 1230 | "SLocCursorForID should only be called for real IDs."); |
| 1231 | |
| 1232 | ID -= 1; |
| 1233 | PerFileData *F = 0; |
| 1234 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1235 | F = Chain[N - I - 1]; |
| 1236 | if (ID < F->LocalNumSLocEntries) |
| 1237 | break; |
| 1238 | ID -= F->LocalNumSLocEntries; |
| 1239 | } |
| 1240 | assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); |
| 1241 | |
| 1242 | F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1243 | return F; |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1246 | /// \brief Read in the source location entry with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1247 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1248 | if (ID == 0) |
| 1249 | return Success; |
| 1250 | |
| 1251 | if (ID > TotalNumSLocEntries) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1252 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1253 | return Failure; |
| 1254 | } |
| 1255 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1256 | PerFileData *F = SLocCursorForID(ID); |
| 1257 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1258 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1259 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1260 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1261 | if (Code == llvm::bitc::END_BLOCK || |
| 1262 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1263 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1264 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1265 | return Failure; |
| 1266 | } |
| 1267 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1268 | RecordData Record; |
| 1269 | const char *BlobStart; |
| 1270 | unsigned BlobLen; |
| 1271 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1272 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1273 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1274 | return Failure; |
| 1275 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1276 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1277 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1278 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1279 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1280 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1281 | OriginalDir != CurrentDir) { |
| 1282 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1283 | OriginalDir, |
| 1284 | CurrentDir); |
| 1285 | if (!resolved.empty()) |
| 1286 | File = FileMgr.getFile(resolved); |
| 1287 | } |
Axel Naumann | 0433116 | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1288 | if (File == 0) |
| 1289 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1290 | (time_t)Record[5]); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1291 | if (File == 0) { |
| 1292 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1293 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1294 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1295 | Error(ErrorStr.c_str()); |
| 1296 | return Failure; |
| 1297 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1298 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1299 | if (Record.size() < 6) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1300 | Error("source location entry is incorrect"); |
| 1301 | return Failure; |
| 1302 | } |
| 1303 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1304 | if (!DisableValidation && |
| 1305 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1306 | #if !defined(LLVM_ON_WIN32) |
| 1307 | // In our regression testing, the Windows file system seems to |
| 1308 | // have inconsistent modification times that sometimes |
| 1309 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1310 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1311 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1312 | )) { |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1313 | Diag(diag::err_fe_pch_file_modified) |
| 1314 | << Filename; |
| 1315 | return Failure; |
| 1316 | } |
| 1317 | |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1318 | FileID FID = SourceMgr.createFileID(File, ReadSourceLocation(*F, Record[1]), |
| 1319 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1320 | ID, Record[0]); |
| 1321 | if (Record[3]) |
| 1322 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1323 | .setHasLineDirectives(); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1324 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1325 | break; |
| 1326 | } |
| 1327 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1328 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1329 | const char *Name = BlobStart; |
| 1330 | unsigned Offset = Record[0]; |
| 1331 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1332 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1334 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1335 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1336 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1337 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1338 | return Failure; |
| 1339 | } |
| 1340 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1341 | llvm::MemoryBuffer *Buffer |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1342 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1343 | Name); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1344 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1345 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1346 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1347 | PCHPredefinesBlock Block = { |
| 1348 | BufferID, |
| 1349 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1350 | }; |
| 1351 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1352 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1353 | |
| 1354 | break; |
| 1355 | } |
| 1356 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1357 | case SM_SLOC_INSTANTIATION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1358 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1359 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1360 | ReadSourceLocation(*F, Record[2]), |
| 1361 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1362 | Record[4], |
| 1363 | ID, |
| 1364 | Record[0]); |
| 1365 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1366 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | return Success; |
| 1370 | } |
| 1371 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1372 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1373 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1374 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1375 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1376 | unsigned BlockID) { |
| 1377 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1378 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1379 | return Failure; |
| 1380 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1381 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1382 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1383 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1384 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1385 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1386 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1387 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1388 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1389 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1390 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1391 | Cursor.ReadAbbrevRecord(); |
| 1392 | } |
| 1393 | } |
| 1394 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1395 | PreprocessedEntity *ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1396 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1397 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1399 | // Keep track of where we are in the stream, then jump back there |
| 1400 | // after reading this macro. |
| 1401 | SavedStreamPosition SavedPosition(Stream); |
| 1402 | |
| 1403 | Stream.JumpToBit(Offset); |
| 1404 | RecordData Record; |
| 1405 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1406 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1408 | while (true) { |
| 1409 | unsigned Code = Stream.ReadCode(); |
| 1410 | switch (Code) { |
| 1411 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1412 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1413 | |
| 1414 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1415 | // No known subblocks, always skip them. |
| 1416 | Stream.ReadSubBlockID(); |
| 1417 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1418 | Error("malformed block record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1419 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1420 | } |
| 1421 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1422 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1423 | case llvm::bitc::DEFINE_ABBREV: |
| 1424 | Stream.ReadAbbrevRecord(); |
| 1425 | continue; |
| 1426 | default: break; |
| 1427 | } |
| 1428 | |
| 1429 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1430 | const char *BlobStart = 0; |
| 1431 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1432 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1433 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1434 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1435 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1436 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1437 | case PP_MACRO_OBJECT_LIKE: |
| 1438 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1439 | // If we already have a macro, that means that we've hit the end |
| 1440 | // of the definition of the macro we were looking for. We're |
| 1441 | // done. |
| 1442 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1443 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1444 | |
| 1445 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1446 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1447 | Error("macro must have a name in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1448 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1449 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1450 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1451 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1452 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1453 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1454 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1455 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1456 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1457 | unsigned NextIndex = 3; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1458 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1459 | // Decode function-like macro info. |
| 1460 | bool isC99VarArgs = Record[3]; |
| 1461 | bool isGNUVarArgs = Record[4]; |
| 1462 | MacroArgs.clear(); |
| 1463 | unsigned NumArgs = Record[5]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1464 | NextIndex = 6 + NumArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1465 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1466 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1467 | |
| 1468 | // Install function-like macro info. |
| 1469 | MI->setIsFunctionLike(); |
| 1470 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1471 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1472 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1473 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1477 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1478 | |
| 1479 | // Remember that we saw this macro last so that we add the tokens that |
| 1480 | // form its body to it. |
| 1481 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1482 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1483 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1484 | // We have a macro definition. Load it now. |
| 1485 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1486 | getMacroDefinition(Record[NextIndex])); |
| 1487 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1488 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1489 | ++NumMacrosRead; |
| 1490 | break; |
| 1491 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1492 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1493 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1494 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1495 | // erroneous, just pretend we didn't see this. |
| 1496 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1497 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1498 | Token Tok; |
| 1499 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1500 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1501 | Tok.setLength(Record[1]); |
| 1502 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1503 | Tok.setIdentifierInfo(II); |
| 1504 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1505 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1506 | Macro->AddTokenToBody(Tok); |
| 1507 | break; |
| 1508 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1509 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1510 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1511 | |
| 1512 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1515 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(PerFileData &F) { |
| 1516 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1517 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1518 | switch (Code) { |
| 1519 | case llvm::bitc::END_BLOCK: |
| 1520 | return 0; |
| 1521 | |
| 1522 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1523 | Error("unexpected subblock record in preprocessor detail block"); |
| 1524 | return 0; |
| 1525 | |
| 1526 | case llvm::bitc::DEFINE_ABBREV: |
| 1527 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1528 | return 0; |
| 1529 | |
| 1530 | default: |
| 1531 | break; |
| 1532 | } |
| 1533 | |
| 1534 | if (!PP->getPreprocessingRecord()) { |
| 1535 | Error("no preprocessing record"); |
| 1536 | return 0; |
| 1537 | } |
| 1538 | |
| 1539 | // Read the record. |
| 1540 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1541 | const char *BlobStart = 0; |
| 1542 | unsigned BlobLen = 0; |
| 1543 | RecordData Record; |
| 1544 | PreprocessorDetailRecordTypes RecType = |
| 1545 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1546 | Code, Record, BlobStart, BlobLen); |
| 1547 | switch (RecType) { |
| 1548 | case PPD_MACRO_INSTANTIATION: { |
| 1549 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1550 | return PE; |
| 1551 | |
| 1552 | MacroInstantiation *MI |
| 1553 | = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), |
| 1554 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1555 | ReadSourceLocation(F, Record[2])), |
| 1556 | getMacroDefinition(Record[4])); |
| 1557 | PPRec.SetPreallocatedEntity(Record[0], MI); |
| 1558 | return MI; |
| 1559 | } |
| 1560 | |
| 1561 | case PPD_MACRO_DEFINITION: { |
| 1562 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1563 | return PE; |
| 1564 | |
| 1565 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
| 1566 | Error("out-of-bounds macro definition record"); |
| 1567 | return 0; |
| 1568 | } |
| 1569 | |
| 1570 | // Decode the identifier info and then check again; if the macro is |
| 1571 | // still defined and associated with the identifier, |
| 1572 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1573 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1574 | MacroDefinition *MD |
| 1575 | = new (PPRec) MacroDefinition(II, |
| 1576 | ReadSourceLocation(F, Record[5]), |
| 1577 | SourceRange( |
| 1578 | ReadSourceLocation(F, Record[2]), |
| 1579 | ReadSourceLocation(F, Record[3]))); |
| 1580 | |
| 1581 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1582 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
| 1583 | |
| 1584 | if (DeserializationListener) |
| 1585 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1586 | } |
| 1587 | |
| 1588 | return MacroDefinitionsLoaded[Record[1] - 1]; |
| 1589 | } |
| 1590 | |
| 1591 | case PPD_INCLUSION_DIRECTIVE: { |
| 1592 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1593 | return PE; |
| 1594 | |
| 1595 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1596 | const FileEntry *File |
| 1597 | = PP->getFileManager().getFile(llvm::StringRef(FullFileNameStart, |
| 1598 | BlobLen - Record[3])); |
| 1599 | |
| 1600 | // FIXME: Stable encoding |
| 1601 | InclusionDirective::InclusionKind Kind |
| 1602 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1603 | InclusionDirective *ID |
| 1604 | = new (PPRec) InclusionDirective(PPRec, Kind, |
| 1605 | llvm::StringRef(BlobStart, Record[3]), |
| 1606 | Record[4], |
| 1607 | File, |
| 1608 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1609 | ReadSourceLocation(F, Record[2]))); |
| 1610 | PPRec.SetPreallocatedEntity(Record[0], ID); |
| 1611 | return ID; |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | Error("invalid offset in preprocessor detail block"); |
| 1616 | return 0; |
| 1617 | } |
| 1618 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1619 | namespace { |
| 1620 | /// \brief Trait class used to search the on-disk hash table containing all of |
| 1621 | /// the header search information. |
| 1622 | /// |
| 1623 | /// The on-disk hash table contains a mapping from each header path to |
| 1624 | /// information about that header (how many times it has been included, its |
| 1625 | /// controlling macro, etc.). Note that we actually hash based on the |
| 1626 | /// filename, and support "deep" comparisons of file names based on current |
| 1627 | /// inode numbers, so that the search can cope with non-normalized path names |
| 1628 | /// and symlinks. |
| 1629 | class HeaderFileInfoTrait { |
| 1630 | const char *SearchPath; |
| 1631 | struct stat SearchPathStatBuf; |
| 1632 | llvm::Optional<int> SearchPathStatResult; |
| 1633 | |
| 1634 | int StatSimpleCache(const char *Path, struct stat *StatBuf) { |
| 1635 | if (Path == SearchPath) { |
| 1636 | if (!SearchPathStatResult) |
| 1637 | SearchPathStatResult = stat(Path, &SearchPathStatBuf); |
| 1638 | |
| 1639 | *StatBuf = SearchPathStatBuf; |
| 1640 | return *SearchPathStatResult; |
| 1641 | } |
| 1642 | |
| 1643 | return stat(Path, StatBuf); |
| 1644 | } |
| 1645 | |
| 1646 | public: |
| 1647 | typedef const char *external_key_type; |
| 1648 | typedef const char *internal_key_type; |
| 1649 | |
| 1650 | typedef HeaderFileInfo data_type; |
| 1651 | |
| 1652 | HeaderFileInfoTrait(const char *SearchPath = 0) : SearchPath(SearchPath) { } |
| 1653 | |
| 1654 | static unsigned ComputeHash(const char *path) { |
| 1655 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1656 | } |
| 1657 | |
| 1658 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1659 | |
| 1660 | bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1661 | if (strcmp(a, b) == 0) |
| 1662 | return true; |
| 1663 | |
| 1664 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1665 | return false; |
| 1666 | |
| 1667 | // The file names match, but the path names don't. stat() the files to |
| 1668 | // see if they are the same. |
| 1669 | struct stat StatBufA, StatBufB; |
| 1670 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1671 | return false; |
| 1672 | |
| 1673 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1674 | } |
| 1675 | |
| 1676 | static std::pair<unsigned, unsigned> |
| 1677 | ReadKeyDataLength(const unsigned char*& d) { |
| 1678 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1679 | unsigned DataLen = (unsigned) *d++; |
| 1680 | return std::make_pair(KeyLen + 1, DataLen); |
| 1681 | } |
| 1682 | |
| 1683 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1684 | return (const char *)d; |
| 1685 | } |
| 1686 | |
| 1687 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1688 | unsigned DataLen) { |
| 1689 | const unsigned char *End = d + DataLen; |
| 1690 | using namespace clang::io; |
| 1691 | HeaderFileInfo HFI; |
| 1692 | unsigned Flags = *d++; |
| 1693 | HFI.isImport = (Flags >> 3) & 0x01; |
| 1694 | HFI.DirInfo = (Flags >> 1) & 0x03; |
| 1695 | HFI.Resolved = Flags & 0x01; |
| 1696 | HFI.NumIncludes = ReadUnalignedLE16(d); |
| 1697 | HFI.ControllingMacroID = ReadUnalignedLE32(d); |
| 1698 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1699 | (void)End; |
| 1700 | |
| 1701 | // This HeaderFileInfo was externally loaded. |
| 1702 | HFI.External = true; |
| 1703 | return HFI; |
| 1704 | } |
| 1705 | }; |
| 1706 | } |
| 1707 | |
| 1708 | /// \brief The on-disk hash table used for the global method pool. |
| 1709 | typedef OnDiskChainedHashTable<HeaderFileInfoTrait> |
| 1710 | HeaderFileInfoLookupTable; |
| 1711 | |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1712 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F, |
| 1713 | uint64_t Offset) { |
| 1714 | // Note that this identifier has a macro definition. |
| 1715 | II->setHasMacroDefinition(true); |
| 1716 | |
| 1717 | // Adjust the offset based on our position in the chain. |
| 1718 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1719 | if (Chain[I] == &F) |
| 1720 | break; |
| 1721 | |
| 1722 | Offset += Chain[I]->SizeInBits; |
| 1723 | } |
| 1724 | |
| 1725 | UnreadMacroRecordOffsets[II] = Offset; |
| 1726 | } |
| 1727 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1728 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1729 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1730 | PerFileData &F = *Chain[N - I - 1]; |
| 1731 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1732 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1733 | // If there was no preprocessor block, skip this file. |
| 1734 | if (!MacroCursor.getBitStreamReader()) |
| 1735 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1736 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1737 | llvm::BitstreamCursor Cursor = MacroCursor; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1738 | Cursor.JumpToBit(F.MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1739 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1740 | RecordData Record; |
| 1741 | while (true) { |
| 1742 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1743 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1744 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1745 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1746 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1747 | // No known subblocks, always skip them. |
| 1748 | Cursor.ReadSubBlockID(); |
| 1749 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1750 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1751 | return; |
| 1752 | } |
| 1753 | continue; |
| 1754 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1755 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1756 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1757 | Cursor.ReadAbbrevRecord(); |
| 1758 | continue; |
| 1759 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1760 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1761 | // Read a record. |
| 1762 | const char *BlobStart; |
| 1763 | unsigned BlobLen; |
| 1764 | Record.clear(); |
| 1765 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1766 | default: // Default behavior: ignore. |
| 1767 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1768 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1769 | case PP_MACRO_OBJECT_LIKE: |
| 1770 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1771 | DecodeIdentifierInfo(Record[0]); |
| 1772 | break; |
| 1773 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1774 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1775 | // Ignore tokens. |
| 1776 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1777 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1778 | } |
| 1779 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1780 | |
| 1781 | // Drain the unread macro-record offsets map. |
| 1782 | while (!UnreadMacroRecordOffsets.empty()) |
| 1783 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1784 | } |
| 1785 | |
| 1786 | void ASTReader::LoadMacroDefinition( |
| 1787 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1788 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
| 1789 | PerFileData *F = 0; |
| 1790 | uint64_t Offset = Pos->second; |
| 1791 | UnreadMacroRecordOffsets.erase(Pos); |
| 1792 | |
| 1793 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1794 | if (Offset < Chain[I]->SizeInBits) { |
| 1795 | F = Chain[I]; |
| 1796 | break; |
| 1797 | } |
| 1798 | |
| 1799 | Offset -= Chain[I]->SizeInBits; |
| 1800 | } |
| 1801 | if (!F) { |
| 1802 | Error("Malformed macro record offset"); |
| 1803 | return; |
| 1804 | } |
| 1805 | |
| 1806 | ReadMacroRecord(*F, Offset); |
| 1807 | } |
| 1808 | |
| 1809 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1810 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1811 | = UnreadMacroRecordOffsets.find(II); |
| 1812 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1813 | } |
| 1814 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1815 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1816 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1817 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1818 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1819 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1820 | unsigned Index = ID - 1; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1821 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1822 | PerFileData &F = *Chain[N - I - 1]; |
| 1823 | if (Index < F.LocalNumMacroDefinitions) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1824 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 1825 | F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]); |
| 1826 | LoadPreprocessedEntity(F); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1827 | break; |
| 1828 | } |
| 1829 | Index -= F.LocalNumMacroDefinitions; |
| 1830 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1831 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1834 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1837 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1838 | /// not an absolute path, add the system root to the beginning of the file |
| 1839 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1840 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1841 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1842 | if (!RelocatablePCH) |
| 1843 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1844 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1845 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1846 | return; |
| 1847 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1848 | if (isysroot == 0) { |
| 1849 | // If no system root was given, default to '/' |
| 1850 | Filename.insert(Filename.begin(), '/'); |
| 1851 | return; |
| 1852 | } |
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 | unsigned Length = strlen(isysroot); |
| 1855 | if (isysroot[Length - 1] != '/') |
| 1856 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1857 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1858 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1859 | } |
| 1860 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1861 | ASTReader::ASTReadResult |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1862 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1863 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1864 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1865 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1866 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1867 | return Failure; |
| 1868 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1869 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1870 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1871 | RecordData Record; |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1872 | bool First = true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1873 | while (!Stream.AtEndOfStream()) { |
| 1874 | unsigned Code = Stream.ReadCode(); |
| 1875 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1876 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1877 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1878 | return Failure; |
| 1879 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1880 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1881 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1885 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1886 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1887 | // We lazily load the decls block, but we want to set up the |
| 1888 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1889 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1890 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1891 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1892 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1893 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1894 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1895 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1896 | return Failure; |
| 1897 | } |
| 1898 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1899 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1900 | case DECL_UPDATES_BLOCK_ID: |
| 1901 | if (Stream.SkipBlock()) { |
| 1902 | Error("malformed block record in AST file"); |
| 1903 | return Failure; |
| 1904 | } |
| 1905 | break; |
| 1906 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1907 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1908 | F.MacroCursor = Stream; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1909 | if (PP) |
| 1910 | PP->setExternalSource(this); |
| 1911 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1912 | if (Stream.SkipBlock() || |
| 1913 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1914 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1915 | return Failure; |
| 1916 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1917 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1918 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1919 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1920 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1921 | F.PreprocessorDetailCursor = Stream; |
| 1922 | if (Stream.SkipBlock() || |
| 1923 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1924 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1925 | Error("malformed preprocessor detail record in AST file"); |
| 1926 | return Failure; |
| 1927 | } |
| 1928 | F.PreprocessorDetailStartOffset |
| 1929 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 1930 | break; |
| 1931 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1932 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1933 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1934 | case Success: |
| 1935 | break; |
| 1936 | |
| 1937 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1938 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1939 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1940 | |
| 1941 | case IgnorePCH: |
| 1942 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1943 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1944 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1945 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1946 | First = false; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1947 | continue; |
| 1948 | } |
| 1949 | |
| 1950 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1951 | Stream.ReadAbbrevRecord(); |
| 1952 | continue; |
| 1953 | } |
| 1954 | |
| 1955 | // Read and process a record. |
| 1956 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1957 | const char *BlobStart = 0; |
| 1958 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1959 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1960 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1961 | default: // Default behavior: ignore. |
| 1962 | break; |
| 1963 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1964 | case METADATA: { |
| 1965 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1966 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1967 | : diag::warn_pch_version_too_new); |
| 1968 | return IgnorePCH; |
| 1969 | } |
| 1970 | |
| 1971 | RelocatablePCH = Record[4]; |
| 1972 | if (Listener) { |
| 1973 | std::string TargetTriple(BlobStart, BlobLen); |
| 1974 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1975 | return IgnorePCH; |
| 1976 | } |
| 1977 | break; |
| 1978 | } |
| 1979 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1980 | case CHAINED_METADATA: { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1981 | if (!First) { |
| 1982 | Error("CHAINED_METADATA is not first record in block"); |
| 1983 | return Failure; |
| 1984 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1985 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1986 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1987 | : diag::warn_pch_version_too_new); |
| 1988 | return IgnorePCH; |
| 1989 | } |
| 1990 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 1991 | // Load the chained file, which is always a PCH file. |
| 1992 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1993 | case Failure: return Failure; |
| 1994 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1995 | case IgnorePCH: return IgnorePCH; |
| 1996 | case Success: break; |
| 1997 | } |
| 1998 | break; |
| 1999 | } |
| 2000 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2001 | case TYPE_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2002 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2003 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2004 | return Failure; |
| 2005 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2006 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 2007 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2008 | break; |
| 2009 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2010 | case DECL_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2011 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2012 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2013 | return Failure; |
| 2014 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2015 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 2016 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2017 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2018 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2019 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2020 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2021 | /* No visible information */ 0, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2022 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 2023 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2024 | }; |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2025 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 2026 | .push_back(Info); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2027 | break; |
| 2028 | } |
| 2029 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2030 | case UPDATE_VISIBLE: { |
| 2031 | serialization::DeclID ID = Record[0]; |
| 2032 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 2033 | (const unsigned char *)BlobStart + Record[1], |
| 2034 | (const unsigned char *)BlobStart, |
| 2035 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2036 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2037 | DeclContextInfo Info = { |
| 2038 | Table, /* No lexical inforamtion */ 0, 0 |
| 2039 | }; |
| 2040 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 2041 | } else |
| 2042 | PendingVisibleUpdates[ID].push_back(Table); |
| 2043 | break; |
| 2044 | } |
| 2045 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2046 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2047 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 2048 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2049 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2050 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 2051 | Latest > FirstLatestDeclIDs[First]) && |
| 2052 | "The new latest is supposed to come after the previous latest"); |
| 2053 | FirstLatestDeclIDs[First] = Latest; |
| 2054 | } |
| 2055 | break; |
| 2056 | } |
| 2057 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2058 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2059 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2060 | return IgnorePCH; |
| 2061 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2062 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2063 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2064 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2065 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2066 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2067 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2068 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2069 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2070 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2071 | if (PP) |
| 2072 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2073 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2074 | break; |
| 2075 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2076 | case IDENTIFIER_OFFSET: |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2077 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2078 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2079 | return Failure; |
| 2080 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2081 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2082 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2083 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2084 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2085 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2086 | // Optimization for the first block. |
| 2087 | if (ExternalDefinitions.empty()) |
| 2088 | ExternalDefinitions.swap(Record); |
| 2089 | else |
| 2090 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 2091 | Record.begin(), Record.end()); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2092 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2093 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2094 | case SPECIAL_TYPES: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2095 | // Optimization for the first block |
| 2096 | if (SpecialTypes.empty()) |
| 2097 | SpecialTypes.swap(Record); |
| 2098 | else |
| 2099 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2100 | break; |
| 2101 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2102 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2103 | TotalNumStatements += Record[0]; |
| 2104 | TotalNumMacros += Record[1]; |
| 2105 | TotalLexicalDeclContexts += Record[2]; |
| 2106 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2107 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2108 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2109 | case TENTATIVE_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2110 | // Optimization for the first block. |
| 2111 | if (TentativeDefinitions.empty()) |
| 2112 | TentativeDefinitions.swap(Record); |
| 2113 | else |
| 2114 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 2115 | Record.begin(), Record.end()); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2116 | break; |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2117 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2118 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2119 | // Optimization for the first block. |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2120 | if (UnusedFileScopedDecls.empty()) |
| 2121 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2122 | else |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2123 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 2124 | Record.begin(), Record.end()); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2125 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2126 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2127 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2128 | // Later blocks overwrite earlier ones. |
| 2129 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2130 | break; |
| 2131 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2132 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2133 | // Optimization for the first block. |
| 2134 | if (LocallyScopedExternalDecls.empty()) |
| 2135 | LocallyScopedExternalDecls.swap(Record); |
| 2136 | else |
| 2137 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 2138 | Record.begin(), Record.end()); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2139 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2140 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2141 | case SELECTOR_OFFSETS: |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2142 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2143 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2144 | break; |
| 2145 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2146 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2147 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2148 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2149 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2150 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2151 | F.SelectorLookupTableData + Record[0], |
| 2152 | F.SelectorLookupTableData, |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2153 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2154 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2155 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2156 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2157 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2158 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2159 | break; |
| 2160 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2161 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2162 | if (!Record.empty() && Listener) |
| 2163 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2164 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2165 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2166 | case SOURCE_LOCATION_OFFSETS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2167 | F.SLocOffsets = (const uint32_t *)BlobStart; |
| 2168 | F.LocalNumSLocEntries = Record[0]; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2169 | F.LocalSLocSize = Record[1]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2170 | break; |
| 2171 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2172 | case SOURCE_LOCATION_PRELOADS: |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2173 | if (PreloadSLocEntries.empty()) |
| 2174 | PreloadSLocEntries.swap(Record); |
| 2175 | else |
| 2176 | PreloadSLocEntries.insert(PreloadSLocEntries.end(), |
| 2177 | Record.begin(), Record.end()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2178 | break; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2179 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2180 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2181 | if (!DisableStatCache) { |
| 2182 | ASTStatCache *MyStatCache = |
| 2183 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2184 | (const unsigned char *)BlobStart, |
| 2185 | NumStatHits, NumStatMisses); |
| 2186 | FileMgr.addStatCache(MyStatCache); |
| 2187 | F.StatCache = MyStatCache; |
| 2188 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2189 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2190 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2191 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2192 | case EXT_VECTOR_DECLS: |
Sebastian Redl | a9f2368 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 2193 | // Optimization for the first block. |
| 2194 | if (ExtVectorDecls.empty()) |
| 2195 | ExtVectorDecls.swap(Record); |
| 2196 | else |
| 2197 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 2198 | Record.begin(), Record.end()); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2199 | break; |
| 2200 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2201 | case VTABLE_USES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2202 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2203 | VTableUses.swap(Record); |
| 2204 | break; |
| 2205 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2206 | case DYNAMIC_CLASSES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2207 | // Optimization for the first block. |
| 2208 | if (DynamicClasses.empty()) |
| 2209 | DynamicClasses.swap(Record); |
| 2210 | else |
| 2211 | DynamicClasses.insert(DynamicClasses.end(), |
| 2212 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2213 | break; |
| 2214 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2215 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2216 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2217 | break; |
| 2218 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2219 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2220 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2221 | SemaDeclRefs.swap(Record); |
| 2222 | break; |
| 2223 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2224 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2225 | // 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] | 2226 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2227 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2228 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2229 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2230 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2231 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2232 | case ORIGINAL_PCH_DIR: |
| 2233 | // The primary AST will be the last to get here, so it will be the one |
| 2234 | // that's used. |
| 2235 | OriginalDir.assign(BlobStart, BlobLen); |
| 2236 | break; |
| 2237 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2238 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2239 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2240 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 2241 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2242 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2243 | return IgnorePCH; |
| 2244 | } |
| 2245 | break; |
| 2246 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2247 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2248 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2249 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2250 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2251 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2252 | break; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2253 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2254 | case DECL_UPDATE_OFFSETS: { |
| 2255 | if (Record.size() % 2 != 0) { |
| 2256 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2257 | return Failure; |
| 2258 | } |
| 2259 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
| 2260 | DeclUpdateOffsets[static_cast<DeclID>(Record[I])] |
| 2261 | .push_back(std::make_pair(&F, Record[I+1])); |
| 2262 | break; |
| 2263 | } |
| 2264 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2265 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2266 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2267 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2268 | return Failure; |
| 2269 | } |
| 2270 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2271 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2272 | std::make_pair(&F, Record[I+1]); |
| 2273 | break; |
| 2274 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2275 | |
| 2276 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2277 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2278 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2279 | return Failure; |
| 2280 | } |
| 2281 | |
| 2282 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2283 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
| 2284 | break; |
| 2285 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2286 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2287 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2288 | if (Record.size() % 2 != 0) { |
| 2289 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2290 | return Failure; |
| 2291 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2292 | if (PragmaDiagMappings.empty()) |
| 2293 | PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2294 | else |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2295 | PragmaDiagMappings.insert(PragmaDiagMappings.end(), |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2296 | Record.begin(), Record.end()); |
| 2297 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2298 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2299 | case CUDA_SPECIAL_DECL_REFS: |
| 2300 | // Later tables overwrite earlier ones. |
| 2301 | CUDASpecialDeclRefs.swap(Record); |
| 2302 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2303 | |
| 2304 | case HEADER_SEARCH_TABLE: |
| 2305 | F.HeaderFileInfoTableData = BlobStart; |
| 2306 | F.LocalNumHeaderFileInfos = Record[1]; |
| 2307 | if (Record[0]) { |
| 2308 | F.HeaderFileInfoTable |
| 2309 | = HeaderFileInfoLookupTable::Create( |
| 2310 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 2311 | (const unsigned char *)F.HeaderFileInfoTableData); |
| 2312 | if (PP) |
| 2313 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2314 | } |
| 2315 | break; |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2316 | |
| 2317 | case FP_PRAGMA_OPTIONS: |
| 2318 | // Later tables overwrite earlier ones. |
| 2319 | FPPragmaOptions.swap(Record); |
| 2320 | break; |
| 2321 | |
| 2322 | case OPENCL_EXTENSIONS: |
| 2323 | // Later tables overwrite earlier ones. |
| 2324 | OpenCLExtensions.swap(Record); |
| 2325 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2326 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2327 | First = false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2328 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2329 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2330 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2333 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2334 | ASTFileType Type) { |
| 2335 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2336 | case Failure: return Failure; |
| 2337 | case IgnorePCH: return IgnorePCH; |
| 2338 | case Success: break; |
| 2339 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2340 | |
| 2341 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2342 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2343 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2344 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2345 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2346 | TotalNumSelectors = 0; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2347 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2348 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2349 | NextSLocOffset += Chain[I]->LocalSLocSize; |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2350 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2351 | TotalNumTypes += Chain[I]->LocalNumTypes; |
| 2352 | TotalNumDecls += Chain[I]->LocalNumDecls; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2353 | TotalNumPreallocatedPreprocessingEntities += |
| 2354 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2355 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2356 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2357 | } |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2358 | SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset); |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2359 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2360 | TypesLoaded.resize(TotalNumTypes); |
| 2361 | DeclsLoaded.resize(TotalNumDecls); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2362 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2363 | if (PP) { |
| 2364 | if (TotalNumIdentifiers > 0) |
| 2365 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2366 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2367 | if (!PP->getPreprocessingRecord()) |
| 2368 | PP->createPreprocessingRecord(); |
| 2369 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2370 | TotalNumPreallocatedPreprocessingEntities); |
| 2371 | } |
| 2372 | } |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2373 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2374 | // Preload SLocEntries. |
| 2375 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2376 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2377 | if (Result != Success) |
| 2378 | return Result; |
| 2379 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2380 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2381 | // Check the predefines buffers. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2382 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2383 | return IgnorePCH; |
| 2384 | |
| 2385 | if (PP) { |
| 2386 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2387 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2388 | // loaded into the IdentifierTable before we intercepted the |
| 2389 | // creation of identifiers. Iterate through the list of known |
| 2390 | // identifiers and determine whether we have to establish |
| 2391 | // preprocessor definitions or top-level identifier declaration |
| 2392 | // chains for those identifiers. |
| 2393 | // |
| 2394 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2395 | // since de-serializing declarations or macro definitions can add |
| 2396 | // new entries into the identifier table, invalidating the |
| 2397 | // iterators. |
| 2398 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2399 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2400 | IdEnd = PP->getIdentifierTable().end(); |
| 2401 | Id != IdEnd; ++Id) |
| 2402 | Identifiers.push_back(Id->second); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2403 | // We need to search the tables in all files. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2404 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2405 | ASTIdentifierLookupTable *IdTable |
| 2406 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2407 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2408 | // ones. |
| 2409 | if (!IdTable) |
| 2410 | continue; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2411 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2412 | IdentifierInfo *II = Identifiers[I]; |
| 2413 | // 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] | 2414 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2415 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2416 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2417 | if (Pos == IdTable->end()) |
| 2418 | continue; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2419 | |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2420 | // Dereferencing the iterator has the effect of populating the |
| 2421 | // IdentifierInfo node with the various declarations it needs. |
| 2422 | (void)*Pos; |
| 2423 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | if (Context) |
| 2428 | InitializeContext(*Context); |
| 2429 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2430 | if (DeserializationListener) |
| 2431 | DeserializationListener->ReaderInitialized(this); |
| 2432 | |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2433 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2434 | // the source manager to the file source file from which the preamble was |
| 2435 | // built. This is the only valid way to use a precompiled preamble. |
| 2436 | if (Type == Preamble) { |
| 2437 | SourceLocation Loc |
| 2438 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2439 | if (Loc.isValid()) { |
| 2440 | std::pair<FileID, unsigned> Decomposed = SourceMgr.getDecomposedLoc(Loc); |
| 2441 | SourceMgr.SetPreambleFileID(Decomposed.first); |
| 2442 | } |
| 2443 | } |
| 2444 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2445 | return Success; |
| 2446 | } |
| 2447 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2448 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2449 | ASTFileType Type) { |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2450 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2451 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2452 | PerFileData &F = *Chain.back(); |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2453 | if (Prev) |
| 2454 | Prev->NextInSource = &F; |
| 2455 | else |
| 2456 | FirstInSource = &F; |
| 2457 | F.Loaders.push_back(Prev); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2458 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2459 | // Set the AST file name. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2460 | F.FileName = FileName; |
| 2461 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2462 | if (FileName != "-") { |
| 2463 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2464 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2465 | } |
| 2466 | |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 2467 | if (!ASTBuffers.empty()) { |
Sebastian Redl | 5655837 | 2011-04-14 14:07:41 +0000 | [diff] [blame] | 2468 | F.Buffer.reset(ASTBuffers.back()); |
| 2469 | ASTBuffers.pop_back(); |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 2470 | assert(F.Buffer && "Passed null buffer"); |
| 2471 | } else { |
| 2472 | // Open the AST file. |
| 2473 | // |
| 2474 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2475 | std::string ErrStr; |
| 2476 | llvm::error_code ec; |
| 2477 | if (FileName == "-") { |
| 2478 | ec = llvm::MemoryBuffer::getSTDIN(F.Buffer); |
| 2479 | if (ec) |
| 2480 | ErrStr = ec.message(); |
| 2481 | } else |
| 2482 | F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr)); |
| 2483 | if (!F.Buffer) { |
| 2484 | Error(ErrStr.c_str()); |
| 2485 | return IgnorePCH; |
| 2486 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | // Initialize the stream |
| 2490 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2491 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2492 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2493 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2494 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2495 | |
| 2496 | // Sniff for the signature. |
| 2497 | if (Stream.Read(8) != 'C' || |
| 2498 | Stream.Read(8) != 'P' || |
| 2499 | Stream.Read(8) != 'C' || |
| 2500 | Stream.Read(8) != 'H') { |
| 2501 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2502 | return Failure; |
| 2503 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2504 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2505 | while (!Stream.AtEndOfStream()) { |
| 2506 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2507 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2508 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2509 | Error("invalid record at top-level of 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 | |
| 2513 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2514 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2515 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2516 | switch (BlockID) { |
| 2517 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2518 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2519 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2520 | return Failure; |
| 2521 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2522 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2523 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2524 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2525 | case Success: |
| 2526 | break; |
| 2527 | |
| 2528 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2529 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2530 | |
| 2531 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2532 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2533 | // AST block, skipping subblocks, to see if there are other |
| 2534 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2535 | |
| 2536 | // Clear out any preallocated source location entries, so that |
| 2537 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2538 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2539 | |
| 2540 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2541 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2542 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2543 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2544 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2545 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2546 | break; |
| 2547 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2548 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2549 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2550 | return Failure; |
| 2551 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2552 | break; |
| 2553 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2556 | return Success; |
| 2557 | } |
| 2558 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2559 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2560 | PP = &pp; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2561 | |
| 2562 | unsigned TotalNum = 0; |
| 2563 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2564 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2565 | if (TotalNum) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2566 | if (!PP->getPreprocessingRecord()) |
| 2567 | PP->createPreprocessingRecord(); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2568 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2569 | } |
| 2570 | } |
| 2571 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2572 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2573 | Context = &Ctx; |
| 2574 | assert(Context && "Passed null context!"); |
| 2575 | |
| 2576 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2577 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2578 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2579 | PP->setExternalSource(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2580 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2581 | |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2582 | // If we have an update block for the TU waiting, we have to add it before |
| 2583 | // deserializing the decl. |
| 2584 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2585 | if (DCU != DeclContextOffsets.end()) { |
| 2586 | // Insertion could invalidate map, so grab vector. |
| 2587 | DeclContextInfos T; |
| 2588 | T.swap(DCU->second); |
| 2589 | DeclContextOffsets.erase(DCU); |
| 2590 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2591 | } |
| 2592 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2593 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2594 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2595 | |
| 2596 | // Load the special types. |
| 2597 | Context->setBuiltinVaListType( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2598 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2599 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2600 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2601 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2602 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2603 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2604 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2605 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2606 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2607 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2608 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2609 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2610 | if (unsigned FastEnum |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2611 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2612 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2613 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2614 | QualType FileType = GetType(File); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2615 | if (FileType.isNull()) { |
| 2616 | Error("FILE type is NULL"); |
| 2617 | return; |
| 2618 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2619 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2620 | Context->setFILEDecl(Typedef->getDecl()); |
| 2621 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2622 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2623 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2624 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2625 | return; |
| 2626 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2627 | Context->setFILEDecl(Tag->getDecl()); |
| 2628 | } |
| 2629 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2630 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2631 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2632 | if (Jmp_bufType.isNull()) { |
| 2633 | Error("jmp_bug type is NULL"); |
| 2634 | return; |
| 2635 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2636 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2637 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2638 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2639 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2640 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2641 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2642 | return; |
| 2643 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2644 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2645 | } |
| 2646 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2647 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2648 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2649 | if (Sigjmp_bufType.isNull()) { |
| 2650 | Error("sigjmp_buf type is NULL"); |
| 2651 | return; |
| 2652 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2653 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2654 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2655 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2656 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2657 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2658 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2659 | } |
| 2660 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2661 | if (unsigned ObjCIdRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2662 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2663 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2664 | if (unsigned ObjCClassRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2665 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2666 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2667 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2668 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2669 | if (unsigned String |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2670 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2671 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2672 | if (unsigned ObjCSelRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2673 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2674 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2675 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2676 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2677 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2678 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2679 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2680 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2681 | if (unsigned AutoDeduct = SpecialTypes[SPECIAL_TYPE_AUTO_DEDUCT]) |
| 2682 | Context->AutoDeductTy = GetType(AutoDeduct); |
| 2683 | if (unsigned AutoRRefDeduct = SpecialTypes[SPECIAL_TYPE_AUTO_RREF_DEDUCT]) |
| 2684 | Context->AutoRRefDeductTy = GetType(AutoRRefDeduct); |
| 2685 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2686 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2687 | |
| 2688 | // If there were any CUDA special declarations, deserialize them. |
| 2689 | if (!CUDASpecialDeclRefs.empty()) { |
| 2690 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 2691 | Context->setcudaConfigureCallDecl( |
| 2692 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2693 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2694 | } |
| 2695 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2696 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2697 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2698 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2699 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2700 | FileManager &FileMgr, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2701 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2702 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2703 | std::string ErrStr; |
| 2704 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2705 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2706 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2707 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2708 | return std::string(); |
| 2709 | } |
| 2710 | |
| 2711 | // Initialize the stream |
| 2712 | llvm::BitstreamReader StreamFile; |
| 2713 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2714 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2715 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2716 | Stream.init(StreamFile); |
| 2717 | |
| 2718 | // Sniff for the signature. |
| 2719 | if (Stream.Read(8) != 'C' || |
| 2720 | Stream.Read(8) != 'P' || |
| 2721 | Stream.Read(8) != 'C' || |
| 2722 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2723 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2724 | return std::string(); |
| 2725 | } |
| 2726 | |
| 2727 | RecordData Record; |
| 2728 | while (!Stream.AtEndOfStream()) { |
| 2729 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2730 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2731 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2732 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2733 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2734 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2735 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2736 | case AST_BLOCK_ID: |
| 2737 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2738 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2739 | return std::string(); |
| 2740 | } |
| 2741 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2742 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2743 | default: |
| 2744 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2745 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2746 | return std::string(); |
| 2747 | } |
| 2748 | break; |
| 2749 | } |
| 2750 | continue; |
| 2751 | } |
| 2752 | |
| 2753 | if (Code == llvm::bitc::END_BLOCK) { |
| 2754 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2755 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2756 | return std::string(); |
| 2757 | } |
| 2758 | continue; |
| 2759 | } |
| 2760 | |
| 2761 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2762 | Stream.ReadAbbrevRecord(); |
| 2763 | continue; |
| 2764 | } |
| 2765 | |
| 2766 | Record.clear(); |
| 2767 | const char *BlobStart = 0; |
| 2768 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2769 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2770 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2771 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2772 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2773 | |
| 2774 | return std::string(); |
| 2775 | } |
| 2776 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2777 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2778 | /// structure. |
| 2779 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2780 | /// This routine parses the language options from the AST file and then gives |
| 2781 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2782 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2783 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2784 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2785 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2786 | if (Listener) { |
| 2787 | LangOptions LangOpts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2788 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2789 | #define PARSE_LANGOPT(Option) \ |
| 2790 | LangOpts.Option = Record[Idx]; \ |
| 2791 | ++Idx |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2792 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2793 | unsigned Idx = 0; |
| 2794 | PARSE_LANGOPT(Trigraphs); |
| 2795 | PARSE_LANGOPT(BCPLComment); |
| 2796 | PARSE_LANGOPT(DollarIdents); |
| 2797 | PARSE_LANGOPT(AsmPreprocessor); |
| 2798 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2799 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2800 | PARSE_LANGOPT(ImplicitInt); |
| 2801 | PARSE_LANGOPT(Digraphs); |
| 2802 | PARSE_LANGOPT(HexFloats); |
| 2803 | PARSE_LANGOPT(C99); |
Peter Collingbourne | 7e7fbd0 | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 2804 | PARSE_LANGOPT(C1X); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2805 | PARSE_LANGOPT(Microsoft); |
| 2806 | PARSE_LANGOPT(CPlusPlus); |
| 2807 | PARSE_LANGOPT(CPlusPlus0x); |
| 2808 | PARSE_LANGOPT(CXXOperatorNames); |
| 2809 | PARSE_LANGOPT(ObjC1); |
| 2810 | PARSE_LANGOPT(ObjC2); |
| 2811 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 2812 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 2813 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 2814 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 2815 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2816 | PARSE_LANGOPT(PascalStrings); |
| 2817 | PARSE_LANGOPT(WritableStrings); |
| 2818 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2819 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2820 | PARSE_LANGOPT(Exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 2821 | PARSE_LANGOPT(ObjCExceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 2822 | PARSE_LANGOPT(CXXExceptions); |
| 2823 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 2824 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2825 | PARSE_LANGOPT(NeXTRuntime); |
| 2826 | PARSE_LANGOPT(Freestanding); |
| 2827 | PARSE_LANGOPT(NoBuiltin); |
| 2828 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 2829 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2830 | PARSE_LANGOPT(Blocks); |
| 2831 | PARSE_LANGOPT(EmitAllDecls); |
| 2832 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2833 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 2834 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2835 | PARSE_LANGOPT(HeinousExtensions); |
| 2836 | PARSE_LANGOPT(Optimize); |
| 2837 | PARSE_LANGOPT(OptimizeSize); |
| 2838 | PARSE_LANGOPT(Static); |
| 2839 | PARSE_LANGOPT(PICLevel); |
| 2840 | PARSE_LANGOPT(GNUInline); |
| 2841 | PARSE_LANGOPT(NoInline); |
Chandler Carruth | 0d2d1bc | 2011-04-23 20:05:38 +0000 | [diff] [blame^] | 2842 | PARSE_LANGOPT(Deprecated); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2843 | PARSE_LANGOPT(AccessControl); |
| 2844 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2845 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | b1bdced | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 2846 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2847 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2848 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 2849 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2850 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2851 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2852 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 2853 | PARSE_LANGOPT(CUDA); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2854 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2855 | PARSE_LANGOPT(DefaultFPContract); |
Roman Divacky | 1c51b1c | 2011-03-01 17:36:40 +0000 | [diff] [blame] | 2856 | PARSE_LANGOPT(ElideConstructors); |
| 2857 | PARSE_LANGOPT(SpellChecking); |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 2858 | PARSE_LANGOPT(MRTD); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2859 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2860 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2861 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2862 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2863 | |
| 2864 | return false; |
| 2865 | } |
| 2866 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2867 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2868 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2869 | PerFileData &F = *Chain[I]; |
| 2870 | if (!F.PreprocessorDetailCursor.getBitStreamReader()) |
| 2871 | continue; |
| 2872 | |
| 2873 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 2874 | F.PreprocessorDetailCursor.JumpToBit(F.PreprocessorDetailStartOffset); |
| 2875 | while (LoadPreprocessedEntity(F)) { } |
| 2876 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2877 | } |
| 2878 | |
Douglas Gregor | 0a48029 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 2879 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2880 | PerFileData *F = 0; |
| 2881 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2882 | if (Offset < Chain[I]->SizeInBits) { |
| 2883 | F = Chain[I]; |
| 2884 | break; |
| 2885 | } |
| 2886 | |
| 2887 | Offset -= Chain[I]->SizeInBits; |
| 2888 | } |
| 2889 | |
| 2890 | if (!F) { |
| 2891 | Error("Malformed preprocessed entity offset"); |
| 2892 | return 0; |
| 2893 | } |
| 2894 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2895 | // Keep track of where we are in the stream, then jump back there |
| 2896 | // after reading this entity. |
| 2897 | SavedStreamPosition SavedPosition(F->PreprocessorDetailCursor); |
| 2898 | F->PreprocessorDetailCursor.JumpToBit(Offset); |
| 2899 | return LoadPreprocessedEntity(*F); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2900 | } |
| 2901 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2902 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
| 2903 | HeaderFileInfoTrait Trait(FE->getName()); |
| 2904 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2905 | PerFileData &F = *Chain[I]; |
| 2906 | HeaderFileInfoLookupTable *Table |
| 2907 | = static_cast<HeaderFileInfoLookupTable *>(F.HeaderFileInfoTable); |
| 2908 | if (!Table) |
| 2909 | continue; |
| 2910 | |
| 2911 | // Look in the on-disk hash table for an entry for this file name. |
| 2912 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE->getName(), |
| 2913 | &Trait); |
| 2914 | if (Pos == Table->end()) |
| 2915 | continue; |
| 2916 | |
| 2917 | HeaderFileInfo HFI = *Pos; |
| 2918 | if (Listener) |
| 2919 | Listener->ReadHeaderFileInfo(HFI, FE->getUID()); |
| 2920 | |
| 2921 | return HFI; |
| 2922 | } |
| 2923 | |
| 2924 | return HeaderFileInfo(); |
| 2925 | } |
| 2926 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2927 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2928 | unsigned Idx = 0; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2929 | while (Idx < PragmaDiagMappings.size()) { |
| 2930 | SourceLocation |
| 2931 | Loc = SourceLocation::getFromRawEncoding(PragmaDiagMappings[Idx++]); |
| 2932 | while (1) { |
| 2933 | assert(Idx < PragmaDiagMappings.size() && |
| 2934 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 2935 | if (Idx >= PragmaDiagMappings.size()) |
| 2936 | break; // Something is messed up but at least avoid infinite loop in |
| 2937 | // release build. |
| 2938 | unsigned DiagID = PragmaDiagMappings[Idx++]; |
| 2939 | if (DiagID == (unsigned)-1) |
| 2940 | break; // no more diag/map pairs for this location. |
| 2941 | diag::Mapping Map = (diag::Mapping)PragmaDiagMappings[Idx++]; |
| 2942 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 2943 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2944 | } |
| 2945 | } |
| 2946 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2947 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2948 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2949 | PerFileData *F = 0; |
| 2950 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2951 | F = Chain[N - I - 1]; |
| 2952 | if (Index < F->LocalNumTypes) |
| 2953 | break; |
| 2954 | Index -= F->LocalNumTypes; |
| 2955 | } |
| 2956 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2957 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2961 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2962 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 2963 | /// routine actually reads the record corresponding to the type at the given |
| 2964 | /// location. It is a helper routine for GetType, which deals with reading type |
| 2965 | /// IDs. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2966 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2967 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2968 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2969 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2970 | // Keep track of where we are in the stream, then jump back there |
| 2971 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2972 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2973 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 2974 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 2975 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2976 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 2977 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2978 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2979 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2980 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2981 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2982 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 2983 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2984 | if (Record.size() != 2) { |
| 2985 | Error("Incorrect encoding of extended qualifier type"); |
| 2986 | return QualType(); |
| 2987 | } |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2988 | QualType Base = GetType(Record[0]); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2989 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 2990 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2991 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2992 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2993 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2994 | if (Record.size() != 1) { |
| 2995 | Error("Incorrect encoding of complex type"); |
| 2996 | return QualType(); |
| 2997 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2998 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2999 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3000 | } |
| 3001 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3002 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3003 | if (Record.size() != 1) { |
| 3004 | Error("Incorrect encoding of pointer type"); |
| 3005 | return QualType(); |
| 3006 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3007 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3008 | return Context->getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3011 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3012 | if (Record.size() != 1) { |
| 3013 | Error("Incorrect encoding of block pointer type"); |
| 3014 | return QualType(); |
| 3015 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3016 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3017 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3018 | } |
| 3019 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3020 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3021 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3022 | Error("Incorrect encoding of lvalue reference type"); |
| 3023 | return QualType(); |
| 3024 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3025 | QualType PointeeType = GetType(Record[0]); |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3026 | return Context->getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3029 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3030 | if (Record.size() != 1) { |
| 3031 | Error("Incorrect encoding of rvalue reference type"); |
| 3032 | return QualType(); |
| 3033 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3034 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3035 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3036 | } |
| 3037 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3038 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3039 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3040 | Error("Incorrect encoding of member pointer type"); |
| 3041 | return QualType(); |
| 3042 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3043 | QualType PointeeType = GetType(Record[0]); |
| 3044 | QualType ClassType = GetType(Record[1]); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3045 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3046 | return QualType(); |
| 3047 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3048 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3049 | } |
| 3050 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3051 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3052 | QualType ElementType = GetType(Record[0]); |
| 3053 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3054 | unsigned IndexTypeQuals = Record[2]; |
| 3055 | unsigned Idx = 3; |
| 3056 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3057 | return Context->getConstantArrayType(ElementType, Size, |
| 3058 | ASM, IndexTypeQuals); |
| 3059 | } |
| 3060 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3061 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3062 | QualType ElementType = GetType(Record[0]); |
| 3063 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3064 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3065 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3066 | } |
| 3067 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3068 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3069 | QualType ElementType = GetType(Record[0]); |
| 3070 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3071 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3072 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3073 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 3074 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3075 | ASM, IndexTypeQuals, |
| 3076 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3077 | } |
| 3078 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3079 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3080 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3081 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3082 | return QualType(); |
| 3083 | } |
| 3084 | |
| 3085 | QualType ElementType = GetType(Record[0]); |
| 3086 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3087 | unsigned VecKind = Record[2]; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3088 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3089 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3090 | } |
| 3091 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3092 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3093 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3094 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3095 | return QualType(); |
| 3096 | } |
| 3097 | |
| 3098 | QualType ElementType = GetType(Record[0]); |
| 3099 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3100 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3101 | } |
| 3102 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3103 | case TYPE_FUNCTION_NO_PROTO: { |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3104 | if (Record.size() != 5) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3105 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3106 | return QualType(); |
| 3107 | } |
| 3108 | QualType ResultType = GetType(Record[0]); |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3109 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], (CallingConv)Record[4]); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 3110 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3111 | } |
| 3112 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3113 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3114 | QualType ResultType = GetType(Record[0]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3115 | |
| 3116 | FunctionProtoType::ExtProtoInfo EPI; |
| 3117 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3118 | /*hasregparm*/ Record[2], |
| 3119 | /*regparm*/ Record[3], |
| 3120 | static_cast<CallingConv>(Record[4])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3121 | |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3122 | unsigned Idx = 5; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3123 | unsigned NumParams = Record[Idx++]; |
| 3124 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 3125 | for (unsigned I = 0; I != NumParams; ++I) |
| 3126 | ParamTypes.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3127 | |
| 3128 | EPI.Variadic = Record[Idx++]; |
| 3129 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3130 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3131 | ExceptionSpecificationType EST = |
| 3132 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3133 | EPI.ExceptionSpecType = EST; |
| 3134 | if (EST == EST_Dynamic) { |
| 3135 | EPI.NumExceptions = Record[Idx++]; |
| 3136 | llvm::SmallVector<QualType, 2> Exceptions; |
| 3137 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
| 3138 | Exceptions.push_back(GetType(Record[Idx++])); |
| 3139 | EPI.Exceptions = Exceptions.data(); |
| 3140 | } else if (EST == EST_ComputedNoexcept) { |
| 3141 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
| 3142 | } |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 3143 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3144 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3145 | } |
| 3146 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3147 | case TYPE_UNRESOLVED_USING: |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3148 | return Context->getTypeDeclType( |
| 3149 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 3150 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3151 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3152 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3153 | Error("incorrect encoding of typedef type"); |
| 3154 | return QualType(); |
| 3155 | } |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3156 | TypedefNameDecl *Decl = cast<TypedefNameDecl>(GetDecl(Record[0])); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3157 | QualType Canonical = GetType(Record[1]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3158 | if (!Canonical.isNull()) |
| 3159 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3160 | return Context->getTypedefType(Decl, Canonical); |
| 3161 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3162 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3163 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3164 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3165 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3166 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3167 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3168 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3169 | return QualType(); |
| 3170 | } |
| 3171 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3172 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3173 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3174 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3175 | case TYPE_DECLTYPE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3176 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3177 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3178 | case TYPE_AUTO: |
| 3179 | return Context->getAutoType(GetType(Record[0])); |
| 3180 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3181 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3182 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3183 | Error("incorrect encoding of record type"); |
| 3184 | return QualType(); |
| 3185 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3186 | bool IsDependent = Record[0]; |
| 3187 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3188 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3189 | return T; |
| 3190 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3191 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3192 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3193 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3194 | Error("incorrect encoding of enum type"); |
| 3195 | return QualType(); |
| 3196 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3197 | bool IsDependent = Record[0]; |
| 3198 | QualType T = Context->getEnumType(cast<EnumDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3199 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3200 | return T; |
| 3201 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3202 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3203 | case TYPE_ATTRIBUTED: { |
| 3204 | if (Record.size() != 3) { |
| 3205 | Error("incorrect encoding of attributed type"); |
| 3206 | return QualType(); |
| 3207 | } |
| 3208 | QualType modifiedType = GetType(Record[0]); |
| 3209 | QualType equivalentType = GetType(Record[1]); |
| 3210 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 3211 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 3212 | } |
| 3213 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3214 | case TYPE_PAREN: { |
| 3215 | if (Record.size() != 1) { |
| 3216 | Error("incorrect encoding of paren type"); |
| 3217 | return QualType(); |
| 3218 | } |
| 3219 | QualType InnerType = GetType(Record[0]); |
| 3220 | return Context->getParenType(InnerType); |
| 3221 | } |
| 3222 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3223 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3224 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3225 | Error("incorrect encoding of pack expansion type"); |
| 3226 | return QualType(); |
| 3227 | } |
| 3228 | QualType Pattern = GetType(Record[0]); |
| 3229 | if (Pattern.isNull()) |
| 3230 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3231 | llvm::Optional<unsigned> NumExpansions; |
| 3232 | if (Record[1]) |
| 3233 | NumExpansions = Record[1] - 1; |
| 3234 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3235 | } |
| 3236 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3237 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3238 | unsigned Idx = 0; |
| 3239 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3240 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3241 | QualType NamedType = GetType(Record[Idx++]); |
| 3242 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3243 | } |
| 3244 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3245 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3246 | unsigned Idx = 0; |
| 3247 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3248 | return Context->getObjCInterfaceType(ItfD); |
| 3249 | } |
| 3250 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3251 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3252 | unsigned Idx = 0; |
| 3253 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3254 | unsigned NumProtos = Record[Idx++]; |
| 3255 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 3256 | for (unsigned I = 0; I != NumProtos; ++I) |
| 3257 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3258 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3259 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3260 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3261 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3262 | unsigned Idx = 0; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3263 | QualType Pointee = GetType(Record[Idx++]); |
| 3264 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3265 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3266 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3267 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3268 | unsigned Idx = 0; |
| 3269 | QualType Parm = GetType(Record[Idx++]); |
| 3270 | QualType Replacement = GetType(Record[Idx++]); |
| 3271 | return |
| 3272 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3273 | Replacement); |
| 3274 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3275 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3276 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3277 | unsigned Idx = 0; |
| 3278 | QualType Parm = GetType(Record[Idx++]); |
| 3279 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3280 | return Context->getSubstTemplateTypeParmPackType( |
| 3281 | cast<TemplateTypeParmType>(Parm), |
| 3282 | ArgPack); |
| 3283 | } |
| 3284 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3285 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3286 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 3287 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3288 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3289 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3290 | return |
| 3291 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3292 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3293 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3294 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3295 | unsigned Idx = 0; |
| 3296 | unsigned Depth = Record[Idx++]; |
| 3297 | unsigned Index = Record[Idx++]; |
| 3298 | bool Pack = Record[Idx++]; |
| 3299 | IdentifierInfo *Name = GetIdentifierInfo(Record, Idx); |
| 3300 | return Context->getTemplateTypeParmType(Depth, Index, Pack, Name); |
| 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_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3304 | unsigned Idx = 0; |
| 3305 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3306 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3307 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3308 | QualType Canon = GetType(Record[Idx++]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3309 | if (!Canon.isNull()) |
| 3310 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3311 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3312 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3313 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3314 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3315 | unsigned Idx = 0; |
| 3316 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3317 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3318 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
| 3319 | unsigned NumArgs = Record[Idx++]; |
| 3320 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 3321 | Args.reserve(NumArgs); |
| 3322 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3323 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3324 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3325 | Args.size(), Args.data()); |
| 3326 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3327 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3328 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3329 | unsigned Idx = 0; |
| 3330 | |
| 3331 | // ArrayType |
| 3332 | QualType ElementType = GetType(Record[Idx++]); |
| 3333 | ArrayType::ArraySizeModifier ASM |
| 3334 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3335 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3336 | |
| 3337 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3338 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3339 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3340 | |
| 3341 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3342 | IndexTypeQuals, Brackets); |
| 3343 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3344 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3345 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3346 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3347 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3348 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3349 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3350 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3351 | QualType Canon = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3352 | QualType T; |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3353 | if (Canon.isNull()) |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3354 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3355 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3356 | else |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3357 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
| 3358 | Args.size(), Canon); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3359 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3360 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3361 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3362 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3363 | // Suppress a GCC warning |
| 3364 | return QualType(); |
| 3365 | } |
| 3366 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3367 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3368 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3369 | ASTReader::PerFileData &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3370 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3371 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3372 | unsigned &Idx; |
| 3373 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3374 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3375 | unsigned &I) { |
| 3376 | return Reader.ReadSourceLocation(F, R, I); |
| 3377 | } |
| 3378 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3379 | public: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3380 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3381 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3382 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3383 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3384 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3385 | // We want compile-time assurance that we've enumerated all of |
| 3386 | // these, so unfortunately we have to declare them first, then |
| 3387 | // define them out-of-line. |
| 3388 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3389 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3390 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3391 | #include "clang/AST/TypeLocNodes.def" |
| 3392 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3393 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3394 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3395 | }; |
| 3396 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3397 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3398 | // nothing to do |
| 3399 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3400 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3401 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3402 | if (TL.needsExtraLocalData()) { |
| 3403 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3404 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3405 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3406 | TL.setModeAttr(Record[Idx++]); |
| 3407 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3408 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3409 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3410 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3411 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3412 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3413 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3414 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3415 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3416 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3417 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3418 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3419 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3420 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3421 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3422 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3423 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3424 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3425 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3426 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3427 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3428 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3429 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3430 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3431 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3432 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3433 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3434 | TL.setSizeExpr(0); |
| 3435 | } |
| 3436 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3437 | VisitArrayTypeLoc(TL); |
| 3438 | } |
| 3439 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3440 | VisitArrayTypeLoc(TL); |
| 3441 | } |
| 3442 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3443 | VisitArrayTypeLoc(TL); |
| 3444 | } |
| 3445 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3446 | DependentSizedArrayTypeLoc TL) { |
| 3447 | VisitArrayTypeLoc(TL); |
| 3448 | } |
| 3449 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3450 | DependentSizedExtVectorTypeLoc 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::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3454 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3455 | } |
| 3456 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3457 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3458 | } |
| 3459 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3460 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 3461 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3462 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3463 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | 86acc2a | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 3464 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3465 | } |
| 3466 | } |
| 3467 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3468 | VisitFunctionTypeLoc(TL); |
| 3469 | } |
| 3470 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3471 | VisitFunctionTypeLoc(TL); |
| 3472 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3473 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3474 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3475 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3476 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3477 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3478 | } |
| 3479 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3480 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3481 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3482 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3483 | } |
| 3484 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3485 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3486 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3487 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3488 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3489 | } |
| 3490 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3491 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3492 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3493 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3494 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3495 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3496 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3497 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3498 | } |
| 3499 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3500 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3501 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3502 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3503 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3504 | if (TL.hasAttrOperand()) { |
| 3505 | SourceRange range; |
| 3506 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3507 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3508 | TL.setAttrOperandParensRange(range); |
| 3509 | } |
| 3510 | if (TL.hasAttrExprOperand()) { |
| 3511 | if (Record[Idx++]) |
| 3512 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3513 | else |
| 3514 | TL.setAttrExprOperand(0); |
| 3515 | } else if (TL.hasAttrEnumOperand()) |
| 3516 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3517 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3518 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3519 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3520 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3521 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3522 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3523 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3524 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3525 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3526 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3527 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3528 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3529 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3530 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3531 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3532 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3533 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3534 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3535 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3536 | Reader.GetTemplateArgumentLocInfo(F, |
| 3537 | TL.getTypePtr()->getArg(i).getKind(), |
| 3538 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3539 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3540 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3541 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3542 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3543 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3544 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3545 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3546 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3547 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3548 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3549 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3550 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3551 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3552 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3553 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3554 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3555 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3556 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3557 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3558 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3559 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3560 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3561 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3562 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3563 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3564 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3565 | Reader.GetTemplateArgumentLocInfo(F, |
| 3566 | TL.getTypePtr()->getArg(I).getKind(), |
| 3567 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3568 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3569 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3570 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3571 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3572 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3573 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3574 | } |
| 3575 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3576 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3577 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3578 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3579 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3580 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3581 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3582 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3583 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3584 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3585 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3586 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3587 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3588 | unsigned &Idx) { |
| 3589 | QualType InfoTy = GetType(Record[Idx++]); |
| 3590 | if (InfoTy.isNull()) |
| 3591 | return 0; |
| 3592 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3593 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3594 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3595 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3596 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3597 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3598 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3599 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3600 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3601 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3602 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3603 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3604 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3605 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3606 | switch ((PredefinedTypeIDs)Index) { |
| 3607 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3608 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3609 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3610 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3611 | case PREDEF_TYPE_CHAR_U_ID: |
| 3612 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3613 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3614 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3615 | break; |
| 3616 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3617 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3618 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3619 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3620 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3621 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3622 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3623 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3624 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3625 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3626 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3627 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3628 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3629 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3630 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3631 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3632 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3633 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
| 3634 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
John McCall | 1de4d4e | 2011-04-07 08:22:57 +0000 | [diff] [blame] | 3635 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context->UnknownAnyTy; break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3636 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3637 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3638 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3639 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3640 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3641 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3642 | } |
| 3643 | |
| 3644 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3645 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3646 | } |
| 3647 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3648 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3649 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3650 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3651 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3652 | if (TypesLoaded[Index].isNull()) |
| 3653 | return QualType(); |
| 3654 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3655 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3656 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3657 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3658 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3659 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3660 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3661 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3662 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3663 | } |
| 3664 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3665 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3666 | return MakeTypeID(T, |
| 3667 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3668 | } |
| 3669 | |
| 3670 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3671 | if (T.isNull()) |
| 3672 | return TypeIdx(); |
| 3673 | assert(!T.getLocalFastQualifiers()); |
| 3674 | |
| 3675 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3676 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3677 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3678 | // If the type didn't come from the AST file use a specially marked index |
| 3679 | // so that any hash/key comparison fail since no such index is stored |
| 3680 | // in a AST file. |
| 3681 | if (I == TypeIdxs.end()) |
| 3682 | return TypeIdx(-1); |
| 3683 | return I->second; |
| 3684 | } |
| 3685 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3686 | unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const { |
| 3687 | unsigned Result = 0; |
| 3688 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 3689 | Result += Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3690 | |
| 3691 | return Result; |
| 3692 | } |
| 3693 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3694 | TemplateArgumentLocInfo |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3695 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3696 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3697 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3698 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3699 | switch (Kind) { |
| 3700 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3701 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3702 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3703 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3704 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3705 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3706 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3707 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3708 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3709 | SourceLocation()); |
| 3710 | } |
| 3711 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3712 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3713 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3714 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3715 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3716 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3717 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3718 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3719 | case TemplateArgument::Null: |
| 3720 | case TemplateArgument::Integral: |
| 3721 | case TemplateArgument::Declaration: |
| 3722 | case TemplateArgument::Pack: |
| 3723 | return TemplateArgumentLocInfo(); |
| 3724 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3725 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3726 | return TemplateArgumentLocInfo(); |
| 3727 | } |
| 3728 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3729 | TemplateArgumentLoc |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3730 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3731 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3732 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3733 | |
| 3734 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3735 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3736 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3737 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3738 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3739 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3740 | } |
| 3741 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3742 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3743 | return GetDecl(ID); |
| 3744 | } |
| 3745 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3746 | uint64_t |
| 3747 | ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) { |
| 3748 | if (ID == 0) |
| 3749 | return 0; |
| 3750 | |
| 3751 | --ID; |
| 3752 | uint64_t Offset = 0; |
| 3753 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3754 | PerFileData &F = *Chain[N - I - 1]; |
| 3755 | |
| 3756 | if (ID < F.LocalNumCXXBaseSpecifiers) |
| 3757 | return Offset + F.CXXBaseSpecifiersOffsets[ID]; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3758 | |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3759 | ID -= F.LocalNumCXXBaseSpecifiers; |
| 3760 | Offset += F.SizeInBits; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | assert(false && "CXXBaseSpecifiers not found"); |
| 3764 | return 0; |
| 3765 | } |
| 3766 | |
| 3767 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 3768 | // Figure out which AST file contains this offset. |
| 3769 | PerFileData *F = 0; |
| 3770 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3771 | if (Offset < Chain[N - I - 1]->SizeInBits) { |
| 3772 | F = Chain[N - I - 1]; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3773 | break; |
| 3774 | } |
| 3775 | |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3776 | Offset -= Chain[N - I - 1]->SizeInBits; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3777 | } |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3778 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3779 | if (!F) { |
| 3780 | Error("Malformed AST file: C++ base specifiers at impossible offset"); |
| 3781 | return 0; |
| 3782 | } |
| 3783 | |
| 3784 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3785 | SavedStreamPosition SavedPosition(Cursor); |
| 3786 | Cursor.JumpToBit(Offset); |
| 3787 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3788 | RecordData Record; |
| 3789 | unsigned Code = Cursor.ReadCode(); |
| 3790 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 3791 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 3792 | Error("Malformed AST file: missing C++ base specifiers"); |
| 3793 | return 0; |
| 3794 | } |
| 3795 | |
| 3796 | unsigned Idx = 0; |
| 3797 | unsigned NumBases = Record[Idx++]; |
| 3798 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 3799 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 3800 | for (unsigned I = 0; I != NumBases; ++I) |
| 3801 | Bases[I] = ReadCXXBaseSpecifier(*F, Record, Idx); |
| 3802 | return Bases; |
| 3803 | } |
| 3804 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3805 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3806 | if (!DeclsLoaded[0]) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 3807 | ReadDeclRecord(0, 1); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3808 | if (DeserializationListener) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3809 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3810 | } |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 3811 | |
| 3812 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 3813 | } |
| 3814 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3815 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3816 | if (ID == 0) |
| 3817 | return 0; |
| 3818 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3819 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3820 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3821 | return 0; |
| 3822 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3823 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3824 | unsigned Index = ID - 1; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3825 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3826 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3827 | if (DeserializationListener) |
| 3828 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3829 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3830 | |
| 3831 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3834 | /// \brief Resolve the offset of a statement into a statement. |
| 3835 | /// |
| 3836 | /// This operation will read a new statement from the external |
| 3837 | /// source each time it is called, and is meant to be used via a |
| 3838 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3839 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 3840 | // Switch case IDs are per Decl. |
| 3841 | ClearSwitchCaseIDs(); |
| 3842 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3843 | // Offset here is a global offset across the entire chain. |
| 3844 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3845 | PerFileData &F = *Chain[N - I - 1]; |
| 3846 | if (Offset < F.SizeInBits) { |
| 3847 | // Since we know that this statement is part of a decl, make sure to use |
| 3848 | // the decl cursor to read it. |
| 3849 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3850 | return ReadStmtFromStream(F); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3851 | } |
| 3852 | Offset -= F.SizeInBits; |
| 3853 | } |
| 3854 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 3855 | } |
| 3856 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3857 | bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3858 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3859 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3860 | assert(DC->hasExternalLexicalStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3861 | "DeclContext has no lexical decls in storage"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3862 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3863 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 3864 | // at least. |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3865 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 3866 | // so make a copy of the vector. |
| 3867 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3868 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3869 | I != E; ++I) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3870 | // IDs can be 0 if this context doesn't contain declarations. |
| 3871 | if (!I->LexicalDecls) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3872 | continue; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3873 | |
| 3874 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3875 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 3876 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 3877 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 3878 | continue; |
| 3879 | |
| 3880 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3881 | assert(D && "Null decl in lexical decls"); |
| 3882 | Decls.push_back(D); |
| 3883 | } |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3884 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3885 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3886 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3887 | return false; |
| 3888 | } |
| 3889 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3890 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3891 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3892 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3893 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3894 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3895 | if (!Name) |
| 3896 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 3897 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3898 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3899 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 8b12273 | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 3900 | // 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] | 3901 | // and namespaces. For any given name, the last available results replace |
| 3902 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3903 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3904 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3905 | I != E; ++I) { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3906 | if (!I->NameLookupTableData) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3907 | continue; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3908 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3909 | ASTDeclContextNameLookupTable *LookupTable = |
| 3910 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3911 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 3912 | if (Pos == LookupTable->end()) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3913 | continue; |
| 3914 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3915 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 3916 | for (; Data.first != Data.second; ++Data.first) |
| 3917 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3918 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3919 | } |
| 3920 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3921 | ++NumVisibleDeclContextsRead; |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3922 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3923 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3924 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3925 | } |
| 3926 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 3927 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 3928 | assert(DC->hasExternalVisibleStorage() && |
| 3929 | "DeclContext has no visible decls in storage"); |
| 3930 | |
| 3931 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 3932 | // There might be visible decls in multiple parts of the chain, for the TU |
| 3933 | // and namespaces. |
| 3934 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 3935 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3936 | I != E; ++I) { |
| 3937 | if (!I->NameLookupTableData) |
| 3938 | continue; |
| 3939 | |
| 3940 | ASTDeclContextNameLookupTable *LookupTable = |
| 3941 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3942 | for (ASTDeclContextNameLookupTable::item_iterator |
| 3943 | ItemI = LookupTable->item_begin(), |
| 3944 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 3945 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 3946 | = *ItemI; |
| 3947 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 3948 | Decls.clear(); |
| 3949 | for (; Data.first != Data.second; ++Data.first) |
| 3950 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 3951 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 3952 | } |
| 3953 | } |
| 3954 | } |
| 3955 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3956 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3957 | assert(Consumer); |
| 3958 | while (!InterestingDecls.empty()) { |
| 3959 | DeclGroupRef DG(InterestingDecls.front()); |
| 3960 | InterestingDecls.pop_front(); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3961 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3962 | } |
| 3963 | } |
| 3964 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3965 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 3966 | this->Consumer = Consumer; |
| 3967 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3968 | if (!Consumer) |
| 3969 | return; |
| 3970 | |
| 3971 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3972 | // Force deserialization of this decl, which will cause it to be queued for |
| 3973 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 3974 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3975 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 3976 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3977 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3978 | } |
| 3979 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3980 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3981 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3982 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3983 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3984 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3985 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3986 | unsigned NumDeclsLoaded |
| 3987 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 3988 | (Decl *)0); |
| 3989 | unsigned NumIdentifiersLoaded |
| 3990 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 3991 | IdentifiersLoaded.end(), |
| 3992 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3993 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3994 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 3995 | SelectorsLoaded.end(), |
| 3996 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 3997 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3998 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 3999 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4000 | if (TotalNumSLocEntries) |
| 4001 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 4002 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 4003 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4004 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4005 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4006 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 4007 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 4008 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4009 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4010 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 4011 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4012 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4013 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4014 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4015 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4016 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4017 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4018 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4019 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4020 | if (TotalNumStatements) |
| 4021 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4022 | NumStatementsRead, TotalNumStatements, |
| 4023 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4024 | if (TotalNumMacros) |
| 4025 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4026 | NumMacrosRead, TotalNumMacros, |
| 4027 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4028 | if (TotalLexicalDeclContexts) |
| 4029 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4030 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4031 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4032 | * 100)); |
| 4033 | if (TotalVisibleDeclContexts) |
| 4034 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4035 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4036 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4037 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4038 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4039 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4040 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4041 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4042 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4043 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4044 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4045 | std::fprintf(stderr, "\n"); |
| 4046 | } |
| 4047 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4048 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4049 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4050 | S.ExternalSource = this; |
| 4051 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4052 | // Makes sure any declarations that were deserialized "too early" |
| 4053 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4054 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4055 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4056 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4057 | |
| 4058 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4059 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4060 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4061 | |
| 4062 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4063 | // them to Sema's list of tentative definitions. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4064 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4065 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4066 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4067 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 4068 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4069 | // If there were any unused file scoped decls, deserialize them and add to |
| 4070 | // Sema's list of unused file scoped decls. |
| 4071 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4072 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4073 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 4074 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4075 | |
| 4076 | // If there were any locally-scoped external declarations, |
| 4077 | // deserialize them and add them to Sema's table of locally-scoped |
| 4078 | // external declarations. |
| 4079 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4080 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4081 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 4082 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4083 | |
| 4084 | // If there were any ext_vector type declarations, deserialize them |
| 4085 | // and add them to Sema's vector of such declarations. |
| 4086 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 4087 | SemaObj->ExtVectorDecls.push_back( |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4088 | cast<TypedefNameDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4089 | |
| 4090 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 4091 | // Can we cut them down before writing them ? |
| 4092 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4093 | // If there were any dynamic classes declarations, deserialize them |
| 4094 | // and add them to Sema's vector of such declarations. |
| 4095 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 4096 | SemaObj->DynamicClasses.push_back( |
| 4097 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4098 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4099 | // Load the offsets of the declarations that Sema references. |
| 4100 | // They will be lazily deserialized when needed. |
| 4101 | if (!SemaDeclRefs.empty()) { |
| 4102 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 4103 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4104 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 4105 | } |
| 4106 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4107 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 4108 | |
| 4109 | // If there are @selector references added them to its pool. This is for |
| 4110 | // implementation of -Wselector. |
| 4111 | if (!F->ReferencedSelectorsData.empty()) { |
| 4112 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 4113 | unsigned I = 0; |
| 4114 | while (I < DataSize) { |
| 4115 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 4116 | SourceLocation SelLoc = ReadSourceLocation( |
| 4117 | *F, F->ReferencedSelectorsData, I); |
| 4118 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 4119 | } |
| 4120 | } |
| 4121 | |
| 4122 | // If there were any pending implicit instantiations, deserialize them |
| 4123 | // and add them to Sema's queue of such instantiations. |
| 4124 | assert(F->PendingInstantiations.size() % 2 == 0 && |
| 4125 | "Expected pairs of entries"); |
| 4126 | for (unsigned Idx = 0, N = F->PendingInstantiations.size(); Idx < N;) { |
| 4127 | ValueDecl *D=cast<ValueDecl>(GetDecl(F->PendingInstantiations[Idx++])); |
| 4128 | SourceLocation Loc = ReadSourceLocation(*F, F->PendingInstantiations,Idx); |
| 4129 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 4130 | } |
| 4131 | } |
| 4132 | |
| 4133 | // The two special data sets below always come from the most recent PCH, |
| 4134 | // which is at the front of the chain. |
| 4135 | PerFileData &F = *Chain.front(); |
| 4136 | |
| 4137 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 4138 | // Sema's list of weak undeclared identifiers. |
| 4139 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 4140 | unsigned Idx = 0; |
| 4141 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 4142 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4143 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4144 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 4145 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 4146 | Sema::WeakInfo WI(AliasId, Loc); |
| 4147 | WI.setUsed(Used); |
| 4148 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 4149 | } |
| 4150 | } |
| 4151 | |
| 4152 | // If there were any VTable uses, deserialize the information and add it |
| 4153 | // to Sema's vector and map of VTable uses. |
| 4154 | if (!VTableUses.empty()) { |
| 4155 | unsigned Idx = 0; |
| 4156 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 4157 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4158 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 4159 | bool DefinitionRequired = VTableUses[Idx++]; |
| 4160 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 4161 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4162 | } |
| 4163 | } |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4164 | |
| 4165 | if (!FPPragmaOptions.empty()) { |
| 4166 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4167 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4168 | } |
| 4169 | |
| 4170 | if (!OpenCLExtensions.empty()) { |
| 4171 | unsigned I = 0; |
| 4172 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4173 | #include "clang/Basic/OpenCLExtensions.def" |
| 4174 | |
| 4175 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4176 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4177 | } |
| 4178 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4179 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4180 | // Try to find this name within our on-disk hash tables. We start with the |
| 4181 | // 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] | 4182 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4183 | ASTIdentifierLookupTable *IdTable |
| 4184 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4185 | if (!IdTable) |
| 4186 | continue; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4187 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4188 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4189 | if (Pos == IdTable->end()) |
| 4190 | continue; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4191 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4192 | // Dereferencing the iterator has the effect of building the |
| 4193 | // IdentifierInfo node and populating it with the various |
| 4194 | // declarations it needs. |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4195 | return *Pos; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4196 | } |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4197 | return 0; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4198 | } |
| 4199 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4200 | namespace clang { |
| 4201 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4202 | /// identifiers stored within a set of AST files. |
| 4203 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4204 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4205 | const ASTReader &Reader; |
| 4206 | |
| 4207 | /// \brief The current index into the chain of AST files stored in |
| 4208 | /// the AST reader. |
| 4209 | unsigned Index; |
| 4210 | |
| 4211 | /// \brief The current position within the identifier lookup table |
| 4212 | /// of the current AST file. |
| 4213 | ASTIdentifierLookupTable::key_iterator Current; |
| 4214 | |
| 4215 | /// \brief The end position within the identifier lookup table of |
| 4216 | /// the current AST file. |
| 4217 | ASTIdentifierLookupTable::key_iterator End; |
| 4218 | |
| 4219 | public: |
| 4220 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4221 | |
| 4222 | virtual llvm::StringRef Next(); |
| 4223 | }; |
| 4224 | } |
| 4225 | |
| 4226 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 4227 | : Reader(Reader), Index(Reader.Chain.size() - 1) { |
| 4228 | ASTIdentifierLookupTable *IdTable |
| 4229 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4230 | Current = IdTable->key_begin(); |
| 4231 | End = IdTable->key_end(); |
| 4232 | } |
| 4233 | |
| 4234 | llvm::StringRef ASTIdentifierIterator::Next() { |
| 4235 | while (Current == End) { |
| 4236 | // If we have exhausted all of our AST files, we're done. |
| 4237 | if (Index == 0) |
| 4238 | return llvm::StringRef(); |
| 4239 | |
| 4240 | --Index; |
| 4241 | ASTIdentifierLookupTable *IdTable |
| 4242 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4243 | Current = IdTable->key_begin(); |
| 4244 | End = IdTable->key_end(); |
| 4245 | } |
| 4246 | |
| 4247 | // We have any identifiers remaining in the current AST file; return |
| 4248 | // the next one. |
| 4249 | std::pair<const char*, unsigned> Key = *Current; |
| 4250 | ++Current; |
| 4251 | return llvm::StringRef(Key.first, Key.second); |
| 4252 | } |
| 4253 | |
| 4254 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4255 | return new ASTIdentifierIterator(*this); |
| 4256 | } |
| 4257 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4258 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4259 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4260 | // Find this selector in a hash table. We want to find the most recent entry. |
| 4261 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4262 | PerFileData &F = *Chain[I]; |
| 4263 | if (!F.SelectorLookupTable) |
| 4264 | continue; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4265 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4266 | ASTSelectorLookupTable *PoolTable |
| 4267 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 4268 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4269 | if (Pos != PoolTable->end()) { |
| 4270 | ++NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4271 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4272 | // disable this tracking when called via LoadSelector. |
| 4273 | // Also, should entries without methods count as misses? |
| 4274 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4275 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4276 | if (DeserializationListener) |
| 4277 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 4278 | return std::make_pair(Data.Instance, Data.Factory); |
| 4279 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4280 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4281 | |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4282 | ++NumMethodPoolMisses; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4283 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4284 | } |
| 4285 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4286 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4287 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4288 | ReadMethodPool(Sel); |
| 4289 | } |
| 4290 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4291 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4292 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4293 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4294 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4295 | if (DeserializationListener) |
| 4296 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4297 | } |
| 4298 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4299 | /// \brief Set the globally-visible declarations associated with the given |
| 4300 | /// identifier. |
| 4301 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4302 | /// 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] | 4303 | /// 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] | 4304 | /// them. |
| 4305 | /// |
| 4306 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4307 | /// declarations. |
| 4308 | /// |
| 4309 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4310 | /// visible at global scope. |
| 4311 | /// |
| 4312 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4313 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4314 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4315 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4316 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4317 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 4318 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4319 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4320 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4321 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4322 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4323 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4324 | return; |
| 4325 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4326 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4327 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4328 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4329 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4330 | if (SemaObj->TUScope) { |
| 4331 | // Introduce this declaration into the translation-unit scope |
| 4332 | // and add it to the declaration chain for this identifier, so |
| 4333 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4334 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4335 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4336 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4337 | } else { |
| 4338 | // Queue this declaration so that it will be added to the |
| 4339 | // translation unit scope and identifier's declaration chain |
| 4340 | // once a Sema object is known. |
| 4341 | PreloadedDecls.push_back(D); |
| 4342 | } |
| 4343 | } |
| 4344 | } |
| 4345 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4346 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4347 | if (ID == 0) |
| 4348 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4349 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4350 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4351 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4352 | return 0; |
| 4353 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4354 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4355 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4356 | ID -= 1; |
| 4357 | if (!IdentifiersLoaded[ID]) { |
| 4358 | unsigned Index = ID; |
| 4359 | const char *Str = 0; |
| 4360 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4361 | PerFileData *F = Chain[N - I - 1]; |
| 4362 | if (Index < F->LocalNumIdentifiers) { |
| 4363 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 4364 | Str = F->IdentifierTableData + Offset; |
| 4365 | break; |
| 4366 | } |
| 4367 | Index -= F->LocalNumIdentifiers; |
| 4368 | } |
| 4369 | assert(Str && "Broken Chain"); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4370 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4371 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4372 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4373 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4374 | // unsigned integers. This is important to avoid integer overflow when |
| 4375 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4376 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4377 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4378 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4379 | IdentifiersLoaded[ID] |
Kovarththanan Rajaratnam | 811f426 | 2010-03-12 10:32:27 +0000 | [diff] [blame] | 4380 | = &PP->getIdentifierTable().get(Str, StrLen); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4381 | if (DeserializationListener) |
| 4382 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4383 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4384 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4385 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4386 | } |
| 4387 | |
Douglas Gregor | e23ac65 | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 4388 | bool ASTReader::ReadSLocEntry(unsigned ID) { |
| 4389 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4390 | } |
| 4391 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4392 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4393 | if (ID == 0) |
| 4394 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4395 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4396 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4397 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4398 | return Selector(); |
| 4399 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4400 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4401 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4402 | // Load this selector from the selector table. |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4403 | unsigned Idx = ID - 1; |
| 4404 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4405 | PerFileData &F = *Chain[N - I - 1]; |
| 4406 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4407 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4408 | SelectorsLoaded[ID - 1] = |
| 4409 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 4410 | if (DeserializationListener) |
| 4411 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 4412 | break; |
| 4413 | } |
| 4414 | Idx -= F.LocalNumSelectors; |
| 4415 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4416 | } |
| 4417 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4418 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4419 | } |
| 4420 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4421 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4422 | return DecodeSelector(ID); |
| 4423 | } |
| 4424 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4425 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4426 | // ID 0 (the null selector) is considered an external selector. |
| 4427 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4428 | } |
| 4429 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4430 | DeclarationName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4431 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4432 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4433 | switch (Kind) { |
| 4434 | case DeclarationName::Identifier: |
| 4435 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 4436 | |
| 4437 | case DeclarationName::ObjCZeroArgSelector: |
| 4438 | case DeclarationName::ObjCOneArgSelector: |
| 4439 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 4440 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4441 | |
| 4442 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4443 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4444 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4445 | |
| 4446 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4447 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4448 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4449 | |
| 4450 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4451 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4452 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4453 | |
| 4454 | case DeclarationName::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4455 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4456 | (OverloadedOperatorKind)Record[Idx++]); |
| 4457 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4458 | case DeclarationName::CXXLiteralOperatorName: |
| 4459 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 4460 | GetIdentifierInfo(Record, Idx)); |
| 4461 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4462 | case DeclarationName::CXXUsingDirective: |
| 4463 | return DeclarationName::getUsingDirectiveName(); |
| 4464 | } |
| 4465 | |
| 4466 | // Required to silence GCC warning |
| 4467 | return DeclarationName(); |
| 4468 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4469 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4470 | void ASTReader::ReadDeclarationNameLoc(PerFileData &F, |
| 4471 | DeclarationNameLoc &DNLoc, |
| 4472 | DeclarationName Name, |
| 4473 | const RecordData &Record, unsigned &Idx) { |
| 4474 | switch (Name.getNameKind()) { |
| 4475 | case DeclarationName::CXXConstructorName: |
| 4476 | case DeclarationName::CXXDestructorName: |
| 4477 | case DeclarationName::CXXConversionFunctionName: |
| 4478 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4479 | break; |
| 4480 | |
| 4481 | case DeclarationName::CXXOperatorName: |
| 4482 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4483 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4484 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4485 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4486 | break; |
| 4487 | |
| 4488 | case DeclarationName::CXXLiteralOperatorName: |
| 4489 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4490 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4491 | break; |
| 4492 | |
| 4493 | case DeclarationName::Identifier: |
| 4494 | case DeclarationName::ObjCZeroArgSelector: |
| 4495 | case DeclarationName::ObjCOneArgSelector: |
| 4496 | case DeclarationName::ObjCMultiArgSelector: |
| 4497 | case DeclarationName::CXXUsingDirective: |
| 4498 | break; |
| 4499 | } |
| 4500 | } |
| 4501 | |
| 4502 | void ASTReader::ReadDeclarationNameInfo(PerFileData &F, |
| 4503 | DeclarationNameInfo &NameInfo, |
| 4504 | const RecordData &Record, unsigned &Idx) { |
| 4505 | NameInfo.setName(ReadDeclarationName(Record, Idx)); |
| 4506 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4507 | DeclarationNameLoc DNLoc; |
| 4508 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4509 | NameInfo.setInfo(DNLoc); |
| 4510 | } |
| 4511 | |
| 4512 | void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info, |
| 4513 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4514 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4515 | unsigned NumTPLists = Record[Idx++]; |
| 4516 | Info.NumTemplParamLists = NumTPLists; |
| 4517 | if (NumTPLists) { |
| 4518 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 4519 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4520 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4521 | } |
| 4522 | } |
| 4523 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4524 | TemplateName |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4525 | ASTReader::ReadTemplateName(PerFileData &F, const RecordData &Record, |
| 4526 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4527 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4528 | switch (Kind) { |
| 4529 | case TemplateName::Template: |
| 4530 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 4531 | |
| 4532 | case TemplateName::OverloadedTemplate: { |
| 4533 | unsigned size = Record[Idx++]; |
| 4534 | UnresolvedSet<8> Decls; |
| 4535 | while (size--) |
| 4536 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 4537 | |
| 4538 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 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 | case TemplateName::QualifiedTemplate: { |
| 4542 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4543 | bool hasTemplKeyword = Record[Idx++]; |
| 4544 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 4545 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 4546 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4547 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4548 | case TemplateName::DependentTemplate: { |
| 4549 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4550 | if (Record[Idx++]) // isIdentifier |
| 4551 | return Context->getDependentTemplateName(NNS, |
| 4552 | GetIdentifierInfo(Record, Idx)); |
| 4553 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4554 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4555 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4556 | |
| 4557 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4558 | TemplateTemplateParmDecl *Param |
| 4559 | = cast_or_null<TemplateTemplateParmDecl>(GetDecl(Record[Idx++])); |
| 4560 | if (!Param) |
| 4561 | return TemplateName(); |
| 4562 | |
| 4563 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 4564 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 4565 | return TemplateName(); |
| 4566 | |
| 4567 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 4568 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4569 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4570 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4571 | assert(0 && "Unhandled template name kind!"); |
| 4572 | return TemplateName(); |
| 4573 | } |
| 4574 | |
| 4575 | TemplateArgument |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4576 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4577 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4578 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 4579 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4580 | case TemplateArgument::Null: |
| 4581 | return TemplateArgument(); |
| 4582 | case TemplateArgument::Type: |
| 4583 | return TemplateArgument(GetType(Record[Idx++])); |
| 4584 | case TemplateArgument::Declaration: |
| 4585 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4586 | case TemplateArgument::Integral: { |
| 4587 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 4588 | QualType T = GetType(Record[Idx++]); |
| 4589 | return TemplateArgument(Value, T); |
| 4590 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4591 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4592 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4593 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4594 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4595 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 4596 | if (unsigned NumExpansions = Record[Idx++]) |
| 4597 | NumTemplateExpansions = NumExpansions - 1; |
| 4598 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4599 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4600 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4601 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4602 | case TemplateArgument::Pack: { |
| 4603 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4604 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 4605 | for (unsigned I = 0; I != NumArgs; ++I) |
| 4606 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 4607 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4608 | } |
| 4609 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4610 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4611 | assert(0 && "Unhandled template argument kind!"); |
| 4612 | return TemplateArgument(); |
| 4613 | } |
| 4614 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4615 | TemplateParameterList * |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4616 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 4617 | const RecordData &Record, unsigned &Idx) { |
| 4618 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 4619 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 4620 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4621 | |
| 4622 | unsigned NumParams = Record[Idx++]; |
| 4623 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 4624 | Params.reserve(NumParams); |
| 4625 | while (NumParams--) |
| 4626 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4627 | |
| 4628 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4629 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 4630 | Params.data(), Params.size(), RAngleLoc); |
| 4631 | return TemplateParams; |
| 4632 | } |
| 4633 | |
| 4634 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4635 | ASTReader:: |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4636 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4637 | PerFileData &F, const RecordData &Record, |
| 4638 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4639 | unsigned NumTemplateArgs = Record[Idx++]; |
| 4640 | TemplArgs.reserve(NumTemplateArgs); |
| 4641 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4642 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4643 | } |
| 4644 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4645 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4646 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4647 | const RecordData &Record, unsigned &Idx) { |
| 4648 | unsigned NumDecls = Record[Idx++]; |
| 4649 | while (NumDecls--) { |
| 4650 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 4651 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 4652 | Set.addDecl(D, AS); |
| 4653 | } |
| 4654 | } |
| 4655 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4656 | CXXBaseSpecifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4657 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4658 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4659 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 4660 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 4661 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4662 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4663 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4664 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4665 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4666 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4667 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4668 | Result.setInheritConstructors(inheritConstructors); |
| 4669 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4670 | } |
| 4671 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4672 | std::pair<CXXCtorInitializer **, unsigned> |
| 4673 | ASTReader::ReadCXXCtorInitializers(PerFileData &F, const RecordData &Record, |
| 4674 | unsigned &Idx) { |
| 4675 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4676 | unsigned NumInitializers = Record[Idx++]; |
| 4677 | if (NumInitializers) { |
| 4678 | ASTContext &C = *getContext(); |
| 4679 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4680 | CtorInitializers |
| 4681 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4682 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 4683 | TypeSourceInfo *BaseClassInfo = 0; |
| 4684 | bool IsBaseVirtual = false; |
| 4685 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4686 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4687 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4688 | bool IsBaseInitializer = Record[Idx++]; |
| 4689 | if (IsBaseInitializer) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4690 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4691 | IsBaseVirtual = Record[Idx++]; |
| 4692 | } else { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4693 | bool IsIndirectMemberInitializer = Record[Idx++]; |
| 4694 | if (IsIndirectMemberInitializer) |
| 4695 | IndirectMember = cast<IndirectFieldDecl>(GetDecl(Record[Idx++])); |
| 4696 | else |
| 4697 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4698 | } |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 4699 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4700 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4701 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 4702 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4703 | bool IsWritten = Record[Idx++]; |
| 4704 | unsigned SourceOrderOrNumArrayIndices; |
| 4705 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 4706 | if (IsWritten) { |
| 4707 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4708 | } else { |
| 4709 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4710 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 4711 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 4712 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 4713 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4714 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4715 | CXXCtorInitializer *BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4716 | if (IsBaseInitializer) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4717 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 4718 | LParenLoc, Init, RParenLoc, |
| 4719 | MemberOrEllipsisLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4720 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4721 | if (Member) |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4722 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 4723 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4724 | else |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4725 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 4726 | MemberOrEllipsisLoc, LParenLoc, |
| 4727 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4728 | } else { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4729 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 4730 | LParenLoc, Init, RParenLoc, |
| 4731 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4732 | } |
| 4733 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 4734 | if (IsWritten) |
| 4735 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4736 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4737 | } |
| 4738 | } |
| 4739 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4740 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4741 | } |
| 4742 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4743 | NestedNameSpecifier * |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4744 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4745 | unsigned N = Record[Idx++]; |
| 4746 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 4747 | for (unsigned I = 0; I != N; ++I) { |
| 4748 | NestedNameSpecifier::SpecifierKind Kind |
| 4749 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4750 | switch (Kind) { |
| 4751 | case NestedNameSpecifier::Identifier: { |
| 4752 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 4753 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 4754 | break; |
| 4755 | } |
| 4756 | |
| 4757 | case NestedNameSpecifier::Namespace: { |
| 4758 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 4759 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 4760 | break; |
| 4761 | } |
| 4762 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 4763 | case NestedNameSpecifier::NamespaceAlias: { |
| 4764 | NamespaceAliasDecl *Alias |
| 4765 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
| 4766 | NNS = NestedNameSpecifier::Create(*Context, Prev, Alias); |
| 4767 | break; |
| 4768 | } |
| 4769 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4770 | case NestedNameSpecifier::TypeSpec: |
| 4771 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4772 | const Type *T = GetType(Record[Idx++]).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 4773 | if (!T) |
| 4774 | return 0; |
| 4775 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4776 | bool Template = Record[Idx++]; |
| 4777 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 4778 | break; |
| 4779 | } |
| 4780 | |
| 4781 | case NestedNameSpecifier::Global: { |
| 4782 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4783 | // No associated value, and there can't be a prefix. |
| 4784 | break; |
| 4785 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4786 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 4787 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4788 | } |
| 4789 | return NNS; |
| 4790 | } |
| 4791 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4792 | NestedNameSpecifierLoc |
| 4793 | ASTReader::ReadNestedNameSpecifierLoc(PerFileData &F, const RecordData &Record, |
| 4794 | unsigned &Idx) { |
| 4795 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4796 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4797 | for (unsigned I = 0; I != N; ++I) { |
| 4798 | NestedNameSpecifier::SpecifierKind Kind |
| 4799 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4800 | switch (Kind) { |
| 4801 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4802 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4803 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4804 | Builder.Extend(*Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4805 | break; |
| 4806 | } |
| 4807 | |
| 4808 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4809 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4810 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4811 | Builder.Extend(*Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4812 | break; |
| 4813 | } |
| 4814 | |
| 4815 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4816 | NamespaceAliasDecl *Alias |
| 4817 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4818 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4819 | Builder.Extend(*Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4820 | break; |
| 4821 | } |
| 4822 | |
| 4823 | case NestedNameSpecifier::TypeSpec: |
| 4824 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4825 | bool Template = Record[Idx++]; |
| 4826 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 4827 | if (!T) |
| 4828 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4829 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4830 | |
| 4831 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
| 4832 | Builder.Extend(*Context, |
| 4833 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 4834 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4835 | break; |
| 4836 | } |
| 4837 | |
| 4838 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4839 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4840 | Builder.MakeGlobal(*Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4841 | break; |
| 4842 | } |
| 4843 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4844 | } |
| 4845 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4846 | return Builder.getWithLocInContext(*Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4847 | } |
| 4848 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4849 | SourceRange |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4850 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 4851 | unsigned &Idx) { |
| 4852 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 4853 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 4854 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4855 | } |
| 4856 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4857 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4858 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4859 | unsigned BitWidth = Record[Idx++]; |
| 4860 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 4861 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 4862 | Idx += NumWords; |
| 4863 | return Result; |
| 4864 | } |
| 4865 | |
| 4866 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4867 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4868 | bool isUnsigned = Record[Idx++]; |
| 4869 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 4870 | } |
| 4871 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4872 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4873 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4874 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 4875 | } |
| 4876 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4877 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4878 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4879 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 4880 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4881 | Idx += Len; |
| 4882 | return Result; |
| 4883 | } |
| 4884 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4885 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 4886 | unsigned &Idx) { |
| 4887 | unsigned Major = Record[Idx++]; |
| 4888 | unsigned Minor = Record[Idx++]; |
| 4889 | unsigned Subminor = Record[Idx++]; |
| 4890 | if (Minor == 0) |
| 4891 | return VersionTuple(Major); |
| 4892 | if (Subminor == 0) |
| 4893 | return VersionTuple(Major, Minor - 1); |
| 4894 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 4895 | } |
| 4896 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4897 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4898 | unsigned &Idx) { |
| 4899 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 4900 | return CXXTemporary::Create(*Context, Decl); |
| 4901 | } |
| 4902 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4903 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 4904 | return Diag(SourceLocation(), DiagID); |
| 4905 | } |
| 4906 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4907 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4908 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4909 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4910 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4911 | /// \brief Retrieve the identifier table associated with the |
| 4912 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4913 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4914 | assert(PP && "Forgot to set Preprocessor ?"); |
| 4915 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4918 | /// \brief Record that the given ID maps to the given switch-case |
| 4919 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4920 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4921 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 4922 | SwitchCaseStmts[ID] = SC; |
| 4923 | } |
| 4924 | |
| 4925 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4926 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4927 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 4928 | return SwitchCaseStmts[ID]; |
| 4929 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4930 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4931 | void ASTReader::ClearSwitchCaseIDs() { |
| 4932 | SwitchCaseStmts.clear(); |
| 4933 | } |
| 4934 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4935 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4936 | assert(NumCurrentElementsDeserializing && |
| 4937 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 4938 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4939 | // If any identifiers with corresponding top-level declarations have |
| 4940 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4941 | while (!PendingIdentifierInfos.empty()) { |
| 4942 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 4943 | PendingIdentifierInfos.front().DeclIDs, true); |
| 4944 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4945 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4946 | |
Argyrios Kyrtzidis | 0895d15 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 4947 | // Ready to load previous declarations of Decls that were delayed. |
| 4948 | while (!PendingPreviousDecls.empty()) { |
| 4949 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 4950 | PendingPreviousDecls.front().second); |
| 4951 | PendingPreviousDecls.pop_front(); |
| 4952 | } |
| 4953 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4954 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 4955 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4956 | if (Consumer) |
| 4957 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 4958 | |
| 4959 | assert(PendingForwardRefs.size() == 0 && |
| 4960 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4961 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4962 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4963 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4964 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4965 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4966 | const char *isysroot, bool DisableValidation, |
| 4967 | bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4968 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 4969 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 4970 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
| 4971 | Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4972 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 4973 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), NextSLocOffset(0), |
| 4974 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 4975 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 4976 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 4977 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
| 4978 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 4979 | NumCurrentElementsDeserializing(0) |
| 4980 | { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4981 | RelocatablePCH = false; |
| 4982 | } |
| 4983 | |
| 4984 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 4985 | Diagnostic &Diags, const char *isysroot, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4986 | bool DisableValidation, bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4987 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
| 4988 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4989 | isysroot(isysroot), DisableValidation(DisableValidation), |
| 4990 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 4991 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4992 | NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0), |
| 4993 | NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), |
| 4994 | NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
| 4995 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4996 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4997 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4998 | RelocatablePCH = false; |
| 4999 | } |
| 5000 | |
| 5001 | ASTReader::~ASTReader() { |
| 5002 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 5003 | delete Chain[e - i - 1]; |
| 5004 | // Delete all visible decl lookup tables |
| 5005 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 5006 | E = DeclContextOffsets.end(); |
| 5007 | I != E; ++I) { |
| 5008 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 5009 | J != F; ++J) { |
| 5010 | if (J->NameLookupTableData) |
| 5011 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 5012 | J->NameLookupTableData); |
| 5013 | } |
| 5014 | } |
| 5015 | for (DeclContextVisibleUpdatesPending::iterator |
| 5016 | I = PendingVisibleUpdates.begin(), |
| 5017 | E = PendingVisibleUpdates.end(); |
| 5018 | I != E; ++I) { |
| 5019 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5020 | F = I->second.end(); |
| 5021 | J != F; ++J) |
| 5022 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 5023 | } |
| 5024 | } |
| 5025 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 5026 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
| 5027 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5028 | LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), |
| 5029 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5030 | MacroDefinitionOffsets(0), |
| 5031 | LocalNumHeaderFileInfos(0), HeaderFileInfoTableData(0), |
| 5032 | HeaderFileInfoTable(0), |
| 5033 | LocalNumSelectors(0), SelectorOffsets(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5034 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5035 | DeclOffsets(0), LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
| 5036 | LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 5037 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5038 | {} |
| 5039 | |
| 5040 | ASTReader::PerFileData::~PerFileData() { |
| 5041 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5042 | delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5043 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 5044 | } |