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 | |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 960 | void ASTReader::Error(llvm::StringRef Msg) { |
| 961 | Error(diag::err_fe_pch_malformed, Msg); |
| 962 | } |
| 963 | |
| 964 | void ASTReader::Error(unsigned DiagID, |
| 965 | llvm::StringRef Arg1, llvm::StringRef Arg2) { |
| 966 | if (Diags.isDiagnosticInFlight()) |
| 967 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 968 | else |
| 969 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 972 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 973 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 974 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 975 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 976 | ActualOriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 977 | SuggestedPredefines, |
| 978 | FileMgr); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 979 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 980 | } |
| 981 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 982 | //===----------------------------------------------------------------------===// |
| 983 | // Source Manager Deserialization |
| 984 | //===----------------------------------------------------------------------===// |
| 985 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 986 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 987 | /// \returns true if there was an error. |
| 988 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 989 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 990 | unsigned Idx = 0; |
| 991 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 992 | |
| 993 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 994 | std::map<int, int> FileIDs; |
| 995 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 996 | // Extract the file name |
| 997 | unsigned FilenameLen = Record[Idx++]; |
| 998 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 999 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1000 | MaybeAddSystemRootToFilename(Filename); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1001 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 1002 | Filename.size()); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | // Parse the line entries |
| 1006 | std::vector<LineEntry> Entries; |
| 1007 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1008 | int FID = Record[Idx++]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1009 | |
| 1010 | // Extract the line entries |
| 1011 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1012 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1013 | Entries.clear(); |
| 1014 | Entries.reserve(NumEntries); |
| 1015 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1016 | unsigned FileOffset = Record[Idx++]; |
| 1017 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1018 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1019 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1020 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1021 | unsigned IncludeOffset = Record[Idx++]; |
| 1022 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1023 | FileKind, IncludeOffset)); |
| 1024 | } |
| 1025 | LineTable.AddEntry(FID, Entries); |
| 1026 | } |
| 1027 | |
| 1028 | return false; |
| 1029 | } |
| 1030 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1031 | namespace { |
| 1032 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1033 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1034 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1035 | const ino_t ino; |
| 1036 | const dev_t dev; |
| 1037 | const mode_t mode; |
| 1038 | const time_t mtime; |
| 1039 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1040 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1041 | 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] | 1042 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1043 | }; |
| 1044 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1045 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1046 | public: |
| 1047 | typedef const char *external_key_type; |
| 1048 | typedef const char *internal_key_type; |
| 1049 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1050 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1051 | |
| 1052 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1053 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1057 | |
| 1058 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1059 | return strcmp(a, b) == 0; |
| 1060 | } |
| 1061 | |
| 1062 | static std::pair<unsigned, unsigned> |
| 1063 | ReadKeyDataLength(const unsigned char*& d) { |
| 1064 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1065 | unsigned DataLen = (unsigned) *d++; |
| 1066 | return std::make_pair(KeyLen + 1, DataLen); |
| 1067 | } |
| 1068 | |
| 1069 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1070 | return (const char *)d; |
| 1071 | } |
| 1072 | |
| 1073 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1074 | unsigned /*DataLen*/) { |
| 1075 | using namespace clang::io; |
| 1076 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1077 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1078 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1079 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1080 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1081 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1082 | return data_type(ino, dev, mode, mtime, size); |
| 1083 | } |
| 1084 | }; |
| 1085 | |
| 1086 | /// \brief stat() cache for precompiled headers. |
| 1087 | /// |
| 1088 | /// This cache is very similar to the stat cache used by pretokenized |
| 1089 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1090 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1091 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1092 | CacheTy *Cache; |
| 1093 | |
| 1094 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1095 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1096 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1097 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1098 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1099 | Cache = CacheTy::Create(Buckets, Base); |
| 1100 | } |
| 1101 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1102 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1103 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1104 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1105 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1106 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1107 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1108 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1109 | // 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] | 1110 | if (I == Cache->end()) { |
| 1111 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1112 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1113 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1114 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1115 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1116 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1117 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1118 | StatBuf.st_ino = Data.ino; |
| 1119 | StatBuf.st_dev = Data.dev; |
| 1120 | StatBuf.st_mtime = Data.mtime; |
| 1121 | StatBuf.st_mode = Data.mode; |
| 1122 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1123 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1124 | } |
| 1125 | }; |
| 1126 | } // end anonymous namespace |
| 1127 | |
| 1128 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1129 | /// \brief Read a source manager block |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1130 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1131 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1132 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1133 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1134 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1135 | // Set the source-location entry cursor to the current position in |
| 1136 | // the stream. This cursor will be used to read the contents of the |
| 1137 | // source manager block initially, and then lazily read |
| 1138 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1139 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1140 | |
| 1141 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1142 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1143 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1144 | return Failure; |
| 1145 | } |
| 1146 | |
| 1147 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1148 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1149 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1150 | return Failure; |
| 1151 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1152 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1153 | RecordData Record; |
| 1154 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1155 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1156 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1157 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1158 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1159 | return Failure; |
| 1160 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1161 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1162 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1163 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1164 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1165 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1166 | SLocEntryCursor.ReadSubBlockID(); |
| 1167 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1168 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1169 | return Failure; |
| 1170 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1171 | continue; |
| 1172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1173 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1174 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1175 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1176 | continue; |
| 1177 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1178 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1179 | // Read a record. |
| 1180 | const char *BlobStart; |
| 1181 | unsigned BlobLen; |
| 1182 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1183 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1184 | default: // Default behavior: ignore. |
| 1185 | break; |
| 1186 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1187 | case SM_LINE_TABLE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1188 | if (ParseLineTable(F, Record)) |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1189 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1190 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1191 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1192 | case SM_SLOC_FILE_ENTRY: |
| 1193 | case SM_SLOC_BUFFER_ENTRY: |
| 1194 | case SM_SLOC_INSTANTIATION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1195 | // Once we hit one of the source location entries, we're done. |
| 1196 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1197 | } |
| 1198 | } |
| 1199 | } |
| 1200 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1201 | /// \brief If a header file is not found at the path that we expect it to be |
| 1202 | /// and the PCH file was moved from its original location, try to resolve the |
| 1203 | /// file by assuming that header+PCH were moved together and the header is in |
| 1204 | /// the same place relative to the PCH. |
| 1205 | static std::string |
| 1206 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1207 | const std::string &OriginalDir, |
| 1208 | const std::string &CurrDir) { |
| 1209 | assert(OriginalDir != CurrDir && |
| 1210 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1211 | using namespace llvm::sys; |
| 1212 | llvm::SmallString<128> filePath(Filename); |
| 1213 | fs::make_absolute(filePath); |
| 1214 | assert(path::is_absolute(OriginalDir)); |
| 1215 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1216 | |
| 1217 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1218 | fileDirE = path::end(path::parent_path(filePath)); |
| 1219 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1220 | origDirE = path::end(OriginalDir); |
| 1221 | // Skip the common path components from filePath and OriginalDir. |
| 1222 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1223 | *fileDirI == *origDirI) { |
| 1224 | ++fileDirI; |
| 1225 | ++origDirI; |
| 1226 | } |
| 1227 | for (; origDirI != origDirE; ++origDirI) |
| 1228 | path::append(currPCHPath, ".."); |
| 1229 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1230 | path::append(currPCHPath, path::filename(Filename)); |
| 1231 | return currPCHPath.str(); |
| 1232 | } |
| 1233 | |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1234 | /// \brief Get a cursor that's correctly positioned for reading the source |
| 1235 | /// location entry with the given ID. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1236 | ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1237 | assert(ID != 0 && ID <= TotalNumSLocEntries && |
| 1238 | "SLocCursorForID should only be called for real IDs."); |
| 1239 | |
| 1240 | ID -= 1; |
| 1241 | PerFileData *F = 0; |
| 1242 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1243 | F = Chain[N - I - 1]; |
| 1244 | if (ID < F->LocalNumSLocEntries) |
| 1245 | break; |
| 1246 | ID -= F->LocalNumSLocEntries; |
| 1247 | } |
| 1248 | assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); |
| 1249 | |
| 1250 | F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1251 | return F; |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1254 | /// \brief Read in the source location entry with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1255 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1256 | if (ID == 0) |
| 1257 | return Success; |
| 1258 | |
| 1259 | if (ID > TotalNumSLocEntries) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1260 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1261 | return Failure; |
| 1262 | } |
| 1263 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1264 | PerFileData *F = SLocCursorForID(ID); |
| 1265 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1266 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1267 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1268 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1269 | if (Code == llvm::bitc::END_BLOCK || |
| 1270 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1271 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1272 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1273 | return Failure; |
| 1274 | } |
| 1275 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1276 | RecordData Record; |
| 1277 | const char *BlobStart; |
| 1278 | unsigned BlobLen; |
| 1279 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1280 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1281 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1282 | return Failure; |
| 1283 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1284 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1285 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1286 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1287 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1288 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1289 | OriginalDir != CurrentDir) { |
| 1290 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1291 | OriginalDir, |
| 1292 | CurrentDir); |
| 1293 | if (!resolved.empty()) |
| 1294 | File = FileMgr.getFile(resolved); |
| 1295 | } |
Axel Naumann | 0433116 | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1296 | if (File == 0) |
| 1297 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1298 | (time_t)Record[5]); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1299 | if (File == 0) { |
| 1300 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1301 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1302 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1303 | Error(ErrorStr.c_str()); |
| 1304 | return Failure; |
| 1305 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1306 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1307 | if (Record.size() < 6) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1308 | Error("source location entry is incorrect"); |
| 1309 | return Failure; |
| 1310 | } |
| 1311 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1312 | if (!DisableValidation && |
| 1313 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1314 | #if !defined(LLVM_ON_WIN32) |
| 1315 | // In our regression testing, the Windows file system seems to |
| 1316 | // have inconsistent modification times that sometimes |
| 1317 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1318 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1319 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1320 | )) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1321 | Error(diag::err_fe_pch_file_modified, Filename); |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1322 | return Failure; |
| 1323 | } |
| 1324 | |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1325 | FileID FID = SourceMgr.createFileID(File, ReadSourceLocation(*F, Record[1]), |
| 1326 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1327 | ID, Record[0]); |
| 1328 | if (Record[3]) |
| 1329 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1330 | .setHasLineDirectives(); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1331 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1332 | break; |
| 1333 | } |
| 1334 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1335 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1336 | const char *Name = BlobStart; |
| 1337 | unsigned Offset = Record[0]; |
| 1338 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1339 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1340 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1341 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1342 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1343 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1344 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1345 | return Failure; |
| 1346 | } |
| 1347 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1348 | llvm::MemoryBuffer *Buffer |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1349 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1350 | Name); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1351 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1352 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1353 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1354 | PCHPredefinesBlock Block = { |
| 1355 | BufferID, |
| 1356 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1357 | }; |
| 1358 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1359 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1360 | |
| 1361 | break; |
| 1362 | } |
| 1363 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1364 | case SM_SLOC_INSTANTIATION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1365 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1366 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1367 | ReadSourceLocation(*F, Record[2]), |
| 1368 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1369 | Record[4], |
| 1370 | ID, |
| 1371 | Record[0]); |
| 1372 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1373 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | return Success; |
| 1377 | } |
| 1378 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1379 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1380 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1381 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1382 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1383 | unsigned BlockID) { |
| 1384 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1385 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1386 | return Failure; |
| 1387 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1388 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1389 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1390 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1391 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1392 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1393 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1394 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1395 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1396 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1397 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1398 | Cursor.ReadAbbrevRecord(); |
| 1399 | } |
| 1400 | } |
| 1401 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1402 | PreprocessedEntity *ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1403 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1404 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1405 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1406 | // Keep track of where we are in the stream, then jump back there |
| 1407 | // after reading this macro. |
| 1408 | SavedStreamPosition SavedPosition(Stream); |
| 1409 | |
| 1410 | Stream.JumpToBit(Offset); |
| 1411 | RecordData Record; |
| 1412 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1413 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1414 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1415 | while (true) { |
| 1416 | unsigned Code = Stream.ReadCode(); |
| 1417 | switch (Code) { |
| 1418 | case llvm::bitc::END_BLOCK: |
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 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1422 | // No known subblocks, always skip them. |
| 1423 | Stream.ReadSubBlockID(); |
| 1424 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1425 | Error("malformed block record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1426 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1427 | } |
| 1428 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1429 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1430 | case llvm::bitc::DEFINE_ABBREV: |
| 1431 | Stream.ReadAbbrevRecord(); |
| 1432 | continue; |
| 1433 | default: break; |
| 1434 | } |
| 1435 | |
| 1436 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1437 | const char *BlobStart = 0; |
| 1438 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1439 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1440 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1441 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1442 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1443 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1444 | case PP_MACRO_OBJECT_LIKE: |
| 1445 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1446 | // If we already have a macro, that means that we've hit the end |
| 1447 | // of the definition of the macro we were looking for. We're |
| 1448 | // done. |
| 1449 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1450 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1451 | |
| 1452 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1453 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1454 | Error("macro must have a name in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1455 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1456 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1457 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1458 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1459 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1460 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1461 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1462 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1463 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1464 | unsigned NextIndex = 3; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1465 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1466 | // Decode function-like macro info. |
| 1467 | bool isC99VarArgs = Record[3]; |
| 1468 | bool isGNUVarArgs = Record[4]; |
| 1469 | MacroArgs.clear(); |
| 1470 | unsigned NumArgs = Record[5]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1471 | NextIndex = 6 + NumArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1472 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1473 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1474 | |
| 1475 | // Install function-like macro info. |
| 1476 | MI->setIsFunctionLike(); |
| 1477 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1478 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1479 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1480 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1484 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1485 | |
| 1486 | // Remember that we saw this macro last so that we add the tokens that |
| 1487 | // form its body to it. |
| 1488 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1489 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1490 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1491 | // We have a macro definition. Load it now. |
| 1492 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1493 | getMacroDefinition(Record[NextIndex])); |
| 1494 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1495 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1496 | ++NumMacrosRead; |
| 1497 | break; |
| 1498 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1499 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1500 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1501 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1502 | // erroneous, just pretend we didn't see this. |
| 1503 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1504 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1505 | Token Tok; |
| 1506 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1507 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1508 | Tok.setLength(Record[1]); |
| 1509 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1510 | Tok.setIdentifierInfo(II); |
| 1511 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1512 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1513 | Macro->AddTokenToBody(Tok); |
| 1514 | break; |
| 1515 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1516 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1517 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1518 | |
| 1519 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1522 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(PerFileData &F) { |
| 1523 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1524 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1525 | switch (Code) { |
| 1526 | case llvm::bitc::END_BLOCK: |
| 1527 | return 0; |
| 1528 | |
| 1529 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1530 | Error("unexpected subblock record in preprocessor detail block"); |
| 1531 | return 0; |
| 1532 | |
| 1533 | case llvm::bitc::DEFINE_ABBREV: |
| 1534 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1535 | return 0; |
| 1536 | |
| 1537 | default: |
| 1538 | break; |
| 1539 | } |
| 1540 | |
| 1541 | if (!PP->getPreprocessingRecord()) { |
| 1542 | Error("no preprocessing record"); |
| 1543 | return 0; |
| 1544 | } |
| 1545 | |
| 1546 | // Read the record. |
| 1547 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1548 | const char *BlobStart = 0; |
| 1549 | unsigned BlobLen = 0; |
| 1550 | RecordData Record; |
| 1551 | PreprocessorDetailRecordTypes RecType = |
| 1552 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1553 | Code, Record, BlobStart, BlobLen); |
| 1554 | switch (RecType) { |
| 1555 | case PPD_MACRO_INSTANTIATION: { |
| 1556 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1557 | return PE; |
| 1558 | |
| 1559 | MacroInstantiation *MI |
| 1560 | = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), |
| 1561 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1562 | ReadSourceLocation(F, Record[2])), |
| 1563 | getMacroDefinition(Record[4])); |
| 1564 | PPRec.SetPreallocatedEntity(Record[0], MI); |
| 1565 | return MI; |
| 1566 | } |
| 1567 | |
| 1568 | case PPD_MACRO_DEFINITION: { |
| 1569 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1570 | return PE; |
| 1571 | |
| 1572 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
| 1573 | Error("out-of-bounds macro definition record"); |
| 1574 | return 0; |
| 1575 | } |
| 1576 | |
| 1577 | // Decode the identifier info and then check again; if the macro is |
| 1578 | // still defined and associated with the identifier, |
| 1579 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1580 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1581 | MacroDefinition *MD |
| 1582 | = new (PPRec) MacroDefinition(II, |
| 1583 | ReadSourceLocation(F, Record[5]), |
| 1584 | SourceRange( |
| 1585 | ReadSourceLocation(F, Record[2]), |
| 1586 | ReadSourceLocation(F, Record[3]))); |
| 1587 | |
| 1588 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1589 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
| 1590 | |
| 1591 | if (DeserializationListener) |
| 1592 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1593 | } |
| 1594 | |
| 1595 | return MacroDefinitionsLoaded[Record[1] - 1]; |
| 1596 | } |
| 1597 | |
| 1598 | case PPD_INCLUSION_DIRECTIVE: { |
| 1599 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1600 | return PE; |
| 1601 | |
| 1602 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1603 | const FileEntry *File |
| 1604 | = PP->getFileManager().getFile(llvm::StringRef(FullFileNameStart, |
| 1605 | BlobLen - Record[3])); |
| 1606 | |
| 1607 | // FIXME: Stable encoding |
| 1608 | InclusionDirective::InclusionKind Kind |
| 1609 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1610 | InclusionDirective *ID |
| 1611 | = new (PPRec) InclusionDirective(PPRec, Kind, |
| 1612 | llvm::StringRef(BlobStart, Record[3]), |
| 1613 | Record[4], |
| 1614 | File, |
| 1615 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1616 | ReadSourceLocation(F, Record[2]))); |
| 1617 | PPRec.SetPreallocatedEntity(Record[0], ID); |
| 1618 | return ID; |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | Error("invalid offset in preprocessor detail block"); |
| 1623 | return 0; |
| 1624 | } |
| 1625 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1626 | namespace { |
| 1627 | /// \brief Trait class used to search the on-disk hash table containing all of |
| 1628 | /// the header search information. |
| 1629 | /// |
| 1630 | /// The on-disk hash table contains a mapping from each header path to |
| 1631 | /// information about that header (how many times it has been included, its |
| 1632 | /// controlling macro, etc.). Note that we actually hash based on the |
| 1633 | /// filename, and support "deep" comparisons of file names based on current |
| 1634 | /// inode numbers, so that the search can cope with non-normalized path names |
| 1635 | /// and symlinks. |
| 1636 | class HeaderFileInfoTrait { |
| 1637 | const char *SearchPath; |
| 1638 | struct stat SearchPathStatBuf; |
| 1639 | llvm::Optional<int> SearchPathStatResult; |
| 1640 | |
| 1641 | int StatSimpleCache(const char *Path, struct stat *StatBuf) { |
| 1642 | if (Path == SearchPath) { |
| 1643 | if (!SearchPathStatResult) |
| 1644 | SearchPathStatResult = stat(Path, &SearchPathStatBuf); |
| 1645 | |
| 1646 | *StatBuf = SearchPathStatBuf; |
| 1647 | return *SearchPathStatResult; |
| 1648 | } |
| 1649 | |
| 1650 | return stat(Path, StatBuf); |
| 1651 | } |
| 1652 | |
| 1653 | public: |
| 1654 | typedef const char *external_key_type; |
| 1655 | typedef const char *internal_key_type; |
| 1656 | |
| 1657 | typedef HeaderFileInfo data_type; |
| 1658 | |
| 1659 | HeaderFileInfoTrait(const char *SearchPath = 0) : SearchPath(SearchPath) { } |
| 1660 | |
| 1661 | static unsigned ComputeHash(const char *path) { |
| 1662 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1663 | } |
| 1664 | |
| 1665 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1666 | |
| 1667 | bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1668 | if (strcmp(a, b) == 0) |
| 1669 | return true; |
| 1670 | |
| 1671 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1672 | return false; |
| 1673 | |
| 1674 | // The file names match, but the path names don't. stat() the files to |
| 1675 | // see if they are the same. |
| 1676 | struct stat StatBufA, StatBufB; |
| 1677 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1678 | return false; |
| 1679 | |
| 1680 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1681 | } |
| 1682 | |
| 1683 | static std::pair<unsigned, unsigned> |
| 1684 | ReadKeyDataLength(const unsigned char*& d) { |
| 1685 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1686 | unsigned DataLen = (unsigned) *d++; |
| 1687 | return std::make_pair(KeyLen + 1, DataLen); |
| 1688 | } |
| 1689 | |
| 1690 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1691 | return (const char *)d; |
| 1692 | } |
| 1693 | |
| 1694 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1695 | unsigned DataLen) { |
| 1696 | const unsigned char *End = d + DataLen; |
| 1697 | using namespace clang::io; |
| 1698 | HeaderFileInfo HFI; |
| 1699 | unsigned Flags = *d++; |
| 1700 | HFI.isImport = (Flags >> 3) & 0x01; |
| 1701 | HFI.DirInfo = (Flags >> 1) & 0x03; |
| 1702 | HFI.Resolved = Flags & 0x01; |
| 1703 | HFI.NumIncludes = ReadUnalignedLE16(d); |
| 1704 | HFI.ControllingMacroID = ReadUnalignedLE32(d); |
| 1705 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1706 | (void)End; |
| 1707 | |
| 1708 | // This HeaderFileInfo was externally loaded. |
| 1709 | HFI.External = true; |
| 1710 | return HFI; |
| 1711 | } |
| 1712 | }; |
| 1713 | } |
| 1714 | |
| 1715 | /// \brief The on-disk hash table used for the global method pool. |
| 1716 | typedef OnDiskChainedHashTable<HeaderFileInfoTrait> |
| 1717 | HeaderFileInfoLookupTable; |
| 1718 | |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1719 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F, |
| 1720 | uint64_t Offset) { |
| 1721 | // Note that this identifier has a macro definition. |
| 1722 | II->setHasMacroDefinition(true); |
| 1723 | |
| 1724 | // Adjust the offset based on our position in the chain. |
| 1725 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1726 | if (Chain[I] == &F) |
| 1727 | break; |
| 1728 | |
| 1729 | Offset += Chain[I]->SizeInBits; |
| 1730 | } |
| 1731 | |
| 1732 | UnreadMacroRecordOffsets[II] = Offset; |
| 1733 | } |
| 1734 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1735 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1736 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1737 | PerFileData &F = *Chain[N - I - 1]; |
| 1738 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1739 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1740 | // If there was no preprocessor block, skip this file. |
| 1741 | if (!MacroCursor.getBitStreamReader()) |
| 1742 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1743 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1744 | llvm::BitstreamCursor Cursor = MacroCursor; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1745 | Cursor.JumpToBit(F.MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1746 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1747 | RecordData Record; |
| 1748 | while (true) { |
| 1749 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1750 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1751 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1752 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1753 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1754 | // No known subblocks, always skip them. |
| 1755 | Cursor.ReadSubBlockID(); |
| 1756 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1757 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1758 | return; |
| 1759 | } |
| 1760 | continue; |
| 1761 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1762 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1763 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1764 | Cursor.ReadAbbrevRecord(); |
| 1765 | continue; |
| 1766 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1767 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1768 | // Read a record. |
| 1769 | const char *BlobStart; |
| 1770 | unsigned BlobLen; |
| 1771 | Record.clear(); |
| 1772 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1773 | default: // Default behavior: ignore. |
| 1774 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1775 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1776 | case PP_MACRO_OBJECT_LIKE: |
| 1777 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1778 | DecodeIdentifierInfo(Record[0]); |
| 1779 | break; |
| 1780 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1781 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1782 | // Ignore tokens. |
| 1783 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1784 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1785 | } |
| 1786 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1787 | |
| 1788 | // Drain the unread macro-record offsets map. |
| 1789 | while (!UnreadMacroRecordOffsets.empty()) |
| 1790 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1791 | } |
| 1792 | |
| 1793 | void ASTReader::LoadMacroDefinition( |
| 1794 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1795 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
| 1796 | PerFileData *F = 0; |
| 1797 | uint64_t Offset = Pos->second; |
| 1798 | UnreadMacroRecordOffsets.erase(Pos); |
| 1799 | |
| 1800 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1801 | if (Offset < Chain[I]->SizeInBits) { |
| 1802 | F = Chain[I]; |
| 1803 | break; |
| 1804 | } |
| 1805 | |
| 1806 | Offset -= Chain[I]->SizeInBits; |
| 1807 | } |
| 1808 | if (!F) { |
| 1809 | Error("Malformed macro record offset"); |
| 1810 | return; |
| 1811 | } |
| 1812 | |
| 1813 | ReadMacroRecord(*F, Offset); |
| 1814 | } |
| 1815 | |
| 1816 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1817 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1818 | = UnreadMacroRecordOffsets.find(II); |
| 1819 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1820 | } |
| 1821 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1822 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1823 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1824 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1825 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1826 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1827 | unsigned Index = ID - 1; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1828 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1829 | PerFileData &F = *Chain[N - I - 1]; |
| 1830 | if (Index < F.LocalNumMacroDefinitions) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1831 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 1832 | F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]); |
| 1833 | LoadPreprocessedEntity(F); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1834 | break; |
| 1835 | } |
| 1836 | Index -= F.LocalNumMacroDefinitions; |
| 1837 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1838 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1841 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1844 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1845 | /// not an absolute path, add the system root to the beginning of the file |
| 1846 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1847 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1848 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1849 | if (!RelocatablePCH) |
| 1850 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1851 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1852 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1853 | return; |
| 1854 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1855 | if (isysroot == 0) { |
| 1856 | // If no system root was given, default to '/' |
| 1857 | Filename.insert(Filename.begin(), '/'); |
| 1858 | return; |
| 1859 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1860 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1861 | unsigned Length = strlen(isysroot); |
| 1862 | if (isysroot[Length - 1] != '/') |
| 1863 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1864 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1865 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1866 | } |
| 1867 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1868 | ASTReader::ASTReadResult |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1869 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1870 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1871 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1872 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1873 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1874 | return Failure; |
| 1875 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1876 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1877 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1878 | RecordData Record; |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1879 | bool First = true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1880 | while (!Stream.AtEndOfStream()) { |
| 1881 | unsigned Code = Stream.ReadCode(); |
| 1882 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1883 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1884 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1885 | return Failure; |
| 1886 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1887 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1888 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1892 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1893 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1894 | // We lazily load the decls block, but we want to set up the |
| 1895 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1896 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1897 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1898 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1899 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1900 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1901 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1902 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1903 | return Failure; |
| 1904 | } |
| 1905 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1906 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1907 | case DECL_UPDATES_BLOCK_ID: |
| 1908 | if (Stream.SkipBlock()) { |
| 1909 | Error("malformed block record in AST file"); |
| 1910 | return Failure; |
| 1911 | } |
| 1912 | break; |
| 1913 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1914 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1915 | F.MacroCursor = Stream; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1916 | if (PP) |
| 1917 | PP->setExternalSource(this); |
| 1918 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1919 | if (Stream.SkipBlock() || |
| 1920 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1921 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1922 | return Failure; |
| 1923 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1924 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1925 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1926 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1927 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1928 | F.PreprocessorDetailCursor = Stream; |
| 1929 | if (Stream.SkipBlock() || |
| 1930 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1931 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1932 | Error("malformed preprocessor detail record in AST file"); |
| 1933 | return Failure; |
| 1934 | } |
| 1935 | F.PreprocessorDetailStartOffset |
| 1936 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 1937 | break; |
| 1938 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1939 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1940 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1941 | case Success: |
| 1942 | break; |
| 1943 | |
| 1944 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1945 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1946 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1947 | |
| 1948 | case IgnorePCH: |
| 1949 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1950 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1951 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1952 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1953 | First = false; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1954 | continue; |
| 1955 | } |
| 1956 | |
| 1957 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1958 | Stream.ReadAbbrevRecord(); |
| 1959 | continue; |
| 1960 | } |
| 1961 | |
| 1962 | // Read and process a record. |
| 1963 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1964 | const char *BlobStart = 0; |
| 1965 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1966 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1967 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1968 | default: // Default behavior: ignore. |
| 1969 | break; |
| 1970 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1971 | case METADATA: { |
| 1972 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1973 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1974 | : diag::warn_pch_version_too_new); |
| 1975 | return IgnorePCH; |
| 1976 | } |
| 1977 | |
| 1978 | RelocatablePCH = Record[4]; |
| 1979 | if (Listener) { |
| 1980 | std::string TargetTriple(BlobStart, BlobLen); |
| 1981 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1982 | return IgnorePCH; |
| 1983 | } |
| 1984 | break; |
| 1985 | } |
| 1986 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1987 | case CHAINED_METADATA: { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1988 | if (!First) { |
| 1989 | Error("CHAINED_METADATA is not first record in block"); |
| 1990 | return Failure; |
| 1991 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1992 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1993 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1994 | : diag::warn_pch_version_too_new); |
| 1995 | return IgnorePCH; |
| 1996 | } |
| 1997 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 1998 | // Load the chained file, which is always a PCH file. |
| 1999 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2000 | case Failure: return Failure; |
| 2001 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 2002 | case IgnorePCH: return IgnorePCH; |
| 2003 | case Success: break; |
| 2004 | } |
| 2005 | break; |
| 2006 | } |
| 2007 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2008 | case TYPE_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2009 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2010 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2011 | return Failure; |
| 2012 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2013 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 2014 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2015 | break; |
| 2016 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2017 | case DECL_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2018 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2019 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2020 | return Failure; |
| 2021 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2022 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 2023 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2024 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2025 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2026 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2027 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2028 | /* No visible information */ 0, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2029 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 2030 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2031 | }; |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2032 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 2033 | .push_back(Info); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2034 | break; |
| 2035 | } |
| 2036 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2037 | case UPDATE_VISIBLE: { |
| 2038 | serialization::DeclID ID = Record[0]; |
| 2039 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 2040 | (const unsigned char *)BlobStart + Record[1], |
| 2041 | (const unsigned char *)BlobStart, |
| 2042 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2043 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2044 | DeclContextInfo Info = { |
| 2045 | Table, /* No lexical inforamtion */ 0, 0 |
| 2046 | }; |
| 2047 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 2048 | } else |
| 2049 | PendingVisibleUpdates[ID].push_back(Table); |
| 2050 | break; |
| 2051 | } |
| 2052 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2053 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2054 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 2055 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2056 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2057 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 2058 | Latest > FirstLatestDeclIDs[First]) && |
| 2059 | "The new latest is supposed to come after the previous latest"); |
| 2060 | FirstLatestDeclIDs[First] = Latest; |
| 2061 | } |
| 2062 | break; |
| 2063 | } |
| 2064 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2065 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2066 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2067 | return IgnorePCH; |
| 2068 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2069 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2070 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2071 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2072 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2073 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2074 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2075 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2076 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2077 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2078 | if (PP) |
| 2079 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2080 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2081 | break; |
| 2082 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2083 | case IDENTIFIER_OFFSET: |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2084 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2085 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2086 | return Failure; |
| 2087 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2088 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2089 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2090 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2091 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2092 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2093 | // Optimization for the first block. |
| 2094 | if (ExternalDefinitions.empty()) |
| 2095 | ExternalDefinitions.swap(Record); |
| 2096 | else |
| 2097 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 2098 | Record.begin(), Record.end()); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2099 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2100 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2101 | case SPECIAL_TYPES: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2102 | // Optimization for the first block |
| 2103 | if (SpecialTypes.empty()) |
| 2104 | SpecialTypes.swap(Record); |
| 2105 | else |
| 2106 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2107 | break; |
| 2108 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2109 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2110 | TotalNumStatements += Record[0]; |
| 2111 | TotalNumMacros += Record[1]; |
| 2112 | TotalLexicalDeclContexts += Record[2]; |
| 2113 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2114 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2115 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2116 | case TENTATIVE_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2117 | // Optimization for the first block. |
| 2118 | if (TentativeDefinitions.empty()) |
| 2119 | TentativeDefinitions.swap(Record); |
| 2120 | else |
| 2121 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 2122 | Record.begin(), Record.end()); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2123 | break; |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2124 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2125 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2126 | // Optimization for the first block. |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2127 | if (UnusedFileScopedDecls.empty()) |
| 2128 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2129 | else |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2130 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 2131 | Record.begin(), Record.end()); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2132 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2133 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2134 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2135 | // Later blocks overwrite earlier ones. |
| 2136 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2137 | break; |
| 2138 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2139 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2140 | // Optimization for the first block. |
| 2141 | if (LocallyScopedExternalDecls.empty()) |
| 2142 | LocallyScopedExternalDecls.swap(Record); |
| 2143 | else |
| 2144 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 2145 | Record.begin(), Record.end()); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2146 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2147 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2148 | case SELECTOR_OFFSETS: |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2149 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2150 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2151 | break; |
| 2152 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2153 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2154 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2155 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2156 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2157 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2158 | F.SelectorLookupTableData + Record[0], |
| 2159 | F.SelectorLookupTableData, |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2160 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2161 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2162 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2163 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2164 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2165 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2166 | break; |
| 2167 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2168 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2169 | if (!Record.empty() && Listener) |
| 2170 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2171 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2172 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2173 | case SOURCE_LOCATION_OFFSETS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2174 | F.SLocOffsets = (const uint32_t *)BlobStart; |
| 2175 | F.LocalNumSLocEntries = Record[0]; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2176 | F.LocalSLocSize = Record[1]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2177 | break; |
| 2178 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2179 | case SOURCE_LOCATION_PRELOADS: |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2180 | if (PreloadSLocEntries.empty()) |
| 2181 | PreloadSLocEntries.swap(Record); |
| 2182 | else |
| 2183 | PreloadSLocEntries.insert(PreloadSLocEntries.end(), |
| 2184 | Record.begin(), Record.end()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2185 | break; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2186 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2187 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2188 | if (!DisableStatCache) { |
| 2189 | ASTStatCache *MyStatCache = |
| 2190 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2191 | (const unsigned char *)BlobStart, |
| 2192 | NumStatHits, NumStatMisses); |
| 2193 | FileMgr.addStatCache(MyStatCache); |
| 2194 | F.StatCache = MyStatCache; |
| 2195 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2196 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2197 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2198 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2199 | case EXT_VECTOR_DECLS: |
Sebastian Redl | a9f2368 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 2200 | // Optimization for the first block. |
| 2201 | if (ExtVectorDecls.empty()) |
| 2202 | ExtVectorDecls.swap(Record); |
| 2203 | else |
| 2204 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 2205 | Record.begin(), Record.end()); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2206 | break; |
| 2207 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2208 | case VTABLE_USES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2209 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2210 | VTableUses.swap(Record); |
| 2211 | break; |
| 2212 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2213 | case DYNAMIC_CLASSES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2214 | // Optimization for the first block. |
| 2215 | if (DynamicClasses.empty()) |
| 2216 | DynamicClasses.swap(Record); |
| 2217 | else |
| 2218 | DynamicClasses.insert(DynamicClasses.end(), |
| 2219 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2220 | break; |
| 2221 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2222 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2223 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2224 | break; |
| 2225 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2226 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2227 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2228 | SemaDeclRefs.swap(Record); |
| 2229 | break; |
| 2230 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2231 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2232 | // 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] | 2233 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2234 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2235 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2236 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2237 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2238 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2239 | case ORIGINAL_PCH_DIR: |
| 2240 | // The primary AST will be the last to get here, so it will be the one |
| 2241 | // that's used. |
| 2242 | OriginalDir.assign(BlobStart, BlobLen); |
| 2243 | break; |
| 2244 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2245 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2246 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2247 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 2248 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2249 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2250 | return IgnorePCH; |
| 2251 | } |
| 2252 | break; |
| 2253 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2254 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2255 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2256 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2257 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2258 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2259 | break; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2260 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2261 | case DECL_UPDATE_OFFSETS: { |
| 2262 | if (Record.size() % 2 != 0) { |
| 2263 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2264 | return Failure; |
| 2265 | } |
| 2266 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
| 2267 | DeclUpdateOffsets[static_cast<DeclID>(Record[I])] |
| 2268 | .push_back(std::make_pair(&F, Record[I+1])); |
| 2269 | break; |
| 2270 | } |
| 2271 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2272 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2273 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2274 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2275 | return Failure; |
| 2276 | } |
| 2277 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2278 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2279 | std::make_pair(&F, Record[I+1]); |
| 2280 | break; |
| 2281 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2282 | |
| 2283 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2284 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2285 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2286 | return Failure; |
| 2287 | } |
| 2288 | |
| 2289 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2290 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
| 2291 | break; |
| 2292 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2293 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2294 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2295 | if (Record.size() % 2 != 0) { |
| 2296 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2297 | return Failure; |
| 2298 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2299 | if (PragmaDiagMappings.empty()) |
| 2300 | PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2301 | else |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2302 | PragmaDiagMappings.insert(PragmaDiagMappings.end(), |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2303 | Record.begin(), Record.end()); |
| 2304 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2305 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2306 | case CUDA_SPECIAL_DECL_REFS: |
| 2307 | // Later tables overwrite earlier ones. |
| 2308 | CUDASpecialDeclRefs.swap(Record); |
| 2309 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2310 | |
| 2311 | case HEADER_SEARCH_TABLE: |
| 2312 | F.HeaderFileInfoTableData = BlobStart; |
| 2313 | F.LocalNumHeaderFileInfos = Record[1]; |
| 2314 | if (Record[0]) { |
| 2315 | F.HeaderFileInfoTable |
| 2316 | = HeaderFileInfoLookupTable::Create( |
| 2317 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 2318 | (const unsigned char *)F.HeaderFileInfoTableData); |
| 2319 | if (PP) |
| 2320 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2321 | } |
| 2322 | break; |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2323 | |
| 2324 | case FP_PRAGMA_OPTIONS: |
| 2325 | // Later tables overwrite earlier ones. |
| 2326 | FPPragmaOptions.swap(Record); |
| 2327 | break; |
| 2328 | |
| 2329 | case OPENCL_EXTENSIONS: |
| 2330 | // Later tables overwrite earlier ones. |
| 2331 | OpenCLExtensions.swap(Record); |
| 2332 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2333 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2334 | First = false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2335 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2336 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2337 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2338 | } |
| 2339 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2340 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2341 | ASTFileType Type) { |
| 2342 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2343 | case Failure: return Failure; |
| 2344 | case IgnorePCH: return IgnorePCH; |
| 2345 | case Success: break; |
| 2346 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2347 | |
| 2348 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2349 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2350 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2351 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2352 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2353 | TotalNumSelectors = 0; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2354 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2355 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2356 | NextSLocOffset += Chain[I]->LocalSLocSize; |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2357 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2358 | TotalNumTypes += Chain[I]->LocalNumTypes; |
| 2359 | TotalNumDecls += Chain[I]->LocalNumDecls; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2360 | TotalNumPreallocatedPreprocessingEntities += |
| 2361 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2362 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2363 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2364 | } |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2365 | SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset); |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2366 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2367 | TypesLoaded.resize(TotalNumTypes); |
| 2368 | DeclsLoaded.resize(TotalNumDecls); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2369 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2370 | if (PP) { |
| 2371 | if (TotalNumIdentifiers > 0) |
| 2372 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2373 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2374 | if (!PP->getPreprocessingRecord()) |
| 2375 | PP->createPreprocessingRecord(); |
| 2376 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2377 | TotalNumPreallocatedPreprocessingEntities); |
| 2378 | } |
| 2379 | } |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2380 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2381 | // Preload SLocEntries. |
| 2382 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2383 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2384 | if (Result != Success) |
| 2385 | return Result; |
| 2386 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2387 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2388 | // Check the predefines buffers. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2389 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2390 | return IgnorePCH; |
| 2391 | |
| 2392 | if (PP) { |
| 2393 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2394 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2395 | // loaded into the IdentifierTable before we intercepted the |
| 2396 | // creation of identifiers. Iterate through the list of known |
| 2397 | // identifiers and determine whether we have to establish |
| 2398 | // preprocessor definitions or top-level identifier declaration |
| 2399 | // chains for those identifiers. |
| 2400 | // |
| 2401 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2402 | // since de-serializing declarations or macro definitions can add |
| 2403 | // new entries into the identifier table, invalidating the |
| 2404 | // iterators. |
| 2405 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2406 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2407 | IdEnd = PP->getIdentifierTable().end(); |
| 2408 | Id != IdEnd; ++Id) |
| 2409 | Identifiers.push_back(Id->second); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2410 | // We need to search the tables in all files. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2411 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2412 | ASTIdentifierLookupTable *IdTable |
| 2413 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2414 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2415 | // ones. |
| 2416 | if (!IdTable) |
| 2417 | continue; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2418 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2419 | IdentifierInfo *II = Identifiers[I]; |
| 2420 | // 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] | 2421 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2422 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2423 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2424 | if (Pos == IdTable->end()) |
| 2425 | continue; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2426 | |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2427 | // Dereferencing the iterator has the effect of populating the |
| 2428 | // IdentifierInfo node with the various declarations it needs. |
| 2429 | (void)*Pos; |
| 2430 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | |
| 2434 | if (Context) |
| 2435 | InitializeContext(*Context); |
| 2436 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2437 | if (DeserializationListener) |
| 2438 | DeserializationListener->ReaderInitialized(this); |
| 2439 | |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2440 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2441 | // the source manager to the file source file from which the preamble was |
| 2442 | // built. This is the only valid way to use a precompiled preamble. |
| 2443 | if (Type == Preamble) { |
| 2444 | SourceLocation Loc |
| 2445 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2446 | if (Loc.isValid()) { |
| 2447 | std::pair<FileID, unsigned> Decomposed = SourceMgr.getDecomposedLoc(Loc); |
| 2448 | SourceMgr.SetPreambleFileID(Decomposed.first); |
| 2449 | } |
| 2450 | } |
| 2451 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2452 | return Success; |
| 2453 | } |
| 2454 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2455 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2456 | ASTFileType Type) { |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2457 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2458 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2459 | PerFileData &F = *Chain.back(); |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2460 | if (Prev) |
| 2461 | Prev->NextInSource = &F; |
| 2462 | else |
| 2463 | FirstInSource = &F; |
| 2464 | F.Loaders.push_back(Prev); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2465 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2466 | // Set the AST file name. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2467 | F.FileName = FileName; |
| 2468 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2469 | if (FileName != "-") { |
| 2470 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2471 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2472 | } |
| 2473 | |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 2474 | if (!ASTBuffers.empty()) { |
Sebastian Redl | 5655837 | 2011-04-14 14:07:41 +0000 | [diff] [blame] | 2475 | F.Buffer.reset(ASTBuffers.back()); |
| 2476 | ASTBuffers.pop_back(); |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 2477 | assert(F.Buffer && "Passed null buffer"); |
| 2478 | } else { |
| 2479 | // Open the AST file. |
| 2480 | // |
| 2481 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2482 | std::string ErrStr; |
| 2483 | llvm::error_code ec; |
| 2484 | if (FileName == "-") { |
| 2485 | ec = llvm::MemoryBuffer::getSTDIN(F.Buffer); |
| 2486 | if (ec) |
| 2487 | ErrStr = ec.message(); |
| 2488 | } else |
| 2489 | F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr)); |
| 2490 | if (!F.Buffer) { |
| 2491 | Error(ErrStr.c_str()); |
| 2492 | return IgnorePCH; |
| 2493 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | // Initialize the stream |
| 2497 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2498 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2499 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2500 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2501 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2502 | |
| 2503 | // Sniff for the signature. |
| 2504 | if (Stream.Read(8) != 'C' || |
| 2505 | Stream.Read(8) != 'P' || |
| 2506 | Stream.Read(8) != 'C' || |
| 2507 | Stream.Read(8) != 'H') { |
| 2508 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2509 | return Failure; |
| 2510 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2511 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2512 | while (!Stream.AtEndOfStream()) { |
| 2513 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2514 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2515 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2516 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2517 | return Failure; |
| 2518 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2519 | |
| 2520 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2521 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2522 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2523 | switch (BlockID) { |
| 2524 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2525 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2526 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2527 | return Failure; |
| 2528 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2529 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2530 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2531 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2532 | case Success: |
| 2533 | break; |
| 2534 | |
| 2535 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2536 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2537 | |
| 2538 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2539 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2540 | // AST block, skipping subblocks, to see if there are other |
| 2541 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2542 | |
| 2543 | // Clear out any preallocated source location entries, so that |
| 2544 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2545 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2546 | |
| 2547 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2548 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2549 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2550 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2551 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2552 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2553 | break; |
| 2554 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2555 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2556 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2557 | return Failure; |
| 2558 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2559 | break; |
| 2560 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2561 | } |
| 2562 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2563 | return Success; |
| 2564 | } |
| 2565 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2566 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2567 | PP = &pp; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2568 | |
| 2569 | unsigned TotalNum = 0; |
| 2570 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2571 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2572 | if (TotalNum) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2573 | if (!PP->getPreprocessingRecord()) |
| 2574 | PP->createPreprocessingRecord(); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2575 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2576 | } |
| 2577 | } |
| 2578 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2579 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2580 | Context = &Ctx; |
| 2581 | assert(Context && "Passed null context!"); |
| 2582 | |
| 2583 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2584 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2585 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2586 | PP->setExternalSource(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2587 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2588 | |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2589 | // If we have an update block for the TU waiting, we have to add it before |
| 2590 | // deserializing the decl. |
| 2591 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2592 | if (DCU != DeclContextOffsets.end()) { |
| 2593 | // Insertion could invalidate map, so grab vector. |
| 2594 | DeclContextInfos T; |
| 2595 | T.swap(DCU->second); |
| 2596 | DeclContextOffsets.erase(DCU); |
| 2597 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2598 | } |
| 2599 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2600 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2601 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2602 | |
| 2603 | // Load the special types. |
| 2604 | Context->setBuiltinVaListType( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2605 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2606 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2607 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2608 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2609 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2610 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2611 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2612 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2613 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2614 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2615 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2616 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2617 | if (unsigned FastEnum |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2618 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2619 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2620 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2621 | QualType FileType = GetType(File); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2622 | if (FileType.isNull()) { |
| 2623 | Error("FILE type is NULL"); |
| 2624 | return; |
| 2625 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2626 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2627 | Context->setFILEDecl(Typedef->getDecl()); |
| 2628 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2629 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2630 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2631 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2632 | return; |
| 2633 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2634 | Context->setFILEDecl(Tag->getDecl()); |
| 2635 | } |
| 2636 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2637 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2638 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2639 | if (Jmp_bufType.isNull()) { |
| 2640 | Error("jmp_bug type is NULL"); |
| 2641 | return; |
| 2642 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2643 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2644 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2645 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2646 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2647 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2648 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2649 | return; |
| 2650 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2651 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2652 | } |
| 2653 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2654 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2655 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2656 | if (Sigjmp_bufType.isNull()) { |
| 2657 | Error("sigjmp_buf type is NULL"); |
| 2658 | return; |
| 2659 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2660 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2661 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2662 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2663 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2664 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2665 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2666 | } |
| 2667 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2668 | if (unsigned ObjCIdRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2669 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2670 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2671 | if (unsigned ObjCClassRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2672 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2673 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2674 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2675 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2676 | if (unsigned String |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2677 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2678 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2679 | if (unsigned ObjCSelRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2680 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2681 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2682 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2683 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2684 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2685 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2686 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2687 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2688 | if (unsigned AutoDeduct = SpecialTypes[SPECIAL_TYPE_AUTO_DEDUCT]) |
| 2689 | Context->AutoDeductTy = GetType(AutoDeduct); |
| 2690 | if (unsigned AutoRRefDeduct = SpecialTypes[SPECIAL_TYPE_AUTO_RREF_DEDUCT]) |
| 2691 | Context->AutoRRefDeductTy = GetType(AutoRRefDeduct); |
| 2692 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2693 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2694 | |
| 2695 | // If there were any CUDA special declarations, deserialize them. |
| 2696 | if (!CUDASpecialDeclRefs.empty()) { |
| 2697 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 2698 | Context->setcudaConfigureCallDecl( |
| 2699 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2700 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2701 | } |
| 2702 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2703 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2704 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2705 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2706 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2707 | FileManager &FileMgr, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2708 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2709 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2710 | std::string ErrStr; |
| 2711 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2712 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2713 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2714 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2715 | return std::string(); |
| 2716 | } |
| 2717 | |
| 2718 | // Initialize the stream |
| 2719 | llvm::BitstreamReader StreamFile; |
| 2720 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2721 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2722 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2723 | Stream.init(StreamFile); |
| 2724 | |
| 2725 | // Sniff for the signature. |
| 2726 | if (Stream.Read(8) != 'C' || |
| 2727 | Stream.Read(8) != 'P' || |
| 2728 | Stream.Read(8) != 'C' || |
| 2729 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2730 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2731 | return std::string(); |
| 2732 | } |
| 2733 | |
| 2734 | RecordData Record; |
| 2735 | while (!Stream.AtEndOfStream()) { |
| 2736 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2737 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2738 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2739 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2740 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2741 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2742 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2743 | case AST_BLOCK_ID: |
| 2744 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
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; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2749 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2750 | default: |
| 2751 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2752 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2753 | return std::string(); |
| 2754 | } |
| 2755 | break; |
| 2756 | } |
| 2757 | continue; |
| 2758 | } |
| 2759 | |
| 2760 | if (Code == llvm::bitc::END_BLOCK) { |
| 2761 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2762 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2763 | return std::string(); |
| 2764 | } |
| 2765 | continue; |
| 2766 | } |
| 2767 | |
| 2768 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2769 | Stream.ReadAbbrevRecord(); |
| 2770 | continue; |
| 2771 | } |
| 2772 | |
| 2773 | Record.clear(); |
| 2774 | const char *BlobStart = 0; |
| 2775 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2776 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2777 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2778 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2779 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2780 | |
| 2781 | return std::string(); |
| 2782 | } |
| 2783 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2784 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2785 | /// structure. |
| 2786 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2787 | /// This routine parses the language options from the AST file and then gives |
| 2788 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2789 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2790 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2791 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2792 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2793 | if (Listener) { |
| 2794 | LangOptions LangOpts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2795 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2796 | #define PARSE_LANGOPT(Option) \ |
| 2797 | LangOpts.Option = Record[Idx]; \ |
| 2798 | ++Idx |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2799 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2800 | unsigned Idx = 0; |
| 2801 | PARSE_LANGOPT(Trigraphs); |
| 2802 | PARSE_LANGOPT(BCPLComment); |
| 2803 | PARSE_LANGOPT(DollarIdents); |
| 2804 | PARSE_LANGOPT(AsmPreprocessor); |
| 2805 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2806 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2807 | PARSE_LANGOPT(ImplicitInt); |
| 2808 | PARSE_LANGOPT(Digraphs); |
| 2809 | PARSE_LANGOPT(HexFloats); |
| 2810 | PARSE_LANGOPT(C99); |
Peter Collingbourne | 7e7fbd0 | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 2811 | PARSE_LANGOPT(C1X); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2812 | PARSE_LANGOPT(Microsoft); |
| 2813 | PARSE_LANGOPT(CPlusPlus); |
| 2814 | PARSE_LANGOPT(CPlusPlus0x); |
| 2815 | PARSE_LANGOPT(CXXOperatorNames); |
| 2816 | PARSE_LANGOPT(ObjC1); |
| 2817 | PARSE_LANGOPT(ObjC2); |
| 2818 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 2819 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 2820 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 2821 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 2822 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2823 | PARSE_LANGOPT(PascalStrings); |
| 2824 | PARSE_LANGOPT(WritableStrings); |
| 2825 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2826 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2827 | PARSE_LANGOPT(Exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 2828 | PARSE_LANGOPT(ObjCExceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 2829 | PARSE_LANGOPT(CXXExceptions); |
| 2830 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 2831 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2832 | PARSE_LANGOPT(NeXTRuntime); |
| 2833 | PARSE_LANGOPT(Freestanding); |
| 2834 | PARSE_LANGOPT(NoBuiltin); |
| 2835 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 2836 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2837 | PARSE_LANGOPT(Blocks); |
| 2838 | PARSE_LANGOPT(EmitAllDecls); |
| 2839 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2840 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 2841 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2842 | PARSE_LANGOPT(HeinousExtensions); |
| 2843 | PARSE_LANGOPT(Optimize); |
| 2844 | PARSE_LANGOPT(OptimizeSize); |
| 2845 | PARSE_LANGOPT(Static); |
| 2846 | PARSE_LANGOPT(PICLevel); |
| 2847 | PARSE_LANGOPT(GNUInline); |
| 2848 | PARSE_LANGOPT(NoInline); |
Chandler Carruth | 0d2d1bc | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 2849 | PARSE_LANGOPT(Deprecated); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2850 | PARSE_LANGOPT(AccessControl); |
| 2851 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2852 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | b1bdced | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 2853 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2854 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2855 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 2856 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2857 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2858 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2859 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 2860 | PARSE_LANGOPT(CUDA); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2861 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2862 | PARSE_LANGOPT(DefaultFPContract); |
Roman Divacky | 1c51b1c | 2011-03-01 17:36:40 +0000 | [diff] [blame] | 2863 | PARSE_LANGOPT(ElideConstructors); |
| 2864 | PARSE_LANGOPT(SpellChecking); |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 2865 | PARSE_LANGOPT(MRTD); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2866 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2867 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2868 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2869 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2870 | |
| 2871 | return false; |
| 2872 | } |
| 2873 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2874 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2875 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2876 | PerFileData &F = *Chain[I]; |
| 2877 | if (!F.PreprocessorDetailCursor.getBitStreamReader()) |
| 2878 | continue; |
| 2879 | |
| 2880 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 2881 | F.PreprocessorDetailCursor.JumpToBit(F.PreprocessorDetailStartOffset); |
| 2882 | while (LoadPreprocessedEntity(F)) { } |
| 2883 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2884 | } |
| 2885 | |
Douglas Gregor | 0a48029 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 2886 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2887 | PerFileData *F = 0; |
| 2888 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2889 | if (Offset < Chain[I]->SizeInBits) { |
| 2890 | F = Chain[I]; |
| 2891 | break; |
| 2892 | } |
| 2893 | |
| 2894 | Offset -= Chain[I]->SizeInBits; |
| 2895 | } |
| 2896 | |
| 2897 | if (!F) { |
| 2898 | Error("Malformed preprocessed entity offset"); |
| 2899 | return 0; |
| 2900 | } |
| 2901 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2902 | // Keep track of where we are in the stream, then jump back there |
| 2903 | // after reading this entity. |
| 2904 | SavedStreamPosition SavedPosition(F->PreprocessorDetailCursor); |
| 2905 | F->PreprocessorDetailCursor.JumpToBit(Offset); |
| 2906 | return LoadPreprocessedEntity(*F); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2909 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
| 2910 | HeaderFileInfoTrait Trait(FE->getName()); |
| 2911 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2912 | PerFileData &F = *Chain[I]; |
| 2913 | HeaderFileInfoLookupTable *Table |
| 2914 | = static_cast<HeaderFileInfoLookupTable *>(F.HeaderFileInfoTable); |
| 2915 | if (!Table) |
| 2916 | continue; |
| 2917 | |
| 2918 | // Look in the on-disk hash table for an entry for this file name. |
| 2919 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE->getName(), |
| 2920 | &Trait); |
| 2921 | if (Pos == Table->end()) |
| 2922 | continue; |
| 2923 | |
| 2924 | HeaderFileInfo HFI = *Pos; |
| 2925 | if (Listener) |
| 2926 | Listener->ReadHeaderFileInfo(HFI, FE->getUID()); |
| 2927 | |
| 2928 | return HFI; |
| 2929 | } |
| 2930 | |
| 2931 | return HeaderFileInfo(); |
| 2932 | } |
| 2933 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2934 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2935 | unsigned Idx = 0; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2936 | while (Idx < PragmaDiagMappings.size()) { |
| 2937 | SourceLocation |
| 2938 | Loc = SourceLocation::getFromRawEncoding(PragmaDiagMappings[Idx++]); |
| 2939 | while (1) { |
| 2940 | assert(Idx < PragmaDiagMappings.size() && |
| 2941 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 2942 | if (Idx >= PragmaDiagMappings.size()) |
| 2943 | break; // Something is messed up but at least avoid infinite loop in |
| 2944 | // release build. |
| 2945 | unsigned DiagID = PragmaDiagMappings[Idx++]; |
| 2946 | if (DiagID == (unsigned)-1) |
| 2947 | break; // no more diag/map pairs for this location. |
| 2948 | diag::Mapping Map = (diag::Mapping)PragmaDiagMappings[Idx++]; |
| 2949 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 2950 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2951 | } |
| 2952 | } |
| 2953 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2954 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2955 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2956 | PerFileData *F = 0; |
| 2957 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2958 | F = Chain[N - I - 1]; |
| 2959 | if (Index < F->LocalNumTypes) |
| 2960 | break; |
| 2961 | Index -= F->LocalNumTypes; |
| 2962 | } |
| 2963 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2964 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2968 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2969 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 2970 | /// routine actually reads the record corresponding to the type at the given |
| 2971 | /// location. It is a helper routine for GetType, which deals with reading type |
| 2972 | /// IDs. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2973 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2974 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2975 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2976 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2977 | // Keep track of where we are in the stream, then jump back there |
| 2978 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2979 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2980 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 2981 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 2982 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2983 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 2984 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2985 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2986 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2987 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2988 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2989 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 2990 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2991 | if (Record.size() != 2) { |
| 2992 | Error("Incorrect encoding of extended qualifier type"); |
| 2993 | return QualType(); |
| 2994 | } |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2995 | QualType Base = GetType(Record[0]); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2996 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 2997 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2998 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2999 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3000 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3001 | if (Record.size() != 1) { |
| 3002 | Error("Incorrect encoding of complex type"); |
| 3003 | return QualType(); |
| 3004 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3005 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3006 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3007 | } |
| 3008 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3009 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3010 | if (Record.size() != 1) { |
| 3011 | Error("Incorrect encoding of pointer type"); |
| 3012 | return QualType(); |
| 3013 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3014 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3015 | return Context->getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3016 | } |
| 3017 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3018 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3019 | if (Record.size() != 1) { |
| 3020 | Error("Incorrect encoding of block pointer type"); |
| 3021 | return QualType(); |
| 3022 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3023 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3024 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3025 | } |
| 3026 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3027 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3028 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3029 | Error("Incorrect encoding of lvalue reference type"); |
| 3030 | return QualType(); |
| 3031 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3032 | QualType PointeeType = GetType(Record[0]); |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3033 | return Context->getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3034 | } |
| 3035 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3036 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3037 | if (Record.size() != 1) { |
| 3038 | Error("Incorrect encoding of rvalue reference type"); |
| 3039 | return QualType(); |
| 3040 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3041 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3042 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3043 | } |
| 3044 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3045 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3046 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3047 | Error("Incorrect encoding of member pointer type"); |
| 3048 | return QualType(); |
| 3049 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3050 | QualType PointeeType = GetType(Record[0]); |
| 3051 | QualType ClassType = GetType(Record[1]); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3052 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3053 | return QualType(); |
| 3054 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3055 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3058 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3059 | QualType ElementType = GetType(Record[0]); |
| 3060 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3061 | unsigned IndexTypeQuals = Record[2]; |
| 3062 | unsigned Idx = 3; |
| 3063 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3064 | return Context->getConstantArrayType(ElementType, Size, |
| 3065 | ASM, IndexTypeQuals); |
| 3066 | } |
| 3067 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3068 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3069 | QualType ElementType = GetType(Record[0]); |
| 3070 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3071 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3072 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3073 | } |
| 3074 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3075 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3076 | QualType ElementType = GetType(Record[0]); |
| 3077 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3078 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3079 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3080 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 3081 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3082 | ASM, IndexTypeQuals, |
| 3083 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3084 | } |
| 3085 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3086 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3087 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3088 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3089 | return QualType(); |
| 3090 | } |
| 3091 | |
| 3092 | QualType ElementType = GetType(Record[0]); |
| 3093 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3094 | unsigned VecKind = Record[2]; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3095 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3096 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3097 | } |
| 3098 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3099 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3100 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3101 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3102 | return QualType(); |
| 3103 | } |
| 3104 | |
| 3105 | QualType ElementType = GetType(Record[0]); |
| 3106 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3107 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3108 | } |
| 3109 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3110 | case TYPE_FUNCTION_NO_PROTO: { |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3111 | if (Record.size() != 5) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3112 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3113 | return QualType(); |
| 3114 | } |
| 3115 | QualType ResultType = GetType(Record[0]); |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3116 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], (CallingConv)Record[4]); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 3117 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3118 | } |
| 3119 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3120 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3121 | QualType ResultType = GetType(Record[0]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3122 | |
| 3123 | FunctionProtoType::ExtProtoInfo EPI; |
| 3124 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3125 | /*hasregparm*/ Record[2], |
| 3126 | /*regparm*/ Record[3], |
| 3127 | static_cast<CallingConv>(Record[4])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3128 | |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3129 | unsigned Idx = 5; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3130 | unsigned NumParams = Record[Idx++]; |
| 3131 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 3132 | for (unsigned I = 0; I != NumParams; ++I) |
| 3133 | ParamTypes.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3134 | |
| 3135 | EPI.Variadic = Record[Idx++]; |
| 3136 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3137 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3138 | ExceptionSpecificationType EST = |
| 3139 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3140 | EPI.ExceptionSpecType = EST; |
| 3141 | if (EST == EST_Dynamic) { |
| 3142 | EPI.NumExceptions = Record[Idx++]; |
| 3143 | llvm::SmallVector<QualType, 2> Exceptions; |
| 3144 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
| 3145 | Exceptions.push_back(GetType(Record[Idx++])); |
| 3146 | EPI.Exceptions = Exceptions.data(); |
| 3147 | } else if (EST == EST_ComputedNoexcept) { |
| 3148 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
| 3149 | } |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 3150 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3151 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3152 | } |
| 3153 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3154 | case TYPE_UNRESOLVED_USING: |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3155 | return Context->getTypeDeclType( |
| 3156 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 3157 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3158 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3159 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3160 | Error("incorrect encoding of typedef type"); |
| 3161 | return QualType(); |
| 3162 | } |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3163 | TypedefNameDecl *Decl = cast<TypedefNameDecl>(GetDecl(Record[0])); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3164 | QualType Canonical = GetType(Record[1]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3165 | if (!Canonical.isNull()) |
| 3166 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3167 | return Context->getTypedefType(Decl, Canonical); |
| 3168 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3169 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3170 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3171 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3172 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3173 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3174 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3175 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3176 | return QualType(); |
| 3177 | } |
| 3178 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3179 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3180 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3181 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3182 | case TYPE_DECLTYPE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3183 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3184 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3185 | case TYPE_AUTO: |
| 3186 | return Context->getAutoType(GetType(Record[0])); |
| 3187 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3188 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3189 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3190 | Error("incorrect encoding of record type"); |
| 3191 | return QualType(); |
| 3192 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3193 | bool IsDependent = Record[0]; |
| 3194 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3195 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3196 | return T; |
| 3197 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3198 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3199 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3200 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3201 | Error("incorrect encoding of enum type"); |
| 3202 | return QualType(); |
| 3203 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3204 | bool IsDependent = Record[0]; |
| 3205 | QualType T = Context->getEnumType(cast<EnumDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3206 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3207 | return T; |
| 3208 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3209 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3210 | case TYPE_ATTRIBUTED: { |
| 3211 | if (Record.size() != 3) { |
| 3212 | Error("incorrect encoding of attributed type"); |
| 3213 | return QualType(); |
| 3214 | } |
| 3215 | QualType modifiedType = GetType(Record[0]); |
| 3216 | QualType equivalentType = GetType(Record[1]); |
| 3217 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 3218 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 3219 | } |
| 3220 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3221 | case TYPE_PAREN: { |
| 3222 | if (Record.size() != 1) { |
| 3223 | Error("incorrect encoding of paren type"); |
| 3224 | return QualType(); |
| 3225 | } |
| 3226 | QualType InnerType = GetType(Record[0]); |
| 3227 | return Context->getParenType(InnerType); |
| 3228 | } |
| 3229 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3230 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3231 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3232 | Error("incorrect encoding of pack expansion type"); |
| 3233 | return QualType(); |
| 3234 | } |
| 3235 | QualType Pattern = GetType(Record[0]); |
| 3236 | if (Pattern.isNull()) |
| 3237 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3238 | llvm::Optional<unsigned> NumExpansions; |
| 3239 | if (Record[1]) |
| 3240 | NumExpansions = Record[1] - 1; |
| 3241 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3242 | } |
| 3243 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3244 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3245 | unsigned Idx = 0; |
| 3246 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3247 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3248 | QualType NamedType = GetType(Record[Idx++]); |
| 3249 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3250 | } |
| 3251 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3252 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3253 | unsigned Idx = 0; |
| 3254 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3255 | return Context->getObjCInterfaceType(ItfD); |
| 3256 | } |
| 3257 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3258 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3259 | unsigned Idx = 0; |
| 3260 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3261 | unsigned NumProtos = Record[Idx++]; |
| 3262 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 3263 | for (unsigned I = 0; I != NumProtos; ++I) |
| 3264 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3265 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3266 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3267 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3268 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3269 | unsigned Idx = 0; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3270 | QualType Pointee = GetType(Record[Idx++]); |
| 3271 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3272 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3273 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3274 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3275 | unsigned Idx = 0; |
| 3276 | QualType Parm = GetType(Record[Idx++]); |
| 3277 | QualType Replacement = GetType(Record[Idx++]); |
| 3278 | return |
| 3279 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3280 | Replacement); |
| 3281 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3282 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3283 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3284 | unsigned Idx = 0; |
| 3285 | QualType Parm = GetType(Record[Idx++]); |
| 3286 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3287 | return Context->getSubstTemplateTypeParmPackType( |
| 3288 | cast<TemplateTypeParmType>(Parm), |
| 3289 | ArgPack); |
| 3290 | } |
| 3291 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3292 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3293 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 3294 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3295 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3296 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3297 | return |
| 3298 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3299 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3300 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3301 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3302 | unsigned Idx = 0; |
| 3303 | unsigned Depth = Record[Idx++]; |
| 3304 | unsigned Index = Record[Idx++]; |
| 3305 | bool Pack = Record[Idx++]; |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame^] | 3306 | TemplateTypeParmDecl *D = |
| 3307 | cast_or_null<TemplateTypeParmDecl>(GetDecl(Record[Idx++])); |
| 3308 | return Context->getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3309 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3310 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3311 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3312 | unsigned Idx = 0; |
| 3313 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3314 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3315 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3316 | QualType Canon = GetType(Record[Idx++]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3317 | if (!Canon.isNull()) |
| 3318 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3319 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3320 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3321 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3322 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3323 | unsigned Idx = 0; |
| 3324 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3325 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3326 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
| 3327 | unsigned NumArgs = Record[Idx++]; |
| 3328 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 3329 | Args.reserve(NumArgs); |
| 3330 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3331 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3332 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3333 | Args.size(), Args.data()); |
| 3334 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3335 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3336 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3337 | unsigned Idx = 0; |
| 3338 | |
| 3339 | // ArrayType |
| 3340 | QualType ElementType = GetType(Record[Idx++]); |
| 3341 | ArrayType::ArraySizeModifier ASM |
| 3342 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3343 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3344 | |
| 3345 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3346 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3347 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3348 | |
| 3349 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3350 | IndexTypeQuals, Brackets); |
| 3351 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3352 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3353 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3354 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3355 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3356 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3357 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3358 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3359 | QualType Canon = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3360 | QualType T; |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3361 | if (Canon.isNull()) |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3362 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3363 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3364 | else |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3365 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
| 3366 | Args.size(), Canon); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3367 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3368 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3369 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3370 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3371 | // Suppress a GCC warning |
| 3372 | return QualType(); |
| 3373 | } |
| 3374 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3375 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3376 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3377 | ASTReader::PerFileData &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3378 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3379 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3380 | unsigned &Idx; |
| 3381 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3382 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3383 | unsigned &I) { |
| 3384 | return Reader.ReadSourceLocation(F, R, I); |
| 3385 | } |
| 3386 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3387 | public: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3388 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3389 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3390 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3391 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3392 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3393 | // We want compile-time assurance that we've enumerated all of |
| 3394 | // these, so unfortunately we have to declare them first, then |
| 3395 | // define them out-of-line. |
| 3396 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3397 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3398 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3399 | #include "clang/AST/TypeLocNodes.def" |
| 3400 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3401 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3402 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3403 | }; |
| 3404 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3405 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3406 | // nothing to do |
| 3407 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3408 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3409 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3410 | if (TL.needsExtraLocalData()) { |
| 3411 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3412 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3413 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3414 | TL.setModeAttr(Record[Idx++]); |
| 3415 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3416 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3417 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3418 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3419 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3420 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3421 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3422 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3423 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3424 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3425 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3426 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3427 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3428 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3429 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3430 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3431 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3432 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3433 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3434 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3435 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3436 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3437 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3438 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3439 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3440 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3441 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3442 | TL.setSizeExpr(0); |
| 3443 | } |
| 3444 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3445 | VisitArrayTypeLoc(TL); |
| 3446 | } |
| 3447 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3448 | VisitArrayTypeLoc(TL); |
| 3449 | } |
| 3450 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3451 | VisitArrayTypeLoc(TL); |
| 3452 | } |
| 3453 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3454 | DependentSizedArrayTypeLoc TL) { |
| 3455 | VisitArrayTypeLoc(TL); |
| 3456 | } |
| 3457 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3458 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3459 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3460 | } |
| 3461 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3462 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3463 | } |
| 3464 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3465 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3466 | } |
| 3467 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3468 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 3469 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3470 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3471 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | 86acc2a | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 3472 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3473 | } |
| 3474 | } |
| 3475 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3476 | VisitFunctionTypeLoc(TL); |
| 3477 | } |
| 3478 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3479 | VisitFunctionTypeLoc(TL); |
| 3480 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3481 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3482 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3483 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3484 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3485 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3486 | } |
| 3487 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3488 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3489 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3490 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3491 | } |
| 3492 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3493 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3494 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3495 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3496 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3497 | } |
| 3498 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3499 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3500 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3501 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3502 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3503 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3504 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3505 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3506 | } |
| 3507 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3508 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3509 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3510 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3511 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3512 | if (TL.hasAttrOperand()) { |
| 3513 | SourceRange range; |
| 3514 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3515 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3516 | TL.setAttrOperandParensRange(range); |
| 3517 | } |
| 3518 | if (TL.hasAttrExprOperand()) { |
| 3519 | if (Record[Idx++]) |
| 3520 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3521 | else |
| 3522 | TL.setAttrExprOperand(0); |
| 3523 | } else if (TL.hasAttrEnumOperand()) |
| 3524 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3525 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3526 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3527 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3528 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3529 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3530 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3531 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3532 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3533 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3534 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3535 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3536 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3537 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3538 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3539 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3540 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3541 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3542 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3543 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3544 | Reader.GetTemplateArgumentLocInfo(F, |
| 3545 | TL.getTypePtr()->getArg(i).getKind(), |
| 3546 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3547 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3548 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3549 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3550 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3551 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3552 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3553 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3554 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3555 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3556 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3557 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3558 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3559 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3560 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3561 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3562 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3563 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3564 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3565 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3566 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3567 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3568 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3569 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3570 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3571 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3572 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3573 | Reader.GetTemplateArgumentLocInfo(F, |
| 3574 | TL.getTypePtr()->getArg(I).getKind(), |
| 3575 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3576 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3577 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3578 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3579 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3580 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3581 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3582 | } |
| 3583 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3584 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3585 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3586 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3587 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3588 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3589 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3590 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3591 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3592 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3593 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3594 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3595 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3596 | unsigned &Idx) { |
| 3597 | QualType InfoTy = GetType(Record[Idx++]); |
| 3598 | if (InfoTy.isNull()) |
| 3599 | return 0; |
| 3600 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3601 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3602 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3603 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3604 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3605 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3606 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3607 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3608 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3609 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3610 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3611 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3612 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3613 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3614 | switch ((PredefinedTypeIDs)Index) { |
| 3615 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3616 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3617 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3618 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3619 | case PREDEF_TYPE_CHAR_U_ID: |
| 3620 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3621 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3622 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3623 | break; |
| 3624 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3625 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3626 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3627 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3628 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3629 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3630 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3631 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3632 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3633 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3634 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3635 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3636 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3637 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3638 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3639 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3640 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3641 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 3642 | case PREDEF_TYPE_BOUND_MEMBER: T = Context->BoundMemberTy; break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3643 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
John McCall | 1de4d4e | 2011-04-07 08:22:57 +0000 | [diff] [blame] | 3644 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context->UnknownAnyTy; break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3645 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3646 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3647 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3648 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3649 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3650 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3651 | } |
| 3652 | |
| 3653 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3654 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3655 | } |
| 3656 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3657 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3658 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3659 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3660 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3661 | if (TypesLoaded[Index].isNull()) |
| 3662 | return QualType(); |
| 3663 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3664 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3665 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3666 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3667 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3668 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3669 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3670 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3671 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3672 | } |
| 3673 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3674 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3675 | return MakeTypeID(T, |
| 3676 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3677 | } |
| 3678 | |
| 3679 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3680 | if (T.isNull()) |
| 3681 | return TypeIdx(); |
| 3682 | assert(!T.getLocalFastQualifiers()); |
| 3683 | |
| 3684 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3685 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3686 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3687 | // If the type didn't come from the AST file use a specially marked index |
| 3688 | // so that any hash/key comparison fail since no such index is stored |
| 3689 | // in a AST file. |
| 3690 | if (I == TypeIdxs.end()) |
| 3691 | return TypeIdx(-1); |
| 3692 | return I->second; |
| 3693 | } |
| 3694 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3695 | unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const { |
| 3696 | unsigned Result = 0; |
| 3697 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 3698 | Result += Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3699 | |
| 3700 | return Result; |
| 3701 | } |
| 3702 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3703 | TemplateArgumentLocInfo |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3704 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3705 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3706 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3707 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3708 | switch (Kind) { |
| 3709 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3710 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3711 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3712 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3713 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3714 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3715 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3716 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3717 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3718 | SourceLocation()); |
| 3719 | } |
| 3720 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3721 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3722 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3723 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3724 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3725 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3726 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3727 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3728 | case TemplateArgument::Null: |
| 3729 | case TemplateArgument::Integral: |
| 3730 | case TemplateArgument::Declaration: |
| 3731 | case TemplateArgument::Pack: |
| 3732 | return TemplateArgumentLocInfo(); |
| 3733 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3734 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3735 | return TemplateArgumentLocInfo(); |
| 3736 | } |
| 3737 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3738 | TemplateArgumentLoc |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3739 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3740 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3741 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3742 | |
| 3743 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3744 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3745 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3746 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3747 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3748 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3749 | } |
| 3750 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3751 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3752 | return GetDecl(ID); |
| 3753 | } |
| 3754 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3755 | uint64_t |
| 3756 | ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) { |
| 3757 | if (ID == 0) |
| 3758 | return 0; |
| 3759 | |
| 3760 | --ID; |
| 3761 | uint64_t Offset = 0; |
| 3762 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3763 | PerFileData &F = *Chain[N - I - 1]; |
| 3764 | |
| 3765 | if (ID < F.LocalNumCXXBaseSpecifiers) |
| 3766 | return Offset + F.CXXBaseSpecifiersOffsets[ID]; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3767 | |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3768 | ID -= F.LocalNumCXXBaseSpecifiers; |
| 3769 | Offset += F.SizeInBits; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | assert(false && "CXXBaseSpecifiers not found"); |
| 3773 | return 0; |
| 3774 | } |
| 3775 | |
| 3776 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 3777 | // Figure out which AST file contains this offset. |
| 3778 | PerFileData *F = 0; |
| 3779 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3780 | if (Offset < Chain[N - I - 1]->SizeInBits) { |
| 3781 | F = Chain[N - I - 1]; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3782 | break; |
| 3783 | } |
| 3784 | |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3785 | Offset -= Chain[N - I - 1]->SizeInBits; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3786 | } |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3787 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3788 | if (!F) { |
| 3789 | Error("Malformed AST file: C++ base specifiers at impossible offset"); |
| 3790 | return 0; |
| 3791 | } |
| 3792 | |
| 3793 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3794 | SavedStreamPosition SavedPosition(Cursor); |
| 3795 | Cursor.JumpToBit(Offset); |
| 3796 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3797 | RecordData Record; |
| 3798 | unsigned Code = Cursor.ReadCode(); |
| 3799 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 3800 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 3801 | Error("Malformed AST file: missing C++ base specifiers"); |
| 3802 | return 0; |
| 3803 | } |
| 3804 | |
| 3805 | unsigned Idx = 0; |
| 3806 | unsigned NumBases = Record[Idx++]; |
| 3807 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 3808 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 3809 | for (unsigned I = 0; I != NumBases; ++I) |
| 3810 | Bases[I] = ReadCXXBaseSpecifier(*F, Record, Idx); |
| 3811 | return Bases; |
| 3812 | } |
| 3813 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3814 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3815 | if (!DeclsLoaded[0]) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 3816 | ReadDeclRecord(0, 1); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3817 | if (DeserializationListener) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3818 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3819 | } |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 3820 | |
| 3821 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 3822 | } |
| 3823 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3824 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3825 | if (ID == 0) |
| 3826 | return 0; |
| 3827 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3828 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3829 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3830 | return 0; |
| 3831 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3832 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3833 | unsigned Index = ID - 1; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3834 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3835 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3836 | if (DeserializationListener) |
| 3837 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3838 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3839 | |
| 3840 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3841 | } |
| 3842 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3843 | /// \brief Resolve the offset of a statement into a statement. |
| 3844 | /// |
| 3845 | /// This operation will read a new statement from the external |
| 3846 | /// source each time it is called, and is meant to be used via a |
| 3847 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3848 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 3849 | // Switch case IDs are per Decl. |
| 3850 | ClearSwitchCaseIDs(); |
| 3851 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3852 | // Offset here is a global offset across the entire chain. |
| 3853 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3854 | PerFileData &F = *Chain[N - I - 1]; |
| 3855 | if (Offset < F.SizeInBits) { |
| 3856 | // Since we know that this statement is part of a decl, make sure to use |
| 3857 | // the decl cursor to read it. |
| 3858 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3859 | return ReadStmtFromStream(F); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3860 | } |
| 3861 | Offset -= F.SizeInBits; |
| 3862 | } |
| 3863 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 3864 | } |
| 3865 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3866 | bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3867 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3868 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3869 | assert(DC->hasExternalLexicalStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3870 | "DeclContext has no lexical decls in storage"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3871 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3872 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 3873 | // at least. |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3874 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 3875 | // so make a copy of the vector. |
| 3876 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3877 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3878 | I != E; ++I) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3879 | // IDs can be 0 if this context doesn't contain declarations. |
| 3880 | if (!I->LexicalDecls) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3881 | continue; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3882 | |
| 3883 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3884 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 3885 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 3886 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 3887 | continue; |
| 3888 | |
| 3889 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3890 | assert(D && "Null decl in lexical decls"); |
| 3891 | Decls.push_back(D); |
| 3892 | } |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3893 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3894 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3895 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3896 | return false; |
| 3897 | } |
| 3898 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3899 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3900 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3901 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3902 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3903 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3904 | if (!Name) |
| 3905 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 3906 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3907 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3908 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 8b12273 | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 3909 | // 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] | 3910 | // and namespaces. For any given name, the last available results replace |
| 3911 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3912 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3913 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3914 | I != E; ++I) { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3915 | if (!I->NameLookupTableData) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3916 | continue; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3917 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3918 | ASTDeclContextNameLookupTable *LookupTable = |
| 3919 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3920 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 3921 | if (Pos == LookupTable->end()) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3922 | continue; |
| 3923 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3924 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 3925 | for (; Data.first != Data.second; ++Data.first) |
| 3926 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3927 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3928 | } |
| 3929 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3930 | ++NumVisibleDeclContextsRead; |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3931 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3932 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3933 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3934 | } |
| 3935 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 3936 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 3937 | assert(DC->hasExternalVisibleStorage() && |
| 3938 | "DeclContext has no visible decls in storage"); |
| 3939 | |
| 3940 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 3941 | // There might be visible decls in multiple parts of the chain, for the TU |
| 3942 | // and namespaces. |
| 3943 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 3944 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3945 | I != E; ++I) { |
| 3946 | if (!I->NameLookupTableData) |
| 3947 | continue; |
| 3948 | |
| 3949 | ASTDeclContextNameLookupTable *LookupTable = |
| 3950 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3951 | for (ASTDeclContextNameLookupTable::item_iterator |
| 3952 | ItemI = LookupTable->item_begin(), |
| 3953 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 3954 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 3955 | = *ItemI; |
| 3956 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 3957 | Decls.clear(); |
| 3958 | for (; Data.first != Data.second; ++Data.first) |
| 3959 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 3960 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 3961 | } |
| 3962 | } |
| 3963 | } |
| 3964 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3965 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3966 | assert(Consumer); |
| 3967 | while (!InterestingDecls.empty()) { |
| 3968 | DeclGroupRef DG(InterestingDecls.front()); |
| 3969 | InterestingDecls.pop_front(); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3970 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3971 | } |
| 3972 | } |
| 3973 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3974 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 3975 | this->Consumer = Consumer; |
| 3976 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3977 | if (!Consumer) |
| 3978 | return; |
| 3979 | |
| 3980 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3981 | // Force deserialization of this decl, which will cause it to be queued for |
| 3982 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 3983 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3984 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 3985 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3986 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3987 | } |
| 3988 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3989 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3990 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3991 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3992 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3993 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3994 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3995 | unsigned NumDeclsLoaded |
| 3996 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 3997 | (Decl *)0); |
| 3998 | unsigned NumIdentifiersLoaded |
| 3999 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 4000 | IdentifiersLoaded.end(), |
| 4001 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4002 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4003 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 4004 | SelectorsLoaded.end(), |
| 4005 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 4006 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4007 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 4008 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4009 | if (TotalNumSLocEntries) |
| 4010 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 4011 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 4012 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4013 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4014 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4015 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 4016 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 4017 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4018 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4019 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 4020 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4021 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4022 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4023 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4024 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4025 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4026 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4027 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4028 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4029 | if (TotalNumStatements) |
| 4030 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4031 | NumStatementsRead, TotalNumStatements, |
| 4032 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4033 | if (TotalNumMacros) |
| 4034 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4035 | NumMacrosRead, TotalNumMacros, |
| 4036 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4037 | if (TotalLexicalDeclContexts) |
| 4038 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4039 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4040 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4041 | * 100)); |
| 4042 | if (TotalVisibleDeclContexts) |
| 4043 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4044 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4045 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4046 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4047 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4048 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4049 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4050 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4051 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4052 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4053 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4054 | std::fprintf(stderr, "\n"); |
| 4055 | } |
| 4056 | |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4057 | /// Return the amount of memory used by memory buffers, breaking down |
| 4058 | /// by heap-backed versus mmap'ed memory. |
| 4059 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
| 4060 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 4061 | if (llvm::MemoryBuffer *buf = Chain[i]->Buffer.get()) { |
| 4062 | size_t bytes = buf->getBufferSize(); |
| 4063 | switch (buf->getBufferKind()) { |
| 4064 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 4065 | sizes.malloc_bytes += bytes; |
| 4066 | break; |
| 4067 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 4068 | sizes.mmap_bytes += bytes; |
| 4069 | break; |
| 4070 | } |
| 4071 | } |
| 4072 | } |
| 4073 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4074 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4075 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4076 | S.ExternalSource = this; |
| 4077 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4078 | // Makes sure any declarations that were deserialized "too early" |
| 4079 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4080 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4081 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4082 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4083 | |
| 4084 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4085 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4086 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4087 | |
| 4088 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4089 | // them to Sema's list of tentative definitions. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4090 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4091 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4092 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4093 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 4094 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4095 | // If there were any unused file scoped decls, deserialize them and add to |
| 4096 | // Sema's list of unused file scoped decls. |
| 4097 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4098 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4099 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 4100 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4101 | |
| 4102 | // If there were any locally-scoped external declarations, |
| 4103 | // deserialize them and add them to Sema's table of locally-scoped |
| 4104 | // external declarations. |
| 4105 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4106 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4107 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 4108 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4109 | |
| 4110 | // If there were any ext_vector type declarations, deserialize them |
| 4111 | // and add them to Sema's vector of such declarations. |
| 4112 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 4113 | SemaObj->ExtVectorDecls.push_back( |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4114 | cast<TypedefNameDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4115 | |
| 4116 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 4117 | // Can we cut them down before writing them ? |
| 4118 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4119 | // If there were any dynamic classes declarations, deserialize them |
| 4120 | // and add them to Sema's vector of such declarations. |
| 4121 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 4122 | SemaObj->DynamicClasses.push_back( |
| 4123 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4124 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4125 | // Load the offsets of the declarations that Sema references. |
| 4126 | // They will be lazily deserialized when needed. |
| 4127 | if (!SemaDeclRefs.empty()) { |
| 4128 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 4129 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4130 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 4131 | } |
| 4132 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4133 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 4134 | |
| 4135 | // If there are @selector references added them to its pool. This is for |
| 4136 | // implementation of -Wselector. |
| 4137 | if (!F->ReferencedSelectorsData.empty()) { |
| 4138 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 4139 | unsigned I = 0; |
| 4140 | while (I < DataSize) { |
| 4141 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 4142 | SourceLocation SelLoc = ReadSourceLocation( |
| 4143 | *F, F->ReferencedSelectorsData, I); |
| 4144 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 4145 | } |
| 4146 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4147 | } |
| 4148 | |
Sebastian Redl | c1d3ffb | 2011-04-24 16:27:30 +0000 | [diff] [blame] | 4149 | // The special data sets below always come from the most recent PCH, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4150 | // which is at the front of the chain. |
| 4151 | PerFileData &F = *Chain.front(); |
| 4152 | |
Sebastian Redl | c1d3ffb | 2011-04-24 16:27:30 +0000 | [diff] [blame] | 4153 | // If there were any pending implicit instantiations, deserialize them |
| 4154 | // and add them to Sema's queue of such instantiations. |
| 4155 | assert(F.PendingInstantiations.size() % 2 == 0 && |
| 4156 | "Expected pairs of entries"); |
| 4157 | for (unsigned Idx = 0, N = F.PendingInstantiations.size(); Idx < N;) { |
| 4158 | ValueDecl *D=cast<ValueDecl>(GetDecl(F.PendingInstantiations[Idx++])); |
| 4159 | SourceLocation Loc = ReadSourceLocation(F, F.PendingInstantiations,Idx); |
| 4160 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 4161 | } |
| 4162 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4163 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 4164 | // Sema's list of weak undeclared identifiers. |
| 4165 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 4166 | unsigned Idx = 0; |
| 4167 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 4168 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4169 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4170 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 4171 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 4172 | Sema::WeakInfo WI(AliasId, Loc); |
| 4173 | WI.setUsed(Used); |
| 4174 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 4175 | } |
| 4176 | } |
| 4177 | |
| 4178 | // If there were any VTable uses, deserialize the information and add it |
| 4179 | // to Sema's vector and map of VTable uses. |
| 4180 | if (!VTableUses.empty()) { |
| 4181 | unsigned Idx = 0; |
| 4182 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 4183 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4184 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 4185 | bool DefinitionRequired = VTableUses[Idx++]; |
| 4186 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 4187 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4188 | } |
| 4189 | } |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4190 | |
| 4191 | if (!FPPragmaOptions.empty()) { |
| 4192 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4193 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4194 | } |
| 4195 | |
| 4196 | if (!OpenCLExtensions.empty()) { |
| 4197 | unsigned I = 0; |
| 4198 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4199 | #include "clang/Basic/OpenCLExtensions.def" |
| 4200 | |
| 4201 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4202 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4203 | } |
| 4204 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4205 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4206 | // Try to find this name within our on-disk hash tables. We start with the |
| 4207 | // 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] | 4208 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4209 | ASTIdentifierLookupTable *IdTable |
| 4210 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4211 | if (!IdTable) |
| 4212 | continue; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4213 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4214 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4215 | if (Pos == IdTable->end()) |
| 4216 | continue; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4217 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4218 | // Dereferencing the iterator has the effect of building the |
| 4219 | // IdentifierInfo node and populating it with the various |
| 4220 | // declarations it needs. |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4221 | return *Pos; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4222 | } |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4223 | return 0; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4224 | } |
| 4225 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4226 | namespace clang { |
| 4227 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4228 | /// identifiers stored within a set of AST files. |
| 4229 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4230 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4231 | const ASTReader &Reader; |
| 4232 | |
| 4233 | /// \brief The current index into the chain of AST files stored in |
| 4234 | /// the AST reader. |
| 4235 | unsigned Index; |
| 4236 | |
| 4237 | /// \brief The current position within the identifier lookup table |
| 4238 | /// of the current AST file. |
| 4239 | ASTIdentifierLookupTable::key_iterator Current; |
| 4240 | |
| 4241 | /// \brief The end position within the identifier lookup table of |
| 4242 | /// the current AST file. |
| 4243 | ASTIdentifierLookupTable::key_iterator End; |
| 4244 | |
| 4245 | public: |
| 4246 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4247 | |
| 4248 | virtual llvm::StringRef Next(); |
| 4249 | }; |
| 4250 | } |
| 4251 | |
| 4252 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 4253 | : Reader(Reader), Index(Reader.Chain.size() - 1) { |
| 4254 | ASTIdentifierLookupTable *IdTable |
| 4255 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4256 | Current = IdTable->key_begin(); |
| 4257 | End = IdTable->key_end(); |
| 4258 | } |
| 4259 | |
| 4260 | llvm::StringRef ASTIdentifierIterator::Next() { |
| 4261 | while (Current == End) { |
| 4262 | // If we have exhausted all of our AST files, we're done. |
| 4263 | if (Index == 0) |
| 4264 | return llvm::StringRef(); |
| 4265 | |
| 4266 | --Index; |
| 4267 | ASTIdentifierLookupTable *IdTable |
| 4268 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4269 | Current = IdTable->key_begin(); |
| 4270 | End = IdTable->key_end(); |
| 4271 | } |
| 4272 | |
| 4273 | // We have any identifiers remaining in the current AST file; return |
| 4274 | // the next one. |
| 4275 | std::pair<const char*, unsigned> Key = *Current; |
| 4276 | ++Current; |
| 4277 | return llvm::StringRef(Key.first, Key.second); |
| 4278 | } |
| 4279 | |
| 4280 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4281 | return new ASTIdentifierIterator(*this); |
| 4282 | } |
| 4283 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4284 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4285 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4286 | // Find this selector in a hash table. We want to find the most recent entry. |
| 4287 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4288 | PerFileData &F = *Chain[I]; |
| 4289 | if (!F.SelectorLookupTable) |
| 4290 | continue; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4291 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4292 | ASTSelectorLookupTable *PoolTable |
| 4293 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 4294 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4295 | if (Pos != PoolTable->end()) { |
| 4296 | ++NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4297 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4298 | // disable this tracking when called via LoadSelector. |
| 4299 | // Also, should entries without methods count as misses? |
| 4300 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4301 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4302 | if (DeserializationListener) |
| 4303 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 4304 | return std::make_pair(Data.Instance, Data.Factory); |
| 4305 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4306 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4307 | |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4308 | ++NumMethodPoolMisses; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4309 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4310 | } |
| 4311 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4312 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4313 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4314 | ReadMethodPool(Sel); |
| 4315 | } |
| 4316 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4317 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4318 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4319 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4320 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4321 | if (DeserializationListener) |
| 4322 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4323 | } |
| 4324 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4325 | /// \brief Set the globally-visible declarations associated with the given |
| 4326 | /// identifier. |
| 4327 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4328 | /// 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] | 4329 | /// 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] | 4330 | /// them. |
| 4331 | /// |
| 4332 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4333 | /// declarations. |
| 4334 | /// |
| 4335 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4336 | /// visible at global scope. |
| 4337 | /// |
| 4338 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4339 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4340 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4341 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4342 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4343 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 4344 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4345 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4346 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4347 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4348 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4349 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4350 | return; |
| 4351 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4352 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4353 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4354 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4355 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4356 | if (SemaObj->TUScope) { |
| 4357 | // Introduce this declaration into the translation-unit scope |
| 4358 | // and add it to the declaration chain for this identifier, so |
| 4359 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4360 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4361 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4362 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4363 | } else { |
| 4364 | // Queue this declaration so that it will be added to the |
| 4365 | // translation unit scope and identifier's declaration chain |
| 4366 | // once a Sema object is known. |
| 4367 | PreloadedDecls.push_back(D); |
| 4368 | } |
| 4369 | } |
| 4370 | } |
| 4371 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4372 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4373 | if (ID == 0) |
| 4374 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4375 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4376 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4377 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4378 | return 0; |
| 4379 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4380 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4381 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4382 | ID -= 1; |
| 4383 | if (!IdentifiersLoaded[ID]) { |
| 4384 | unsigned Index = ID; |
| 4385 | const char *Str = 0; |
| 4386 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4387 | PerFileData *F = Chain[N - I - 1]; |
| 4388 | if (Index < F->LocalNumIdentifiers) { |
| 4389 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 4390 | Str = F->IdentifierTableData + Offset; |
| 4391 | break; |
| 4392 | } |
| 4393 | Index -= F->LocalNumIdentifiers; |
| 4394 | } |
| 4395 | assert(Str && "Broken Chain"); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4396 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4397 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4398 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4399 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4400 | // unsigned integers. This is important to avoid integer overflow when |
| 4401 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4402 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4403 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4404 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4405 | IdentifiersLoaded[ID] |
Kovarththanan Rajaratnam | 811f426 | 2010-03-12 10:32:27 +0000 | [diff] [blame] | 4406 | = &PP->getIdentifierTable().get(Str, StrLen); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4407 | if (DeserializationListener) |
| 4408 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4409 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4410 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4411 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4412 | } |
| 4413 | |
Douglas Gregor | e23ac65 | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 4414 | bool ASTReader::ReadSLocEntry(unsigned ID) { |
| 4415 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4416 | } |
| 4417 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4418 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4419 | if (ID == 0) |
| 4420 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4421 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4422 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4423 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4424 | return Selector(); |
| 4425 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4426 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4427 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4428 | // Load this selector from the selector table. |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4429 | unsigned Idx = ID - 1; |
| 4430 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4431 | PerFileData &F = *Chain[N - I - 1]; |
| 4432 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4433 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4434 | SelectorsLoaded[ID - 1] = |
| 4435 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 4436 | if (DeserializationListener) |
| 4437 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 4438 | break; |
| 4439 | } |
| 4440 | Idx -= F.LocalNumSelectors; |
| 4441 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4442 | } |
| 4443 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4444 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4445 | } |
| 4446 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4447 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4448 | return DecodeSelector(ID); |
| 4449 | } |
| 4450 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4451 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4452 | // ID 0 (the null selector) is considered an external selector. |
| 4453 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4454 | } |
| 4455 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4456 | DeclarationName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4457 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4458 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4459 | switch (Kind) { |
| 4460 | case DeclarationName::Identifier: |
| 4461 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 4462 | |
| 4463 | case DeclarationName::ObjCZeroArgSelector: |
| 4464 | case DeclarationName::ObjCOneArgSelector: |
| 4465 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 4466 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4467 | |
| 4468 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4469 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4470 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4471 | |
| 4472 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4473 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4474 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4475 | |
| 4476 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4477 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4478 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4479 | |
| 4480 | case DeclarationName::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4481 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4482 | (OverloadedOperatorKind)Record[Idx++]); |
| 4483 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4484 | case DeclarationName::CXXLiteralOperatorName: |
| 4485 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 4486 | GetIdentifierInfo(Record, Idx)); |
| 4487 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4488 | case DeclarationName::CXXUsingDirective: |
| 4489 | return DeclarationName::getUsingDirectiveName(); |
| 4490 | } |
| 4491 | |
| 4492 | // Required to silence GCC warning |
| 4493 | return DeclarationName(); |
| 4494 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4495 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4496 | void ASTReader::ReadDeclarationNameLoc(PerFileData &F, |
| 4497 | DeclarationNameLoc &DNLoc, |
| 4498 | DeclarationName Name, |
| 4499 | const RecordData &Record, unsigned &Idx) { |
| 4500 | switch (Name.getNameKind()) { |
| 4501 | case DeclarationName::CXXConstructorName: |
| 4502 | case DeclarationName::CXXDestructorName: |
| 4503 | case DeclarationName::CXXConversionFunctionName: |
| 4504 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4505 | break; |
| 4506 | |
| 4507 | case DeclarationName::CXXOperatorName: |
| 4508 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4509 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4510 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4511 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4512 | break; |
| 4513 | |
| 4514 | case DeclarationName::CXXLiteralOperatorName: |
| 4515 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4516 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4517 | break; |
| 4518 | |
| 4519 | case DeclarationName::Identifier: |
| 4520 | case DeclarationName::ObjCZeroArgSelector: |
| 4521 | case DeclarationName::ObjCOneArgSelector: |
| 4522 | case DeclarationName::ObjCMultiArgSelector: |
| 4523 | case DeclarationName::CXXUsingDirective: |
| 4524 | break; |
| 4525 | } |
| 4526 | } |
| 4527 | |
| 4528 | void ASTReader::ReadDeclarationNameInfo(PerFileData &F, |
| 4529 | DeclarationNameInfo &NameInfo, |
| 4530 | const RecordData &Record, unsigned &Idx) { |
| 4531 | NameInfo.setName(ReadDeclarationName(Record, Idx)); |
| 4532 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4533 | DeclarationNameLoc DNLoc; |
| 4534 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4535 | NameInfo.setInfo(DNLoc); |
| 4536 | } |
| 4537 | |
| 4538 | void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info, |
| 4539 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4540 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4541 | unsigned NumTPLists = Record[Idx++]; |
| 4542 | Info.NumTemplParamLists = NumTPLists; |
| 4543 | if (NumTPLists) { |
| 4544 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 4545 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4546 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4547 | } |
| 4548 | } |
| 4549 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4550 | TemplateName |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4551 | ASTReader::ReadTemplateName(PerFileData &F, const RecordData &Record, |
| 4552 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4553 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4554 | switch (Kind) { |
| 4555 | case TemplateName::Template: |
| 4556 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 4557 | |
| 4558 | case TemplateName::OverloadedTemplate: { |
| 4559 | unsigned size = Record[Idx++]; |
| 4560 | UnresolvedSet<8> Decls; |
| 4561 | while (size--) |
| 4562 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 4563 | |
| 4564 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 4565 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4566 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4567 | case TemplateName::QualifiedTemplate: { |
| 4568 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4569 | bool hasTemplKeyword = Record[Idx++]; |
| 4570 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 4571 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 4572 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4573 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4574 | case TemplateName::DependentTemplate: { |
| 4575 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4576 | if (Record[Idx++]) // isIdentifier |
| 4577 | return Context->getDependentTemplateName(NNS, |
| 4578 | GetIdentifierInfo(Record, Idx)); |
| 4579 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4580 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4581 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4582 | |
| 4583 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4584 | TemplateTemplateParmDecl *Param |
| 4585 | = cast_or_null<TemplateTemplateParmDecl>(GetDecl(Record[Idx++])); |
| 4586 | if (!Param) |
| 4587 | return TemplateName(); |
| 4588 | |
| 4589 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 4590 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 4591 | return TemplateName(); |
| 4592 | |
| 4593 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 4594 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4595 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4596 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4597 | assert(0 && "Unhandled template name kind!"); |
| 4598 | return TemplateName(); |
| 4599 | } |
| 4600 | |
| 4601 | TemplateArgument |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4602 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4603 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4604 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 4605 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4606 | case TemplateArgument::Null: |
| 4607 | return TemplateArgument(); |
| 4608 | case TemplateArgument::Type: |
| 4609 | return TemplateArgument(GetType(Record[Idx++])); |
| 4610 | case TemplateArgument::Declaration: |
| 4611 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4612 | case TemplateArgument::Integral: { |
| 4613 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 4614 | QualType T = GetType(Record[Idx++]); |
| 4615 | return TemplateArgument(Value, T); |
| 4616 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4617 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4618 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4619 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4620 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4621 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 4622 | if (unsigned NumExpansions = Record[Idx++]) |
| 4623 | NumTemplateExpansions = NumExpansions - 1; |
| 4624 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4625 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4626 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4627 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4628 | case TemplateArgument::Pack: { |
| 4629 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4630 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 4631 | for (unsigned I = 0; I != NumArgs; ++I) |
| 4632 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 4633 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4634 | } |
| 4635 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4636 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4637 | assert(0 && "Unhandled template argument kind!"); |
| 4638 | return TemplateArgument(); |
| 4639 | } |
| 4640 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4641 | TemplateParameterList * |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4642 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 4643 | const RecordData &Record, unsigned &Idx) { |
| 4644 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 4645 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 4646 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4647 | |
| 4648 | unsigned NumParams = Record[Idx++]; |
| 4649 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 4650 | Params.reserve(NumParams); |
| 4651 | while (NumParams--) |
| 4652 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4653 | |
| 4654 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4655 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 4656 | Params.data(), Params.size(), RAngleLoc); |
| 4657 | return TemplateParams; |
| 4658 | } |
| 4659 | |
| 4660 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4661 | ASTReader:: |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4662 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4663 | PerFileData &F, const RecordData &Record, |
| 4664 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4665 | unsigned NumTemplateArgs = Record[Idx++]; |
| 4666 | TemplArgs.reserve(NumTemplateArgs); |
| 4667 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4668 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4669 | } |
| 4670 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4671 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4672 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4673 | const RecordData &Record, unsigned &Idx) { |
| 4674 | unsigned NumDecls = Record[Idx++]; |
| 4675 | while (NumDecls--) { |
| 4676 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 4677 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 4678 | Set.addDecl(D, AS); |
| 4679 | } |
| 4680 | } |
| 4681 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4682 | CXXBaseSpecifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4683 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4684 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4685 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 4686 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 4687 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4688 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4689 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4690 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4691 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4692 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4693 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4694 | Result.setInheritConstructors(inheritConstructors); |
| 4695 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4696 | } |
| 4697 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4698 | std::pair<CXXCtorInitializer **, unsigned> |
| 4699 | ASTReader::ReadCXXCtorInitializers(PerFileData &F, const RecordData &Record, |
| 4700 | unsigned &Idx) { |
| 4701 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4702 | unsigned NumInitializers = Record[Idx++]; |
| 4703 | if (NumInitializers) { |
| 4704 | ASTContext &C = *getContext(); |
| 4705 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4706 | CtorInitializers |
| 4707 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4708 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 4709 | TypeSourceInfo *BaseClassInfo = 0; |
| 4710 | bool IsBaseVirtual = false; |
| 4711 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4712 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4713 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4714 | bool IsBaseInitializer = Record[Idx++]; |
| 4715 | if (IsBaseInitializer) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4716 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4717 | IsBaseVirtual = Record[Idx++]; |
| 4718 | } else { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4719 | bool IsIndirectMemberInitializer = Record[Idx++]; |
| 4720 | if (IsIndirectMemberInitializer) |
| 4721 | IndirectMember = cast<IndirectFieldDecl>(GetDecl(Record[Idx++])); |
| 4722 | else |
| 4723 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4724 | } |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 4725 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4726 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4727 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 4728 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4729 | bool IsWritten = Record[Idx++]; |
| 4730 | unsigned SourceOrderOrNumArrayIndices; |
| 4731 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 4732 | if (IsWritten) { |
| 4733 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4734 | } else { |
| 4735 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4736 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 4737 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 4738 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 4739 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4740 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4741 | CXXCtorInitializer *BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4742 | if (IsBaseInitializer) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4743 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 4744 | LParenLoc, Init, RParenLoc, |
| 4745 | MemberOrEllipsisLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4746 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4747 | if (Member) |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4748 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 4749 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4750 | else |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4751 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 4752 | MemberOrEllipsisLoc, LParenLoc, |
| 4753 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4754 | } else { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4755 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 4756 | LParenLoc, Init, RParenLoc, |
| 4757 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4758 | } |
| 4759 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 4760 | if (IsWritten) |
| 4761 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4762 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4763 | } |
| 4764 | } |
| 4765 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4766 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4767 | } |
| 4768 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4769 | NestedNameSpecifier * |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4770 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4771 | unsigned N = Record[Idx++]; |
| 4772 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 4773 | for (unsigned I = 0; I != N; ++I) { |
| 4774 | NestedNameSpecifier::SpecifierKind Kind |
| 4775 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4776 | switch (Kind) { |
| 4777 | case NestedNameSpecifier::Identifier: { |
| 4778 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 4779 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 4780 | break; |
| 4781 | } |
| 4782 | |
| 4783 | case NestedNameSpecifier::Namespace: { |
| 4784 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 4785 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 4786 | break; |
| 4787 | } |
| 4788 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 4789 | case NestedNameSpecifier::NamespaceAlias: { |
| 4790 | NamespaceAliasDecl *Alias |
| 4791 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
| 4792 | NNS = NestedNameSpecifier::Create(*Context, Prev, Alias); |
| 4793 | break; |
| 4794 | } |
| 4795 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4796 | case NestedNameSpecifier::TypeSpec: |
| 4797 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4798 | const Type *T = GetType(Record[Idx++]).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 4799 | if (!T) |
| 4800 | return 0; |
| 4801 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4802 | bool Template = Record[Idx++]; |
| 4803 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 4804 | break; |
| 4805 | } |
| 4806 | |
| 4807 | case NestedNameSpecifier::Global: { |
| 4808 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4809 | // No associated value, and there can't be a prefix. |
| 4810 | break; |
| 4811 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4812 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 4813 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4814 | } |
| 4815 | return NNS; |
| 4816 | } |
| 4817 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4818 | NestedNameSpecifierLoc |
| 4819 | ASTReader::ReadNestedNameSpecifierLoc(PerFileData &F, const RecordData &Record, |
| 4820 | unsigned &Idx) { |
| 4821 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4822 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4823 | for (unsigned I = 0; I != N; ++I) { |
| 4824 | NestedNameSpecifier::SpecifierKind Kind |
| 4825 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4826 | switch (Kind) { |
| 4827 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4828 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4829 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4830 | Builder.Extend(*Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4831 | break; |
| 4832 | } |
| 4833 | |
| 4834 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4835 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4836 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4837 | Builder.Extend(*Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4838 | break; |
| 4839 | } |
| 4840 | |
| 4841 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4842 | NamespaceAliasDecl *Alias |
| 4843 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4844 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4845 | Builder.Extend(*Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4846 | break; |
| 4847 | } |
| 4848 | |
| 4849 | case NestedNameSpecifier::TypeSpec: |
| 4850 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4851 | bool Template = Record[Idx++]; |
| 4852 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 4853 | if (!T) |
| 4854 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4855 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4856 | |
| 4857 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
| 4858 | Builder.Extend(*Context, |
| 4859 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 4860 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4861 | break; |
| 4862 | } |
| 4863 | |
| 4864 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4865 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4866 | Builder.MakeGlobal(*Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4867 | break; |
| 4868 | } |
| 4869 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4870 | } |
| 4871 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 4872 | return Builder.getWithLocInContext(*Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4873 | } |
| 4874 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4875 | SourceRange |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4876 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 4877 | unsigned &Idx) { |
| 4878 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 4879 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 4880 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4881 | } |
| 4882 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4883 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4884 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4885 | unsigned BitWidth = Record[Idx++]; |
| 4886 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 4887 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 4888 | Idx += NumWords; |
| 4889 | return Result; |
| 4890 | } |
| 4891 | |
| 4892 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4893 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4894 | bool isUnsigned = Record[Idx++]; |
| 4895 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 4896 | } |
| 4897 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4898 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4899 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4900 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 4901 | } |
| 4902 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4903 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4904 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4905 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 4906 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4907 | Idx += Len; |
| 4908 | return Result; |
| 4909 | } |
| 4910 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4911 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 4912 | unsigned &Idx) { |
| 4913 | unsigned Major = Record[Idx++]; |
| 4914 | unsigned Minor = Record[Idx++]; |
| 4915 | unsigned Subminor = Record[Idx++]; |
| 4916 | if (Minor == 0) |
| 4917 | return VersionTuple(Major); |
| 4918 | if (Subminor == 0) |
| 4919 | return VersionTuple(Major, Minor - 1); |
| 4920 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 4921 | } |
| 4922 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4923 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4924 | unsigned &Idx) { |
| 4925 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 4926 | return CXXTemporary::Create(*Context, Decl); |
| 4927 | } |
| 4928 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4929 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 4930 | return Diag(SourceLocation(), DiagID); |
| 4931 | } |
| 4932 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4933 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4934 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4935 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4936 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4937 | /// \brief Retrieve the identifier table associated with the |
| 4938 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4939 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4940 | assert(PP && "Forgot to set Preprocessor ?"); |
| 4941 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4944 | /// \brief Record that the given ID maps to the given switch-case |
| 4945 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4946 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4947 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 4948 | SwitchCaseStmts[ID] = SC; |
| 4949 | } |
| 4950 | |
| 4951 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4952 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4953 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 4954 | return SwitchCaseStmts[ID]; |
| 4955 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4956 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4957 | void ASTReader::ClearSwitchCaseIDs() { |
| 4958 | SwitchCaseStmts.clear(); |
| 4959 | } |
| 4960 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4961 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4962 | assert(NumCurrentElementsDeserializing && |
| 4963 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 4964 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4965 | // If any identifiers with corresponding top-level declarations have |
| 4966 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4967 | while (!PendingIdentifierInfos.empty()) { |
| 4968 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 4969 | PendingIdentifierInfos.front().DeclIDs, true); |
| 4970 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4971 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4972 | |
Argyrios Kyrtzidis | 0895d15 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 4973 | // Ready to load previous declarations of Decls that were delayed. |
| 4974 | while (!PendingPreviousDecls.empty()) { |
| 4975 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 4976 | PendingPreviousDecls.front().second); |
| 4977 | PendingPreviousDecls.pop_front(); |
| 4978 | } |
| 4979 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4980 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 4981 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4982 | if (Consumer) |
| 4983 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 4984 | |
| 4985 | assert(PendingForwardRefs.size() == 0 && |
| 4986 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4987 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4988 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4989 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4990 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4991 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4992 | const char *isysroot, bool DisableValidation, |
| 4993 | bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4994 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 4995 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 4996 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
| 4997 | Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 4998 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 4999 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), NextSLocOffset(0), |
| 5000 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 5001 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 5002 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 5003 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
| 5004 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 5005 | NumCurrentElementsDeserializing(0) |
| 5006 | { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5007 | RelocatablePCH = false; |
| 5008 | } |
| 5009 | |
| 5010 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 5011 | Diagnostic &Diags, const char *isysroot, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5012 | bool DisableValidation, bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5013 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
| 5014 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5015 | isysroot(isysroot), DisableValidation(DisableValidation), |
| 5016 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 5017 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 5018 | NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0), |
| 5019 | NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), |
| 5020 | NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
| 5021 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 5022 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 5023 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5024 | RelocatablePCH = false; |
| 5025 | } |
| 5026 | |
| 5027 | ASTReader::~ASTReader() { |
| 5028 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 5029 | delete Chain[e - i - 1]; |
| 5030 | // Delete all visible decl lookup tables |
| 5031 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 5032 | E = DeclContextOffsets.end(); |
| 5033 | I != E; ++I) { |
| 5034 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 5035 | J != F; ++J) { |
| 5036 | if (J->NameLookupTableData) |
| 5037 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 5038 | J->NameLookupTableData); |
| 5039 | } |
| 5040 | } |
| 5041 | for (DeclContextVisibleUpdatesPending::iterator |
| 5042 | I = PendingVisibleUpdates.begin(), |
| 5043 | E = PendingVisibleUpdates.end(); |
| 5044 | I != E; ++I) { |
| 5045 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5046 | F = I->second.end(); |
| 5047 | J != F; ++J) |
| 5048 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 5049 | } |
| 5050 | } |
| 5051 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 5052 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
| 5053 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5054 | LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), |
| 5055 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5056 | MacroDefinitionOffsets(0), |
| 5057 | LocalNumHeaderFileInfos(0), HeaderFileInfoTableData(0), |
| 5058 | HeaderFileInfoTable(0), |
| 5059 | LocalNumSelectors(0), SelectorOffsets(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5060 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5061 | DeclOffsets(0), LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
| 5062 | LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 5063 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5064 | {} |
| 5065 | |
| 5066 | ASTReader::PerFileData::~PerFileData() { |
| 5067 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5068 | delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5069 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 5070 | } |