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); |
Douglas Gregor | 74da19f | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 95 | PARSE_LANGOPT_BENIGN(ObjCInferRelatedResultType) |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 96 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 97 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 98 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 99 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 100 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 101 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 102 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 103 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 104 | PARSE_LANGOPT_IMPORTANT(ObjCExceptions, diag::warn_pch_objc_exceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 105 | PARSE_LANGOPT_IMPORTANT(CXXExceptions, diag::warn_pch_cxx_exceptions); |
| 106 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 107 | PARSE_LANGOPT_IMPORTANT(MSBitfields, diag::warn_pch_ms_bitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 108 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 109 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 110 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 111 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 112 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 113 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 114 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 115 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 116 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 117 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 118 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 119 | diag::warn_pch_heinous_extensions); |
| 120 | // FIXME: Most of the options below are benign if the macro wasn't |
| 121 | // used. Unfortunately, this means that a PCH compiled without |
| 122 | // optimization can't be used with optimization turned on, even |
| 123 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 124 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 125 | // doesn't matter. We could consider making this some special kind |
| 126 | // of check. |
| 127 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 128 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 129 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 130 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 131 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 132 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
Chandler Carruth | 0d2d1bc | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 133 | PARSE_LANGOPT_IMPORTANT(Deprecated, diag::warn_pch_deprecated); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 134 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 135 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 136 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 137 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 138 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 139 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 140 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 141 | return true; |
| 142 | } |
| 143 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 144 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 145 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 146 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 147 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 148 | PARSE_LANGOPT_IMPORTANT(CUDA, diag::warn_pch_cuda); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 149 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 150 | PARSE_LANGOPT_BENIGN(DefaultFPContract); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 151 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 152 | PARSE_LANGOPT_BENIGN(SpellChecking); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 153 | PARSE_LANGOPT_IMPORTANT(ObjCAutoRefCount, diag::warn_pch_auto_ref_count); |
| 154 | PARSE_LANGOPT_BENIGN(ObjCInferRelatedReturnType); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 155 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 156 | #undef PARSE_LANGOPT_BENIGN |
| 157 | |
| 158 | return false; |
| 159 | } |
| 160 | |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 161 | bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) { |
| 162 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 163 | return false; |
| 164 | |
| 165 | Reader.Diag(diag::warn_pch_target_triple) |
| 166 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 167 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 170 | namespace { |
| 171 | struct EmptyStringRef { |
| 172 | bool operator ()(llvm::StringRef r) const { return r.empty(); } |
| 173 | }; |
| 174 | struct EmptyBlock { |
| 175 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 176 | }; |
| 177 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 178 | |
| 179 | static bool EqualConcatenations(llvm::SmallVector<llvm::StringRef, 2> L, |
| 180 | PCHPredefinesBlocks R) { |
| 181 | // First, sum up the lengths. |
| 182 | unsigned LL = 0, RL = 0; |
| 183 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 184 | LL += L[I].size(); |
| 185 | } |
| 186 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 187 | RL += R[I].Data.size(); |
| 188 | } |
| 189 | if (LL != RL) |
| 190 | return false; |
| 191 | if (LL == 0 && RL == 0) |
| 192 | return true; |
| 193 | |
| 194 | // Kick out empty parts, they confuse the algorithm below. |
| 195 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 196 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 197 | |
| 198 | // Do it the hard way. At this point, both vectors must be non-empty. |
| 199 | llvm::StringRef LR = L[0], RR = R[0].Data; |
| 200 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 201 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 202 | for (;;) { |
| 203 | // Compare the current pieces. |
| 204 | if (LR.size() == RR.size()) { |
| 205 | // If they're the same length, it's pretty easy. |
| 206 | if (LR != RR) |
| 207 | return false; |
| 208 | // Both pieces are done, advance. |
| 209 | ++LI; |
| 210 | ++RI; |
| 211 | // If either string is done, they're both done, since they're the same |
| 212 | // length. |
| 213 | if (LI == LN) { |
| 214 | assert(RI == RN && "Strings not the same length after all?"); |
| 215 | return true; |
| 216 | } |
| 217 | LR = L[LI]; |
| 218 | RR = R[RI].Data; |
| 219 | } else if (LR.size() < RR.size()) { |
| 220 | // Right piece is longer. |
| 221 | if (!RR.startswith(LR)) |
| 222 | return false; |
| 223 | ++LI; |
| 224 | assert(LI != LN && "Strings not the same length after all?"); |
| 225 | RR = RR.substr(LR.size()); |
| 226 | LR = L[LI]; |
| 227 | } else { |
| 228 | // Left piece is longer. |
| 229 | if (!LR.startswith(RR)) |
| 230 | return false; |
| 231 | ++RI; |
| 232 | assert(RI != RN && "Strings not the same length after all?"); |
| 233 | LR = LR.substr(RR.size()); |
| 234 | RR = R[RI].Data; |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | static std::pair<FileID, llvm::StringRef::size_type> |
| 240 | FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) { |
| 241 | std::pair<FileID, llvm::StringRef::size_type> Res; |
| 242 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 243 | Res.second = Buffers[I].Data.find(MacroDef); |
| 244 | if (Res.second != llvm::StringRef::npos) { |
| 245 | Res.first = Buffers[I].BufferID; |
| 246 | break; |
| 247 | } |
| 248 | } |
| 249 | return Res; |
| 250 | } |
| 251 | |
| 252 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 253 | llvm::StringRef OriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 254 | std::string &SuggestedPredefines, |
| 255 | FileManager &FileMgr) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 256 | // We are in the context of an implicit include, so the predefines buffer will |
| 257 | // have a #include entry for the PCH file itself (as normalized by the |
| 258 | // preprocessor initialization). Find it and skip over it in the checking |
| 259 | // below. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 260 | llvm::SmallString<256> PCHInclude; |
| 261 | PCHInclude += "#include \""; |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 262 | PCHInclude += NormalizeDashIncludePath(OriginalFileName, FileMgr); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 263 | PCHInclude += "\"\n"; |
| 264 | std::pair<llvm::StringRef,llvm::StringRef> Split = |
| 265 | llvm::StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 266 | llvm::StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 267 | if (Left == PP.getPredefines()) { |
| 268 | Error("Missing PCH include entry!"); |
| 269 | return true; |
| 270 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 271 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 272 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 273 | // command line, we're done. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 274 | llvm::SmallVector<llvm::StringRef, 2> CommandLine; |
| 275 | CommandLine.push_back(Left); |
| 276 | CommandLine.push_back(Right); |
| 277 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 278 | return false; |
| 279 | |
| 280 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 281 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 282 | // The predefines buffers are different. Determine what the differences are, |
| 283 | // and whether they require us to reject the PCH file. |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 284 | llvm::SmallVector<llvm::StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 285 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 286 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 287 | |
| 288 | llvm::SmallVector<llvm::StringRef, 8> CmdLineLines; |
| 289 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 290 | |
| 291 | // Pick out implicit #includes after the PCH and don't consider them for |
| 292 | // validation; we will insert them into SuggestedPredefines so that the |
| 293 | // preprocessor includes them. |
| 294 | std::string IncludesAfterPCH; |
| 295 | llvm::SmallVector<llvm::StringRef, 8> AfterPCHLines; |
| 296 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 297 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 298 | if (AfterPCHLines[i].startswith("#include ")) { |
| 299 | IncludesAfterPCH += AfterPCHLines[i]; |
| 300 | IncludesAfterPCH += '\n'; |
| 301 | } else { |
| 302 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | // Make sure we add the includes last into SuggestedPredefines before we |
| 307 | // exit this function. |
| 308 | struct AddIncludesRAII { |
| 309 | std::string &SuggestedPredefines; |
| 310 | std::string &IncludesAfterPCH; |
| 311 | |
| 312 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 313 | std::string &IncludesAfterPCH) |
| 314 | : SuggestedPredefines(SuggestedPredefines), |
| 315 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 316 | ~AddIncludesRAII() { |
| 317 | SuggestedPredefines += IncludesAfterPCH; |
| 318 | } |
| 319 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 320 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 321 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 322 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 323 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 324 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 325 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 326 | // Determine which predefines that were used to build the PCH file are missing |
| 327 | // from the command line. |
| 328 | std::vector<llvm::StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 329 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 330 | CmdLineLines.begin(), CmdLineLines.end(), |
| 331 | std::back_inserter(MissingPredefines)); |
| 332 | |
| 333 | bool MissingDefines = false; |
| 334 | bool ConflictingDefines = false; |
| 335 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 336 | llvm::StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 337 | if (Missing.startswith("#include ")) { |
| 338 | // An -include was specified when generating the PCH; it is included in |
| 339 | // the PCH, just ignore it. |
| 340 | continue; |
| 341 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 342 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 343 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 344 | return true; |
| 345 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 346 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 347 | // This is a macro definition. Determine the name of the macro we're |
| 348 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 349 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 350 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 351 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 352 | assert(EndOfMacroName != std::string::npos && |
| 353 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 354 | llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 355 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 356 | // Determine whether this macro was given a different definition on the |
| 357 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 358 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 359 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 360 | llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 361 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 362 | MacroDefStart); |
| 363 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 364 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 365 | // Different macro; we're done. |
| 366 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 367 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 368 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 369 | |
| 370 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 371 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 372 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 373 | (*ConflictPos)[MacroDefLen] != '(') |
| 374 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 376 | // We found a conflicting macro definition. |
| 377 | break; |
| 378 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 379 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 380 | if (ConflictPos != CmdLineLines.end()) { |
| 381 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 382 | << MacroName; |
| 383 | |
| 384 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 385 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 386 | FindMacro(Buffers, Missing); |
| 387 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 388 | SourceLocation PCHMissingLoc = |
| 389 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 390 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 391 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 392 | |
| 393 | ConflictingDefines = true; |
| 394 | continue; |
| 395 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 396 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 397 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 398 | // 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] | 399 | if (ConflictingDefines) |
| 400 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 402 | if (!MissingDefines) { |
| 403 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 404 | MissingDefines = true; |
| 405 | } |
| 406 | |
| 407 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 408 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 409 | FindMacro(Buffers, Missing); |
| 410 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 411 | SourceLocation PCHMissingLoc = |
| 412 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 413 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 414 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 415 | } |
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 | if (ConflictingDefines) |
| 418 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 419 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 420 | // Determine what predefines were introduced based on command-line |
| 421 | // parameters that were not present when building the PCH |
| 422 | // file. Extra #defines are okay, so long as the identifiers being |
| 423 | // defined were not used within the precompiled header. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 424 | std::vector<llvm::StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 425 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 426 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 427 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 428 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 429 | llvm::StringRef &Extra = ExtraPredefines[I]; |
| 430 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 431 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 432 | return true; |
| 433 | } |
| 434 | |
| 435 | // This is an extra macro definition. Determine the name of the |
| 436 | // macro we're defining. |
| 437 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 438 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 439 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 440 | assert(EndOfMacroName != std::string::npos && |
| 441 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 442 | llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 443 | |
| 444 | // Check whether this name was used somewhere in the PCH file. If |
| 445 | // so, defining it as a macro could change behavior, so we reject |
| 446 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 447 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 448 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 449 | return true; |
| 450 | } |
| 451 | |
| 452 | // Add this definition to the suggested predefines buffer. |
| 453 | SuggestedPredefines += Extra; |
| 454 | SuggestedPredefines += '\n'; |
| 455 | } |
| 456 | |
| 457 | // If we get here, it's because the predefines buffer had compatible |
| 458 | // contents. Accept the PCH file. |
| 459 | return false; |
| 460 | } |
| 461 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 462 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 463 | unsigned ID) { |
| 464 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 465 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | void PCHValidator::ReadCounter(unsigned Value) { |
| 469 | PP.setCounterValue(Value); |
| 470 | } |
| 471 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 472 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 473 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 474 | //===----------------------------------------------------------------------===// |
| 475 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 476 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 477 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 478 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 479 | } |
| 480 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 481 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 482 | namespace { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 483 | class ASTSelectorLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 484 | ASTReader &Reader; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 485 | |
| 486 | public: |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 487 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 488 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 489 | ObjCMethodList Instance, Factory; |
| 490 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 491 | |
| 492 | typedef Selector external_key_type; |
| 493 | typedef external_key_type internal_key_type; |
| 494 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 495 | explicit ASTSelectorLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 496 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 497 | static bool EqualKey(const internal_key_type& a, |
| 498 | const internal_key_type& b) { |
| 499 | return a == b; |
| 500 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 501 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 502 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 503 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 504 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 505 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 506 | // This hopefully will just get inlined and removed by the optimizer. |
| 507 | static const internal_key_type& |
| 508 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 509 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 510 | static std::pair<unsigned, unsigned> |
| 511 | ReadKeyDataLength(const unsigned char*& d) { |
| 512 | using namespace clang::io; |
| 513 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 514 | unsigned DataLen = ReadUnalignedLE16(d); |
| 515 | return std::make_pair(KeyLen, DataLen); |
| 516 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 517 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 518 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 519 | using namespace clang::io; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 520 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 521 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 522 | IdentifierInfo *FirstII |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 523 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 524 | if (N == 0) |
| 525 | return SelTable.getNullarySelector(FirstII); |
| 526 | else if (N == 1) |
| 527 | return SelTable.getUnarySelector(FirstII); |
| 528 | |
| 529 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 530 | Args.push_back(FirstII); |
| 531 | for (unsigned I = 1; I != N; ++I) |
| 532 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 533 | |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 534 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 535 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 536 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 537 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 538 | using namespace clang::io; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 539 | |
| 540 | data_type Result; |
| 541 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 542 | Result.ID = ReadUnalignedLE32(d); |
| 543 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 544 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 545 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 546 | // Load instance methods |
| 547 | ObjCMethodList *Prev = 0; |
| 548 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 549 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 550 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 551 | if (!Result.Instance.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 552 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 553 | Result.Instance.Method = Method; |
| 554 | Prev = &Result.Instance; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 555 | continue; |
| 556 | } |
| 557 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 558 | ObjCMethodList *Mem = |
| 559 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 560 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 561 | Prev = Prev->Next; |
| 562 | } |
| 563 | |
| 564 | // Load factory methods |
| 565 | Prev = 0; |
| 566 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 567 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 568 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 569 | if (!Result.Factory.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 570 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 571 | Result.Factory.Method = Method; |
| 572 | Prev = &Result.Factory; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 573 | continue; |
| 574 | } |
| 575 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 576 | ObjCMethodList *Mem = |
| 577 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 578 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 579 | Prev = Prev->Next; |
| 580 | } |
| 581 | |
| 582 | return Result; |
| 583 | } |
| 584 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 585 | |
| 586 | } // end anonymous namespace |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 587 | |
| 588 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 589 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 590 | ASTSelectorLookupTable; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 591 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 592 | namespace clang { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 593 | class ASTIdentifierLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 594 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 595 | ASTReader::PerFileData &F; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 596 | |
| 597 | // If we know the IdentifierInfo in advance, it is here and we will |
| 598 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 599 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 600 | IdentifierInfo *KnownII; |
| 601 | |
| 602 | public: |
| 603 | typedef IdentifierInfo * data_type; |
| 604 | |
| 605 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 606 | |
| 607 | typedef external_key_type internal_key_type; |
| 608 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 609 | ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 610 | IdentifierInfo *II = 0) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 611 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 612 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 613 | static bool EqualKey(const internal_key_type& a, |
| 614 | const internal_key_type& b) { |
| 615 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 616 | : false; |
| 617 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 618 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 619 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 620 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 621 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 622 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 623 | // This hopefully will just get inlined and removed by the optimizer. |
| 624 | static const internal_key_type& |
| 625 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 626 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 627 | // This hopefully will just get inlined and removed by the optimizer. |
| 628 | static const external_key_type& |
| 629 | GetExternalKey(const internal_key_type& x) { return x; } |
| 630 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 631 | static std::pair<unsigned, unsigned> |
| 632 | ReadKeyDataLength(const unsigned char*& d) { |
| 633 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 634 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 635 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 636 | return std::make_pair(KeyLen, DataLen); |
| 637 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 638 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 639 | static std::pair<const char*, unsigned> |
| 640 | ReadKey(const unsigned char* d, unsigned n) { |
| 641 | assert(n >= 2 && d[n-1] == '\0'); |
| 642 | return std::make_pair((const char*) d, n-1); |
| 643 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 644 | |
| 645 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 646 | const unsigned char* d, |
| 647 | unsigned DataLen) { |
| 648 | using namespace clang::io; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 649 | IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 650 | bool IsInteresting = ID & 0x01; |
| 651 | |
| 652 | // Wipe out the "is interesting" bit. |
| 653 | ID = ID >> 1; |
| 654 | |
| 655 | if (!IsInteresting) { |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 656 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 657 | // and associate it with the persistent ID. |
| 658 | IdentifierInfo *II = KnownII; |
| 659 | if (!II) |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 660 | II = &Reader.getIdentifierTable().getOwn(llvm::StringRef(k.first, |
| 661 | k.second)); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 662 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 663 | II->setIsFromAST(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 664 | return II; |
| 665 | } |
| 666 | |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 667 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 668 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 669 | Bits >>= 1; |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 670 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 671 | Bits >>= 1; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 672 | bool Poisoned = Bits & 0x01; |
| 673 | Bits >>= 1; |
| 674 | bool ExtensionToken = Bits & 0x01; |
| 675 | Bits >>= 1; |
| 676 | bool hasMacroDefinition = Bits & 0x01; |
| 677 | Bits >>= 1; |
| 678 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 679 | Bits >>= 10; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 680 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 681 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 682 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 683 | |
| 684 | // Build the IdentifierInfo itself and link the identifier ID with |
| 685 | // the new IdentifierInfo. |
| 686 | IdentifierInfo *II = KnownII; |
| 687 | if (!II) |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 688 | II = &Reader.getIdentifierTable().getOwn(llvm::StringRef(k.first, |
| 689 | k.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 690 | Reader.SetIdentifierInfo(ID, II); |
| 691 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 692 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 693 | // Token IDs are read-only. |
| 694 | if (HasRevertedTokenIDToIdentifier) |
| 695 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 696 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 697 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 698 | "Incorrect extension token flag"); |
| 699 | (void)ExtensionToken; |
| 700 | II->setIsPoisoned(Poisoned); |
| 701 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 702 | "Incorrect C++ operator keyword flag"); |
| 703 | (void)CPlusPlusOperatorKeyword; |
| 704 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 705 | // If this identifier is a macro, deserialize the macro |
| 706 | // definition. |
| 707 | if (hasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 708 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 709 | Reader.SetIdentifierIsMacro(II, F, Offset); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 710 | DataLen -= 4; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 711 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 712 | |
| 713 | // Read all of the declarations visible at global scope with this |
| 714 | // name. |
Chris Lattner | 6bf690f | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 715 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 716 | if (DataLen > 0) { |
| 717 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 718 | for (; DataLen > 0; DataLen -= 4) |
| 719 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 720 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 721 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 723 | II->setIsFromAST(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 724 | return II; |
| 725 | } |
| 726 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 727 | |
| 728 | } // end anonymous namespace |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 729 | |
| 730 | /// \brief The on-disk hash table used to contain information about |
| 731 | /// all of the identifiers in the program. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 732 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 733 | ASTIdentifierLookupTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 734 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 735 | namespace { |
| 736 | class ASTDeclContextNameLookupTrait { |
| 737 | ASTReader &Reader; |
| 738 | |
| 739 | public: |
| 740 | /// \brief Pair of begin/end iterators for DeclIDs. |
| 741 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 742 | |
| 743 | /// \brief Special internal key for declaration names. |
| 744 | /// The hash table creates keys for comparison; we do not create |
| 745 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 746 | struct DeclNameKey { |
| 747 | DeclarationName::NameKind Kind; |
| 748 | uint64_t Data; |
| 749 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 750 | }; |
| 751 | |
| 752 | typedef DeclarationName external_key_type; |
| 753 | typedef DeclNameKey internal_key_type; |
| 754 | |
| 755 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
| 756 | |
| 757 | static bool EqualKey(const internal_key_type& a, |
| 758 | const internal_key_type& b) { |
| 759 | return a.Kind == b.Kind && a.Data == b.Data; |
| 760 | } |
| 761 | |
| 762 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 763 | llvm::FoldingSetNodeID ID; |
| 764 | ID.AddInteger(Key.Kind); |
| 765 | |
| 766 | switch (Key.Kind) { |
| 767 | case DeclarationName::Identifier: |
| 768 | case DeclarationName::CXXLiteralOperatorName: |
| 769 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 770 | break; |
| 771 | case DeclarationName::ObjCZeroArgSelector: |
| 772 | case DeclarationName::ObjCOneArgSelector: |
| 773 | case DeclarationName::ObjCMultiArgSelector: |
| 774 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 775 | break; |
| 776 | case DeclarationName::CXXConstructorName: |
| 777 | case DeclarationName::CXXDestructorName: |
| 778 | case DeclarationName::CXXConversionFunctionName: |
| 779 | ID.AddInteger((TypeID)Key.Data); |
| 780 | break; |
| 781 | case DeclarationName::CXXOperatorName: |
| 782 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 783 | break; |
| 784 | case DeclarationName::CXXUsingDirective: |
| 785 | break; |
| 786 | } |
| 787 | |
| 788 | return ID.ComputeHash(); |
| 789 | } |
| 790 | |
| 791 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 792 | DeclNameKey Key; |
| 793 | Key.Kind = Name.getNameKind(); |
| 794 | switch (Name.getNameKind()) { |
| 795 | case DeclarationName::Identifier: |
| 796 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 797 | break; |
| 798 | case DeclarationName::ObjCZeroArgSelector: |
| 799 | case DeclarationName::ObjCOneArgSelector: |
| 800 | case DeclarationName::ObjCMultiArgSelector: |
| 801 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 802 | break; |
| 803 | case DeclarationName::CXXConstructorName: |
| 804 | case DeclarationName::CXXDestructorName: |
| 805 | case DeclarationName::CXXConversionFunctionName: |
| 806 | Key.Data = Reader.GetTypeID(Name.getCXXNameType()); |
| 807 | break; |
| 808 | case DeclarationName::CXXOperatorName: |
| 809 | Key.Data = Name.getCXXOverloadedOperator(); |
| 810 | break; |
| 811 | case DeclarationName::CXXLiteralOperatorName: |
| 812 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 813 | break; |
| 814 | case DeclarationName::CXXUsingDirective: |
| 815 | break; |
| 816 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 817 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 818 | return Key; |
| 819 | } |
| 820 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 821 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 822 | ASTContext *Context = Reader.getContext(); |
| 823 | switch (Key.Kind) { |
| 824 | case DeclarationName::Identifier: |
| 825 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 826 | |
| 827 | case DeclarationName::ObjCZeroArgSelector: |
| 828 | case DeclarationName::ObjCOneArgSelector: |
| 829 | case DeclarationName::ObjCMultiArgSelector: |
| 830 | return DeclarationName(Selector(Key.Data)); |
| 831 | |
| 832 | case DeclarationName::CXXConstructorName: |
| 833 | return Context->DeclarationNames.getCXXConstructorName( |
| 834 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 835 | |
| 836 | case DeclarationName::CXXDestructorName: |
| 837 | return Context->DeclarationNames.getCXXDestructorName( |
| 838 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 839 | |
| 840 | case DeclarationName::CXXConversionFunctionName: |
| 841 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 842 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 843 | |
| 844 | case DeclarationName::CXXOperatorName: |
| 845 | return Context->DeclarationNames.getCXXOperatorName( |
| 846 | (OverloadedOperatorKind)Key.Data); |
| 847 | |
| 848 | case DeclarationName::CXXLiteralOperatorName: |
| 849 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 850 | (IdentifierInfo*)Key.Data); |
| 851 | |
| 852 | case DeclarationName::CXXUsingDirective: |
| 853 | return DeclarationName::getUsingDirectiveName(); |
| 854 | } |
| 855 | |
| 856 | llvm_unreachable("Invalid Name Kind ?"); |
| 857 | } |
| 858 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 859 | static std::pair<unsigned, unsigned> |
| 860 | ReadKeyDataLength(const unsigned char*& d) { |
| 861 | using namespace clang::io; |
| 862 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 863 | unsigned DataLen = ReadUnalignedLE16(d); |
| 864 | return std::make_pair(KeyLen, DataLen); |
| 865 | } |
| 866 | |
| 867 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 868 | using namespace clang::io; |
| 869 | |
| 870 | DeclNameKey Key; |
| 871 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 872 | switch (Key.Kind) { |
| 873 | case DeclarationName::Identifier: |
| 874 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 875 | break; |
| 876 | case DeclarationName::ObjCZeroArgSelector: |
| 877 | case DeclarationName::ObjCOneArgSelector: |
| 878 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 879 | Key.Data = |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 880 | (uint64_t)Reader.DecodeSelector(ReadUnalignedLE32(d)).getAsOpaquePtr(); |
| 881 | break; |
| 882 | case DeclarationName::CXXConstructorName: |
| 883 | case DeclarationName::CXXDestructorName: |
| 884 | case DeclarationName::CXXConversionFunctionName: |
| 885 | Key.Data = ReadUnalignedLE32(d); // TypeID |
| 886 | break; |
| 887 | case DeclarationName::CXXOperatorName: |
| 888 | Key.Data = *d++; // OverloadedOperatorKind |
| 889 | break; |
| 890 | case DeclarationName::CXXLiteralOperatorName: |
| 891 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 892 | break; |
| 893 | case DeclarationName::CXXUsingDirective: |
| 894 | break; |
| 895 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 896 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 897 | return Key; |
| 898 | } |
| 899 | |
| 900 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 901 | unsigned DataLen) { |
| 902 | using namespace clang::io; |
| 903 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 904 | DeclID *Start = (DeclID *)d; |
| 905 | return std::make_pair(Start, Start + NumDecls); |
| 906 | } |
| 907 | }; |
| 908 | |
| 909 | } // end anonymous namespace |
| 910 | |
| 911 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 912 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 913 | ASTDeclContextNameLookupTable; |
| 914 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 915 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 916 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 917 | DeclContextInfo &Info) { |
| 918 | SavedStreamPosition SavedPosition(Cursor); |
| 919 | // First the lexical decls. |
| 920 | if (Offsets.first != 0) { |
| 921 | Cursor.JumpToBit(Offsets.first); |
| 922 | |
| 923 | RecordData Record; |
| 924 | const char *Blob; |
| 925 | unsigned BlobLen; |
| 926 | unsigned Code = Cursor.ReadCode(); |
| 927 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 928 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 929 | Error("Expected lexical block"); |
| 930 | return true; |
| 931 | } |
| 932 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 933 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 934 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 935 | } else { |
| 936 | Info.LexicalDecls = 0; |
| 937 | Info.NumLexicalDecls = 0; |
| 938 | } |
| 939 | |
| 940 | // Now the lookup table. |
| 941 | if (Offsets.second != 0) { |
| 942 | Cursor.JumpToBit(Offsets.second); |
| 943 | |
| 944 | RecordData Record; |
| 945 | const char *Blob; |
| 946 | unsigned BlobLen; |
| 947 | unsigned Code = Cursor.ReadCode(); |
| 948 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 949 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 950 | Error("Expected visible lookup table block"); |
| 951 | return true; |
| 952 | } |
| 953 | Info.NameLookupTableData |
| 954 | = ASTDeclContextNameLookupTable::Create( |
| 955 | (const unsigned char *)Blob + Record[0], |
| 956 | (const unsigned char *)Blob, |
| 957 | ASTDeclContextNameLookupTrait(*this)); |
Sebastian Redl | 0ea8f7f | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 958 | } else { |
| 959 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | return false; |
| 963 | } |
| 964 | |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 965 | void ASTReader::Error(llvm::StringRef Msg) { |
| 966 | Error(diag::err_fe_pch_malformed, Msg); |
| 967 | } |
| 968 | |
| 969 | void ASTReader::Error(unsigned DiagID, |
| 970 | llvm::StringRef Arg1, llvm::StringRef Arg2) { |
| 971 | if (Diags.isDiagnosticInFlight()) |
| 972 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 973 | else |
| 974 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 975 | } |
| 976 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 977 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 978 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 979 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 980 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 981 | ActualOriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 982 | SuggestedPredefines, |
| 983 | FileMgr); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 984 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 985 | } |
| 986 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 987 | //===----------------------------------------------------------------------===// |
| 988 | // Source Manager Deserialization |
| 989 | //===----------------------------------------------------------------------===// |
| 990 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 991 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 992 | /// \returns true if there was an error. |
| 993 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 994 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 995 | unsigned Idx = 0; |
| 996 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 997 | |
| 998 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 999 | std::map<int, int> FileIDs; |
| 1000 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1001 | // Extract the file name |
| 1002 | unsigned FilenameLen = Record[Idx++]; |
| 1003 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 1004 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1005 | MaybeAddSystemRootToFilename(Filename); |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 1006 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | // Parse the line entries |
| 1010 | std::vector<LineEntry> Entries; |
| 1011 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1012 | int FID = Record[Idx++]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1013 | |
| 1014 | // Extract the line entries |
| 1015 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1016 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1017 | Entries.clear(); |
| 1018 | Entries.reserve(NumEntries); |
| 1019 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1020 | unsigned FileOffset = Record[Idx++]; |
| 1021 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1022 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1023 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1024 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1025 | unsigned IncludeOffset = Record[Idx++]; |
| 1026 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1027 | FileKind, IncludeOffset)); |
| 1028 | } |
| 1029 | LineTable.AddEntry(FID, Entries); |
| 1030 | } |
| 1031 | |
| 1032 | return false; |
| 1033 | } |
| 1034 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1035 | namespace { |
| 1036 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1037 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1038 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1039 | const ino_t ino; |
| 1040 | const dev_t dev; |
| 1041 | const mode_t mode; |
| 1042 | const time_t mtime; |
| 1043 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1044 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1045 | 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] | 1046 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1047 | }; |
| 1048 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1049 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1050 | public: |
| 1051 | typedef const char *external_key_type; |
| 1052 | typedef const char *internal_key_type; |
| 1053 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1054 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1055 | |
| 1056 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1057 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1061 | |
| 1062 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1063 | return strcmp(a, b) == 0; |
| 1064 | } |
| 1065 | |
| 1066 | static std::pair<unsigned, unsigned> |
| 1067 | ReadKeyDataLength(const unsigned char*& d) { |
| 1068 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1069 | unsigned DataLen = (unsigned) *d++; |
| 1070 | return std::make_pair(KeyLen + 1, DataLen); |
| 1071 | } |
| 1072 | |
| 1073 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1074 | return (const char *)d; |
| 1075 | } |
| 1076 | |
| 1077 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1078 | unsigned /*DataLen*/) { |
| 1079 | using namespace clang::io; |
| 1080 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1081 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1082 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1083 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1084 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1085 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1086 | return data_type(ino, dev, mode, mtime, size); |
| 1087 | } |
| 1088 | }; |
| 1089 | |
| 1090 | /// \brief stat() cache for precompiled headers. |
| 1091 | /// |
| 1092 | /// This cache is very similar to the stat cache used by pretokenized |
| 1093 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1094 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1095 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1096 | CacheTy *Cache; |
| 1097 | |
| 1098 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1099 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1100 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1101 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1102 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1103 | Cache = CacheTy::Create(Buckets, Base); |
| 1104 | } |
| 1105 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1106 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1107 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1108 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1109 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1110 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1111 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1112 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1113 | // 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] | 1114 | if (I == Cache->end()) { |
| 1115 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1116 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1117 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1118 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1119 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1120 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1121 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1122 | StatBuf.st_ino = Data.ino; |
| 1123 | StatBuf.st_dev = Data.dev; |
| 1124 | StatBuf.st_mtime = Data.mtime; |
| 1125 | StatBuf.st_mode = Data.mode; |
| 1126 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1127 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1128 | } |
| 1129 | }; |
| 1130 | } // end anonymous namespace |
| 1131 | |
| 1132 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1133 | /// \brief Read a source manager block |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1134 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1135 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1136 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1137 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1138 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1139 | // Set the source-location entry cursor to the current position in |
| 1140 | // the stream. This cursor will be used to read the contents of the |
| 1141 | // source manager block initially, and then lazily read |
| 1142 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1143 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1144 | |
| 1145 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1146 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1147 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1148 | return Failure; |
| 1149 | } |
| 1150 | |
| 1151 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1152 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1153 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1154 | return Failure; |
| 1155 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1156 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1157 | RecordData Record; |
| 1158 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1159 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1160 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1161 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1162 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1163 | return Failure; |
| 1164 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1165 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1166 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1167 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1168 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1169 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1170 | SLocEntryCursor.ReadSubBlockID(); |
| 1171 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1172 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1173 | return Failure; |
| 1174 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1175 | continue; |
| 1176 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1177 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1178 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1179 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1180 | continue; |
| 1181 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1182 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1183 | // Read a record. |
| 1184 | const char *BlobStart; |
| 1185 | unsigned BlobLen; |
| 1186 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1187 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1188 | default: // Default behavior: ignore. |
| 1189 | break; |
| 1190 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1191 | case SM_LINE_TABLE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1192 | if (ParseLineTable(F, Record)) |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1193 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1194 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1195 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1196 | case SM_SLOC_FILE_ENTRY: |
| 1197 | case SM_SLOC_BUFFER_ENTRY: |
| 1198 | case SM_SLOC_INSTANTIATION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1199 | // Once we hit one of the source location entries, we're done. |
| 1200 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1201 | } |
| 1202 | } |
| 1203 | } |
| 1204 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1205 | /// \brief If a header file is not found at the path that we expect it to be |
| 1206 | /// and the PCH file was moved from its original location, try to resolve the |
| 1207 | /// file by assuming that header+PCH were moved together and the header is in |
| 1208 | /// the same place relative to the PCH. |
| 1209 | static std::string |
| 1210 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1211 | const std::string &OriginalDir, |
| 1212 | const std::string &CurrDir) { |
| 1213 | assert(OriginalDir != CurrDir && |
| 1214 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1215 | using namespace llvm::sys; |
| 1216 | llvm::SmallString<128> filePath(Filename); |
| 1217 | fs::make_absolute(filePath); |
| 1218 | assert(path::is_absolute(OriginalDir)); |
| 1219 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1220 | |
| 1221 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1222 | fileDirE = path::end(path::parent_path(filePath)); |
| 1223 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1224 | origDirE = path::end(OriginalDir); |
| 1225 | // Skip the common path components from filePath and OriginalDir. |
| 1226 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1227 | *fileDirI == *origDirI) { |
| 1228 | ++fileDirI; |
| 1229 | ++origDirI; |
| 1230 | } |
| 1231 | for (; origDirI != origDirE; ++origDirI) |
| 1232 | path::append(currPCHPath, ".."); |
| 1233 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1234 | path::append(currPCHPath, path::filename(Filename)); |
| 1235 | return currPCHPath.str(); |
| 1236 | } |
| 1237 | |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1238 | /// \brief Get a cursor that's correctly positioned for reading the source |
| 1239 | /// location entry with the given ID. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1240 | ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1241 | assert(ID != 0 && ID <= TotalNumSLocEntries && |
| 1242 | "SLocCursorForID should only be called for real IDs."); |
| 1243 | |
| 1244 | ID -= 1; |
| 1245 | PerFileData *F = 0; |
| 1246 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1247 | F = Chain[N - I - 1]; |
| 1248 | if (ID < F->LocalNumSLocEntries) |
| 1249 | break; |
| 1250 | ID -= F->LocalNumSLocEntries; |
| 1251 | } |
| 1252 | assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); |
| 1253 | |
| 1254 | F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1255 | return F; |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1258 | /// \brief Read in the source location entry with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1259 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1260 | if (ID == 0) |
| 1261 | return Success; |
| 1262 | |
| 1263 | if (ID > TotalNumSLocEntries) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1264 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1265 | return Failure; |
| 1266 | } |
| 1267 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1268 | PerFileData *F = SLocCursorForID(ID); |
| 1269 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1270 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1271 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1272 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1273 | if (Code == llvm::bitc::END_BLOCK || |
| 1274 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1275 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1276 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1277 | return Failure; |
| 1278 | } |
| 1279 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1280 | RecordData Record; |
| 1281 | const char *BlobStart; |
| 1282 | unsigned BlobLen; |
| 1283 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1284 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1285 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1286 | return Failure; |
| 1287 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1288 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1289 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1290 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1291 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1292 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1293 | OriginalDir != CurrentDir) { |
| 1294 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1295 | OriginalDir, |
| 1296 | CurrentDir); |
| 1297 | if (!resolved.empty()) |
| 1298 | File = FileMgr.getFile(resolved); |
| 1299 | } |
Axel Naumann | 0433116 | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1300 | if (File == 0) |
| 1301 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1302 | (time_t)Record[5]); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1303 | if (File == 0) { |
| 1304 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1305 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1306 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1307 | Error(ErrorStr.c_str()); |
| 1308 | return Failure; |
| 1309 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1310 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1311 | if (Record.size() < 6) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1312 | Error("source location entry is incorrect"); |
| 1313 | return Failure; |
| 1314 | } |
| 1315 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1316 | if (!DisableValidation && |
| 1317 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1318 | #if !defined(LLVM_ON_WIN32) |
| 1319 | // In our regression testing, the Windows file system seems to |
| 1320 | // have inconsistent modification times that sometimes |
| 1321 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1322 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1323 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1324 | )) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1325 | Error(diag::err_fe_pch_file_modified, Filename); |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1326 | return Failure; |
| 1327 | } |
| 1328 | |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1329 | FileID FID = SourceMgr.createFileID(File, ReadSourceLocation(*F, Record[1]), |
| 1330 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1331 | ID, Record[0]); |
| 1332 | if (Record[3]) |
| 1333 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1334 | .setHasLineDirectives(); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1335 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1336 | break; |
| 1337 | } |
| 1338 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1339 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1340 | const char *Name = BlobStart; |
| 1341 | unsigned Offset = Record[0]; |
| 1342 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1343 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1344 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1345 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1346 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1347 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1348 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1349 | return Failure; |
| 1350 | } |
| 1351 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1352 | llvm::MemoryBuffer *Buffer |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1353 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1354 | Name); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1355 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1356 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1357 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1358 | PCHPredefinesBlock Block = { |
| 1359 | BufferID, |
| 1360 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1361 | }; |
| 1362 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1363 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1364 | |
| 1365 | break; |
| 1366 | } |
| 1367 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1368 | case SM_SLOC_INSTANTIATION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1369 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1370 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1371 | ReadSourceLocation(*F, Record[2]), |
| 1372 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1373 | Record[4], |
| 1374 | ID, |
| 1375 | Record[0]); |
| 1376 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1377 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | return Success; |
| 1381 | } |
| 1382 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1383 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1384 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1385 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1386 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1387 | unsigned BlockID) { |
| 1388 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1389 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1390 | return Failure; |
| 1391 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1392 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1393 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1394 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1395 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1396 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1397 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1398 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1399 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1400 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1401 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1402 | Cursor.ReadAbbrevRecord(); |
| 1403 | } |
| 1404 | } |
| 1405 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1406 | PreprocessedEntity *ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1407 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1408 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1409 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1410 | // Keep track of where we are in the stream, then jump back there |
| 1411 | // after reading this macro. |
| 1412 | SavedStreamPosition SavedPosition(Stream); |
| 1413 | |
| 1414 | Stream.JumpToBit(Offset); |
| 1415 | RecordData Record; |
| 1416 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1417 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1418 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1419 | while (true) { |
| 1420 | unsigned Code = Stream.ReadCode(); |
| 1421 | switch (Code) { |
| 1422 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1423 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1424 | |
| 1425 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1426 | // No known subblocks, always skip them. |
| 1427 | Stream.ReadSubBlockID(); |
| 1428 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1429 | Error("malformed block record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1430 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1431 | } |
| 1432 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1433 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1434 | case llvm::bitc::DEFINE_ABBREV: |
| 1435 | Stream.ReadAbbrevRecord(); |
| 1436 | continue; |
| 1437 | default: break; |
| 1438 | } |
| 1439 | |
| 1440 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1441 | const char *BlobStart = 0; |
| 1442 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1443 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1444 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1445 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1446 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1447 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1448 | case PP_MACRO_OBJECT_LIKE: |
| 1449 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1450 | // If we already have a macro, that means that we've hit the end |
| 1451 | // of the definition of the macro we were looking for. We're |
| 1452 | // done. |
| 1453 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1454 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1455 | |
| 1456 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1457 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1458 | Error("macro must have a name in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1459 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1460 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1461 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1462 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1463 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1464 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1465 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1466 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1467 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1468 | unsigned NextIndex = 3; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1469 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1470 | // Decode function-like macro info. |
| 1471 | bool isC99VarArgs = Record[3]; |
| 1472 | bool isGNUVarArgs = Record[4]; |
| 1473 | MacroArgs.clear(); |
| 1474 | unsigned NumArgs = Record[5]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1475 | NextIndex = 6 + NumArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1476 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1477 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1478 | |
| 1479 | // Install function-like macro info. |
| 1480 | MI->setIsFunctionLike(); |
| 1481 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1482 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1483 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1484 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1488 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1489 | |
| 1490 | // Remember that we saw this macro last so that we add the tokens that |
| 1491 | // form its body to it. |
| 1492 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1493 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1494 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1495 | // We have a macro definition. Load it now. |
| 1496 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1497 | getMacroDefinition(Record[NextIndex])); |
| 1498 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1499 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1500 | ++NumMacrosRead; |
| 1501 | break; |
| 1502 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1503 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1504 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1505 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1506 | // erroneous, just pretend we didn't see this. |
| 1507 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1508 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1509 | Token Tok; |
| 1510 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1511 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1512 | Tok.setLength(Record[1]); |
| 1513 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1514 | Tok.setIdentifierInfo(II); |
| 1515 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1516 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1517 | Macro->AddTokenToBody(Tok); |
| 1518 | break; |
| 1519 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1520 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1521 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1522 | |
| 1523 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1526 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(PerFileData &F) { |
| 1527 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1528 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1529 | switch (Code) { |
| 1530 | case llvm::bitc::END_BLOCK: |
| 1531 | return 0; |
| 1532 | |
| 1533 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1534 | Error("unexpected subblock record in preprocessor detail block"); |
| 1535 | return 0; |
| 1536 | |
| 1537 | case llvm::bitc::DEFINE_ABBREV: |
| 1538 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1539 | return 0; |
| 1540 | |
| 1541 | default: |
| 1542 | break; |
| 1543 | } |
| 1544 | |
| 1545 | if (!PP->getPreprocessingRecord()) { |
| 1546 | Error("no preprocessing record"); |
| 1547 | return 0; |
| 1548 | } |
| 1549 | |
| 1550 | // Read the record. |
| 1551 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1552 | const char *BlobStart = 0; |
| 1553 | unsigned BlobLen = 0; |
| 1554 | RecordData Record; |
| 1555 | PreprocessorDetailRecordTypes RecType = |
| 1556 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1557 | Code, Record, BlobStart, BlobLen); |
| 1558 | switch (RecType) { |
| 1559 | case PPD_MACRO_INSTANTIATION: { |
| 1560 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1561 | return PE; |
| 1562 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame^] | 1563 | MacroExpansion *ME = |
| 1564 | new (PPRec) MacroExpansion(DecodeIdentifierInfo(Record[3]), |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1565 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1566 | ReadSourceLocation(F, Record[2])), |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame^] | 1567 | getMacroDefinition(Record[4])); |
| 1568 | PPRec.SetPreallocatedEntity(Record[0], ME); |
| 1569 | return ME; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | case PPD_MACRO_DEFINITION: { |
| 1573 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1574 | return PE; |
| 1575 | |
| 1576 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
| 1577 | Error("out-of-bounds macro definition record"); |
| 1578 | return 0; |
| 1579 | } |
| 1580 | |
| 1581 | // Decode the identifier info and then check again; if the macro is |
| 1582 | // still defined and associated with the identifier, |
| 1583 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1584 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1585 | MacroDefinition *MD |
| 1586 | = new (PPRec) MacroDefinition(II, |
| 1587 | ReadSourceLocation(F, Record[5]), |
| 1588 | SourceRange( |
| 1589 | ReadSourceLocation(F, Record[2]), |
| 1590 | ReadSourceLocation(F, Record[3]))); |
| 1591 | |
| 1592 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1593 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
| 1594 | |
| 1595 | if (DeserializationListener) |
| 1596 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1597 | } |
| 1598 | |
| 1599 | return MacroDefinitionsLoaded[Record[1] - 1]; |
| 1600 | } |
| 1601 | |
| 1602 | case PPD_INCLUSION_DIRECTIVE: { |
| 1603 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1604 | return PE; |
| 1605 | |
| 1606 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1607 | const FileEntry *File |
| 1608 | = PP->getFileManager().getFile(llvm::StringRef(FullFileNameStart, |
| 1609 | BlobLen - Record[3])); |
| 1610 | |
| 1611 | // FIXME: Stable encoding |
| 1612 | InclusionDirective::InclusionKind Kind |
| 1613 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1614 | InclusionDirective *ID |
| 1615 | = new (PPRec) InclusionDirective(PPRec, Kind, |
| 1616 | llvm::StringRef(BlobStart, Record[3]), |
| 1617 | Record[4], |
| 1618 | File, |
| 1619 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1620 | ReadSourceLocation(F, Record[2]))); |
| 1621 | PPRec.SetPreallocatedEntity(Record[0], ID); |
| 1622 | return ID; |
| 1623 | } |
| 1624 | } |
| 1625 | |
| 1626 | Error("invalid offset in preprocessor detail block"); |
| 1627 | return 0; |
| 1628 | } |
| 1629 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1630 | namespace { |
| 1631 | /// \brief Trait class used to search the on-disk hash table containing all of |
| 1632 | /// the header search information. |
| 1633 | /// |
| 1634 | /// The on-disk hash table contains a mapping from each header path to |
| 1635 | /// information about that header (how many times it has been included, its |
| 1636 | /// controlling macro, etc.). Note that we actually hash based on the |
| 1637 | /// filename, and support "deep" comparisons of file names based on current |
| 1638 | /// inode numbers, so that the search can cope with non-normalized path names |
| 1639 | /// and symlinks. |
| 1640 | class HeaderFileInfoTrait { |
| 1641 | const char *SearchPath; |
| 1642 | struct stat SearchPathStatBuf; |
| 1643 | llvm::Optional<int> SearchPathStatResult; |
| 1644 | |
| 1645 | int StatSimpleCache(const char *Path, struct stat *StatBuf) { |
| 1646 | if (Path == SearchPath) { |
| 1647 | if (!SearchPathStatResult) |
| 1648 | SearchPathStatResult = stat(Path, &SearchPathStatBuf); |
| 1649 | |
| 1650 | *StatBuf = SearchPathStatBuf; |
| 1651 | return *SearchPathStatResult; |
| 1652 | } |
| 1653 | |
| 1654 | return stat(Path, StatBuf); |
| 1655 | } |
| 1656 | |
| 1657 | public: |
| 1658 | typedef const char *external_key_type; |
| 1659 | typedef const char *internal_key_type; |
| 1660 | |
| 1661 | typedef HeaderFileInfo data_type; |
| 1662 | |
| 1663 | HeaderFileInfoTrait(const char *SearchPath = 0) : SearchPath(SearchPath) { } |
| 1664 | |
| 1665 | static unsigned ComputeHash(const char *path) { |
| 1666 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1667 | } |
| 1668 | |
| 1669 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1670 | |
| 1671 | bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1672 | if (strcmp(a, b) == 0) |
| 1673 | return true; |
| 1674 | |
| 1675 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1676 | return false; |
| 1677 | |
| 1678 | // The file names match, but the path names don't. stat() the files to |
| 1679 | // see if they are the same. |
| 1680 | struct stat StatBufA, StatBufB; |
| 1681 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1682 | return false; |
| 1683 | |
| 1684 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1685 | } |
| 1686 | |
| 1687 | static std::pair<unsigned, unsigned> |
| 1688 | ReadKeyDataLength(const unsigned char*& d) { |
| 1689 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1690 | unsigned DataLen = (unsigned) *d++; |
| 1691 | return std::make_pair(KeyLen + 1, DataLen); |
| 1692 | } |
| 1693 | |
| 1694 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1695 | return (const char *)d; |
| 1696 | } |
| 1697 | |
| 1698 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1699 | unsigned DataLen) { |
| 1700 | const unsigned char *End = d + DataLen; |
| 1701 | using namespace clang::io; |
| 1702 | HeaderFileInfo HFI; |
| 1703 | unsigned Flags = *d++; |
Douglas Gregor | dd3e554 | 2011-05-04 00:14:37 +0000 | [diff] [blame] | 1704 | HFI.isImport = (Flags >> 4) & 0x01; |
| 1705 | HFI.isPragmaOnce = (Flags >> 3) & 0x01; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1706 | HFI.DirInfo = (Flags >> 1) & 0x03; |
| 1707 | HFI.Resolved = Flags & 0x01; |
| 1708 | HFI.NumIncludes = ReadUnalignedLE16(d); |
| 1709 | HFI.ControllingMacroID = ReadUnalignedLE32(d); |
| 1710 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1711 | (void)End; |
| 1712 | |
| 1713 | // This HeaderFileInfo was externally loaded. |
| 1714 | HFI.External = true; |
| 1715 | return HFI; |
| 1716 | } |
| 1717 | }; |
| 1718 | } |
| 1719 | |
| 1720 | /// \brief The on-disk hash table used for the global method pool. |
| 1721 | typedef OnDiskChainedHashTable<HeaderFileInfoTrait> |
| 1722 | HeaderFileInfoLookupTable; |
| 1723 | |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1724 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F, |
| 1725 | uint64_t Offset) { |
| 1726 | // Note that this identifier has a macro definition. |
| 1727 | II->setHasMacroDefinition(true); |
| 1728 | |
| 1729 | // Adjust the offset based on our position in the chain. |
| 1730 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1731 | if (Chain[I] == &F) |
| 1732 | break; |
| 1733 | |
| 1734 | Offset += Chain[I]->SizeInBits; |
| 1735 | } |
| 1736 | |
| 1737 | UnreadMacroRecordOffsets[II] = Offset; |
| 1738 | } |
| 1739 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1740 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1741 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1742 | PerFileData &F = *Chain[N - I - 1]; |
| 1743 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1744 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1745 | // If there was no preprocessor block, skip this file. |
| 1746 | if (!MacroCursor.getBitStreamReader()) |
| 1747 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1748 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1749 | llvm::BitstreamCursor Cursor = MacroCursor; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1750 | Cursor.JumpToBit(F.MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1751 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1752 | RecordData Record; |
| 1753 | while (true) { |
| 1754 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1755 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1756 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1757 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1758 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1759 | // No known subblocks, always skip them. |
| 1760 | Cursor.ReadSubBlockID(); |
| 1761 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1762 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1763 | return; |
| 1764 | } |
| 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 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1769 | Cursor.ReadAbbrevRecord(); |
| 1770 | continue; |
| 1771 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1772 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1773 | // Read a record. |
| 1774 | const char *BlobStart; |
| 1775 | unsigned BlobLen; |
| 1776 | Record.clear(); |
| 1777 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1778 | default: // Default behavior: ignore. |
| 1779 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1780 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1781 | case PP_MACRO_OBJECT_LIKE: |
| 1782 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1783 | DecodeIdentifierInfo(Record[0]); |
| 1784 | break; |
| 1785 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1786 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1787 | // Ignore tokens. |
| 1788 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1789 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1790 | } |
| 1791 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1792 | |
| 1793 | // Drain the unread macro-record offsets map. |
| 1794 | while (!UnreadMacroRecordOffsets.empty()) |
| 1795 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1796 | } |
| 1797 | |
| 1798 | void ASTReader::LoadMacroDefinition( |
| 1799 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1800 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
| 1801 | PerFileData *F = 0; |
| 1802 | uint64_t Offset = Pos->second; |
| 1803 | UnreadMacroRecordOffsets.erase(Pos); |
| 1804 | |
| 1805 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1806 | if (Offset < Chain[I]->SizeInBits) { |
| 1807 | F = Chain[I]; |
| 1808 | break; |
| 1809 | } |
| 1810 | |
| 1811 | Offset -= Chain[I]->SizeInBits; |
| 1812 | } |
| 1813 | if (!F) { |
| 1814 | Error("Malformed macro record offset"); |
| 1815 | return; |
| 1816 | } |
| 1817 | |
| 1818 | ReadMacroRecord(*F, Offset); |
| 1819 | } |
| 1820 | |
| 1821 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1822 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1823 | = UnreadMacroRecordOffsets.find(II); |
| 1824 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1827 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1828 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1829 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1830 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1831 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1832 | unsigned Index = ID - 1; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1833 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1834 | PerFileData &F = *Chain[N - I - 1]; |
| 1835 | if (Index < F.LocalNumMacroDefinitions) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1836 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 1837 | F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]); |
| 1838 | LoadPreprocessedEntity(F); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1839 | break; |
| 1840 | } |
| 1841 | Index -= F.LocalNumMacroDefinitions; |
| 1842 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1843 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1846 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1849 | const FileEntry *ASTReader::getFileEntry(llvm::StringRef filenameStrRef) { |
| 1850 | std::string Filename = filenameStrRef; |
| 1851 | MaybeAddSystemRootToFilename(Filename); |
| 1852 | const FileEntry *File = FileMgr.getFile(Filename); |
| 1853 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1854 | OriginalDir != CurrentDir) { |
| 1855 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1856 | OriginalDir, |
| 1857 | CurrentDir); |
| 1858 | if (!resolved.empty()) |
| 1859 | File = FileMgr.getFile(resolved); |
| 1860 | } |
| 1861 | |
| 1862 | return File; |
| 1863 | } |
| 1864 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1865 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1866 | /// not an absolute path, add the system root to the beginning of the file |
| 1867 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1868 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1869 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1870 | if (!RelocatablePCH) |
| 1871 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1872 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1873 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1874 | return; |
| 1875 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1876 | if (isysroot == 0) { |
| 1877 | // If no system root was given, default to '/' |
| 1878 | Filename.insert(Filename.begin(), '/'); |
| 1879 | return; |
| 1880 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1881 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1882 | unsigned Length = strlen(isysroot); |
| 1883 | if (isysroot[Length - 1] != '/') |
| 1884 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1885 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1886 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1887 | } |
| 1888 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1889 | ASTReader::ASTReadResult |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1890 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1891 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1892 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1893 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1894 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1895 | return Failure; |
| 1896 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1897 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1898 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1899 | RecordData Record; |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1900 | bool First = true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1901 | while (!Stream.AtEndOfStream()) { |
| 1902 | unsigned Code = Stream.ReadCode(); |
| 1903 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1904 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1905 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1906 | return Failure; |
| 1907 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1908 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1909 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1913 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1914 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1915 | // We lazily load the decls block, but we want to set up the |
| 1916 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1917 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1918 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1919 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1920 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1921 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1922 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1923 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1924 | return Failure; |
| 1925 | } |
| 1926 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1927 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1928 | case DECL_UPDATES_BLOCK_ID: |
| 1929 | if (Stream.SkipBlock()) { |
| 1930 | Error("malformed block record in AST file"); |
| 1931 | return Failure; |
| 1932 | } |
| 1933 | break; |
| 1934 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1935 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1936 | F.MacroCursor = Stream; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1937 | if (PP) |
| 1938 | PP->setExternalSource(this); |
| 1939 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1940 | if (Stream.SkipBlock() || |
| 1941 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1942 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1943 | return Failure; |
| 1944 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1945 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1946 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1947 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1948 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1949 | F.PreprocessorDetailCursor = Stream; |
| 1950 | if (Stream.SkipBlock() || |
| 1951 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1952 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1953 | Error("malformed preprocessor detail record in AST file"); |
| 1954 | return Failure; |
| 1955 | } |
| 1956 | F.PreprocessorDetailStartOffset |
| 1957 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 1958 | break; |
| 1959 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1960 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1961 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1962 | case Success: |
| 1963 | break; |
| 1964 | |
| 1965 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1966 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1967 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1968 | |
| 1969 | case IgnorePCH: |
| 1970 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1971 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1972 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1973 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1974 | First = false; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1975 | continue; |
| 1976 | } |
| 1977 | |
| 1978 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1979 | Stream.ReadAbbrevRecord(); |
| 1980 | continue; |
| 1981 | } |
| 1982 | |
| 1983 | // Read and process a record. |
| 1984 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1985 | const char *BlobStart = 0; |
| 1986 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1987 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1988 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1989 | default: // Default behavior: ignore. |
| 1990 | break; |
| 1991 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1992 | case METADATA: { |
| 1993 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1994 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1995 | : diag::warn_pch_version_too_new); |
| 1996 | return IgnorePCH; |
| 1997 | } |
| 1998 | |
| 1999 | RelocatablePCH = Record[4]; |
| 2000 | if (Listener) { |
| 2001 | std::string TargetTriple(BlobStart, BlobLen); |
| 2002 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 2003 | return IgnorePCH; |
| 2004 | } |
| 2005 | break; |
| 2006 | } |
| 2007 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2008 | case CHAINED_METADATA: { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2009 | if (!First) { |
| 2010 | Error("CHAINED_METADATA is not first record in block"); |
| 2011 | return Failure; |
| 2012 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2013 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 2014 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2015 | : diag::warn_pch_version_too_new); |
| 2016 | return IgnorePCH; |
| 2017 | } |
| 2018 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2019 | // Load the chained file, which is always a PCH file. |
| 2020 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2021 | case Failure: return Failure; |
| 2022 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 2023 | case IgnorePCH: return IgnorePCH; |
| 2024 | case Success: break; |
| 2025 | } |
| 2026 | break; |
| 2027 | } |
| 2028 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2029 | case TYPE_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2030 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2031 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2032 | return Failure; |
| 2033 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2034 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 2035 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2036 | break; |
| 2037 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2038 | case DECL_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2039 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2040 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2041 | return Failure; |
| 2042 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2043 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 2044 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2045 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2046 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2047 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2048 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2049 | /* No visible information */ 0, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2050 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 2051 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2052 | }; |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2053 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 2054 | .push_back(Info); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2055 | break; |
| 2056 | } |
| 2057 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2058 | case UPDATE_VISIBLE: { |
| 2059 | serialization::DeclID ID = Record[0]; |
| 2060 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 2061 | (const unsigned char *)BlobStart + Record[1], |
| 2062 | (const unsigned char *)BlobStart, |
| 2063 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2064 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2065 | DeclContextInfo Info = { |
| 2066 | Table, /* No lexical inforamtion */ 0, 0 |
| 2067 | }; |
| 2068 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 2069 | } else |
| 2070 | PendingVisibleUpdates[ID].push_back(Table); |
| 2071 | break; |
| 2072 | } |
| 2073 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2074 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2075 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 2076 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2077 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2078 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 2079 | Latest > FirstLatestDeclIDs[First]) && |
| 2080 | "The new latest is supposed to come after the previous latest"); |
| 2081 | FirstLatestDeclIDs[First] = Latest; |
| 2082 | } |
| 2083 | break; |
| 2084 | } |
| 2085 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2086 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2087 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2088 | return IgnorePCH; |
| 2089 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2090 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2091 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2092 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2093 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2094 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2095 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2096 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2097 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2098 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2099 | if (PP) |
| 2100 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2101 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2102 | break; |
| 2103 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2104 | case IDENTIFIER_OFFSET: |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2105 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2106 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2107 | return Failure; |
| 2108 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2109 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2110 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2111 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2112 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2113 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2114 | // Optimization for the first block. |
| 2115 | if (ExternalDefinitions.empty()) |
| 2116 | ExternalDefinitions.swap(Record); |
| 2117 | else |
| 2118 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 2119 | Record.begin(), Record.end()); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2120 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2121 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2122 | case SPECIAL_TYPES: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2123 | // Optimization for the first block |
| 2124 | if (SpecialTypes.empty()) |
| 2125 | SpecialTypes.swap(Record); |
| 2126 | else |
| 2127 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2128 | break; |
| 2129 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2130 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2131 | TotalNumStatements += Record[0]; |
| 2132 | TotalNumMacros += Record[1]; |
| 2133 | TotalLexicalDeclContexts += Record[2]; |
| 2134 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2135 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2136 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2137 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2138 | // Optimization for the first block. |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2139 | if (UnusedFileScopedDecls.empty()) |
| 2140 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2141 | else |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2142 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 2143 | Record.begin(), Record.end()); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2144 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2145 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2146 | case DELEGATING_CTORS: |
| 2147 | // Optimization for the first block. |
| 2148 | if (DelegatingCtorDecls.empty()) |
| 2149 | DelegatingCtorDecls.swap(Record); |
| 2150 | else |
| 2151 | DelegatingCtorDecls.insert(DelegatingCtorDecls.end(), |
| 2152 | Record.begin(), Record.end()); |
| 2153 | break; |
| 2154 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2155 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2156 | // Later blocks overwrite earlier ones. |
| 2157 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2158 | break; |
| 2159 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2160 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2161 | // Optimization for the first block. |
| 2162 | if (LocallyScopedExternalDecls.empty()) |
| 2163 | LocallyScopedExternalDecls.swap(Record); |
| 2164 | else |
| 2165 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 2166 | Record.begin(), Record.end()); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2167 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2168 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2169 | case SELECTOR_OFFSETS: |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2170 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2171 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2172 | break; |
| 2173 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2174 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2175 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2176 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2177 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2178 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2179 | F.SelectorLookupTableData + Record[0], |
| 2180 | F.SelectorLookupTableData, |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2181 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2182 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2183 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2184 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2185 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2186 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2187 | break; |
| 2188 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2189 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2190 | if (!Record.empty() && Listener) |
| 2191 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2192 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2193 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2194 | case SOURCE_LOCATION_OFFSETS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2195 | F.SLocOffsets = (const uint32_t *)BlobStart; |
| 2196 | F.LocalNumSLocEntries = Record[0]; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2197 | F.LocalSLocSize = Record[1]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2198 | break; |
| 2199 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2200 | case FILE_SOURCE_LOCATION_OFFSETS: |
| 2201 | F.SLocFileOffsets = (const uint32_t *)BlobStart; |
| 2202 | F.LocalNumSLocFileEntries = Record[0]; |
| 2203 | break; |
| 2204 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2205 | case SOURCE_LOCATION_PRELOADS: |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2206 | if (PreloadSLocEntries.empty()) |
| 2207 | PreloadSLocEntries.swap(Record); |
| 2208 | else |
| 2209 | PreloadSLocEntries.insert(PreloadSLocEntries.end(), |
| 2210 | Record.begin(), Record.end()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2211 | break; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2212 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2213 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2214 | if (!DisableStatCache) { |
| 2215 | ASTStatCache *MyStatCache = |
| 2216 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2217 | (const unsigned char *)BlobStart, |
| 2218 | NumStatHits, NumStatMisses); |
| 2219 | FileMgr.addStatCache(MyStatCache); |
| 2220 | F.StatCache = MyStatCache; |
| 2221 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2222 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2223 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2224 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2225 | case EXT_VECTOR_DECLS: |
Sebastian Redl | a9f2368 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 2226 | // Optimization for the first block. |
| 2227 | if (ExtVectorDecls.empty()) |
| 2228 | ExtVectorDecls.swap(Record); |
| 2229 | else |
| 2230 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 2231 | Record.begin(), Record.end()); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2232 | break; |
| 2233 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2234 | case VTABLE_USES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2235 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2236 | VTableUses.swap(Record); |
| 2237 | break; |
| 2238 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2239 | case DYNAMIC_CLASSES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2240 | // Optimization for the first block. |
| 2241 | if (DynamicClasses.empty()) |
| 2242 | DynamicClasses.swap(Record); |
| 2243 | else |
| 2244 | DynamicClasses.insert(DynamicClasses.end(), |
| 2245 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2246 | break; |
| 2247 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2248 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2249 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2250 | break; |
| 2251 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2252 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2253 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2254 | SemaDeclRefs.swap(Record); |
| 2255 | break; |
| 2256 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2257 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2258 | // 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] | 2259 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2260 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2261 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2262 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2263 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2264 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2265 | case ORIGINAL_FILE_ID: |
| 2266 | OriginalFileID = FileID::get(Record[0]); |
| 2267 | break; |
| 2268 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2269 | case ORIGINAL_PCH_DIR: |
| 2270 | // The primary AST will be the last to get here, so it will be the one |
| 2271 | // that's used. |
| 2272 | OriginalDir.assign(BlobStart, BlobLen); |
| 2273 | break; |
| 2274 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2275 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2276 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2277 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 2278 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2279 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2280 | return IgnorePCH; |
| 2281 | } |
| 2282 | break; |
| 2283 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2284 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2285 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2286 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2287 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2288 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2289 | break; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2290 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2291 | case DECL_UPDATE_OFFSETS: { |
| 2292 | if (Record.size() % 2 != 0) { |
| 2293 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2294 | return Failure; |
| 2295 | } |
| 2296 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
| 2297 | DeclUpdateOffsets[static_cast<DeclID>(Record[I])] |
| 2298 | .push_back(std::make_pair(&F, Record[I+1])); |
| 2299 | break; |
| 2300 | } |
| 2301 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2302 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2303 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2304 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2305 | return Failure; |
| 2306 | } |
| 2307 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2308 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2309 | std::make_pair(&F, Record[I+1]); |
| 2310 | break; |
| 2311 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2312 | |
| 2313 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2314 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2315 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2316 | return Failure; |
| 2317 | } |
| 2318 | |
| 2319 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2320 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
| 2321 | break; |
| 2322 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2323 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2324 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2325 | if (Record.size() % 2 != 0) { |
| 2326 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2327 | return Failure; |
| 2328 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2329 | if (PragmaDiagMappings.empty()) |
| 2330 | PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2331 | else |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2332 | PragmaDiagMappings.insert(PragmaDiagMappings.end(), |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2333 | Record.begin(), Record.end()); |
| 2334 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2335 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2336 | case CUDA_SPECIAL_DECL_REFS: |
| 2337 | // Later tables overwrite earlier ones. |
| 2338 | CUDASpecialDeclRefs.swap(Record); |
| 2339 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2340 | |
| 2341 | case HEADER_SEARCH_TABLE: |
| 2342 | F.HeaderFileInfoTableData = BlobStart; |
| 2343 | F.LocalNumHeaderFileInfos = Record[1]; |
| 2344 | if (Record[0]) { |
| 2345 | F.HeaderFileInfoTable |
| 2346 | = HeaderFileInfoLookupTable::Create( |
| 2347 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 2348 | (const unsigned char *)F.HeaderFileInfoTableData); |
| 2349 | if (PP) |
| 2350 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2351 | } |
| 2352 | break; |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2353 | |
| 2354 | case FP_PRAGMA_OPTIONS: |
| 2355 | // Later tables overwrite earlier ones. |
| 2356 | FPPragmaOptions.swap(Record); |
| 2357 | break; |
| 2358 | |
| 2359 | case OPENCL_EXTENSIONS: |
| 2360 | // Later tables overwrite earlier ones. |
| 2361 | OpenCLExtensions.swap(Record); |
| 2362 | break; |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2363 | |
| 2364 | case TENTATIVE_DEFINITIONS: |
| 2365 | // Optimization for the first block. |
| 2366 | if (TentativeDefinitions.empty()) |
| 2367 | TentativeDefinitions.swap(Record); |
| 2368 | else |
| 2369 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 2370 | Record.begin(), Record.end()); |
| 2371 | break; |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2372 | |
| 2373 | case KNOWN_NAMESPACES: |
| 2374 | // Optimization for the first block. |
| 2375 | if (KnownNamespaces.empty()) |
| 2376 | KnownNamespaces.swap(Record); |
| 2377 | else |
| 2378 | KnownNamespaces.insert(KnownNamespaces.end(), |
| 2379 | Record.begin(), Record.end()); |
| 2380 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2381 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2382 | First = false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2383 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2384 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2385 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2386 | } |
| 2387 | |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2388 | ASTReader::ASTReadResult ASTReader::validateFileEntries() { |
| 2389 | for (unsigned CI = 0, CN = Chain.size(); CI != CN; ++CI) { |
| 2390 | PerFileData *F = Chain[CI]; |
| 2391 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
| 2392 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2393 | for (unsigned i = 0, e = F->LocalNumSLocFileEntries; i != e; ++i) { |
| 2394 | SLocEntryCursor.JumpToBit(F->SLocFileOffsets[i]); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2395 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 2396 | if (Code == llvm::bitc::END_BLOCK || |
| 2397 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 2398 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 2399 | Error("incorrectly-formatted source location entry in AST file"); |
| 2400 | return Failure; |
| 2401 | } |
| 2402 | |
| 2403 | RecordData Record; |
| 2404 | const char *BlobStart; |
| 2405 | unsigned BlobLen; |
| 2406 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 2407 | default: |
| 2408 | Error("incorrectly-formatted source location entry in AST file"); |
| 2409 | return Failure; |
| 2410 | |
| 2411 | case SM_SLOC_FILE_ENTRY: { |
| 2412 | llvm::StringRef Filename(BlobStart, BlobLen); |
| 2413 | const FileEntry *File = getFileEntry(Filename); |
| 2414 | |
| 2415 | if (File == 0) { |
| 2416 | std::string ErrorStr = "could not find file '"; |
| 2417 | ErrorStr += Filename; |
| 2418 | ErrorStr += "' referenced by AST file"; |
| 2419 | Error(ErrorStr.c_str()); |
| 2420 | return IgnorePCH; |
| 2421 | } |
| 2422 | |
| 2423 | if (Record.size() < 6) { |
| 2424 | Error("source location entry is incorrect"); |
| 2425 | return Failure; |
| 2426 | } |
| 2427 | |
| 2428 | // The stat info from the FileEntry came from the cached stat |
| 2429 | // info of the PCH, so we cannot trust it. |
| 2430 | struct stat StatBuf; |
| 2431 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 2432 | StatBuf.st_size = File->getSize(); |
| 2433 | StatBuf.st_mtime = File->getModificationTime(); |
| 2434 | } |
| 2435 | |
| 2436 | if (((off_t)Record[4] != StatBuf.st_size |
| 2437 | #if !defined(LLVM_ON_WIN32) |
| 2438 | // In our regression testing, the Windows file system seems to |
| 2439 | // have inconsistent modification times that sometimes |
| 2440 | // erroneously trigger this error-handling path. |
| 2441 | || (time_t)Record[5] != StatBuf.st_mtime |
| 2442 | #endif |
| 2443 | )) { |
| 2444 | Error(diag::err_fe_pch_file_modified, Filename); |
| 2445 | return IgnorePCH; |
| 2446 | } |
| 2447 | |
| 2448 | break; |
| 2449 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2450 | } |
| 2451 | } |
| 2452 | } |
| 2453 | |
| 2454 | return Success; |
| 2455 | } |
| 2456 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2457 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2458 | ASTFileType Type) { |
| 2459 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2460 | case Failure: return Failure; |
| 2461 | case IgnorePCH: return IgnorePCH; |
| 2462 | case Success: break; |
| 2463 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2464 | |
| 2465 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2466 | |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2467 | if (!DisableValidation) { |
| 2468 | switch(validateFileEntries()) { |
| 2469 | case Failure: return Failure; |
| 2470 | case IgnorePCH: return IgnorePCH; |
| 2471 | case Success: break; |
| 2472 | } |
| 2473 | } |
| 2474 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2475 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2476 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2477 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2478 | TotalNumSelectors = 0; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2479 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2480 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2481 | NextSLocOffset += Chain[I]->LocalSLocSize; |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2482 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2483 | TotalNumTypes += Chain[I]->LocalNumTypes; |
| 2484 | TotalNumDecls += Chain[I]->LocalNumDecls; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2485 | TotalNumPreallocatedPreprocessingEntities += |
| 2486 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2487 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2488 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2489 | } |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2490 | SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset); |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2491 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2492 | TypesLoaded.resize(TotalNumTypes); |
| 2493 | DeclsLoaded.resize(TotalNumDecls); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2494 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2495 | if (PP) { |
| 2496 | if (TotalNumIdentifiers > 0) |
| 2497 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2498 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2499 | if (!PP->getPreprocessingRecord()) |
Douglas Gregor | dca8ee8 | 2011-05-06 16:33:08 +0000 | [diff] [blame] | 2500 | PP->createPreprocessingRecord(true); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2501 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2502 | TotalNumPreallocatedPreprocessingEntities); |
| 2503 | } |
| 2504 | } |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2505 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2506 | // Preload SLocEntries. |
| 2507 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2508 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2509 | if (Result != Success) |
| 2510 | return Result; |
| 2511 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2512 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2513 | // Check the predefines buffers. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2514 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2515 | return IgnorePCH; |
| 2516 | |
| 2517 | if (PP) { |
| 2518 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2519 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2520 | // loaded into the IdentifierTable before we intercepted the |
| 2521 | // creation of identifiers. Iterate through the list of known |
| 2522 | // identifiers and determine whether we have to establish |
| 2523 | // preprocessor definitions or top-level identifier declaration |
| 2524 | // chains for those identifiers. |
| 2525 | // |
| 2526 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2527 | // since de-serializing declarations or macro definitions can add |
| 2528 | // new entries into the identifier table, invalidating the |
| 2529 | // iterators. |
| 2530 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2531 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2532 | IdEnd = PP->getIdentifierTable().end(); |
| 2533 | Id != IdEnd; ++Id) |
| 2534 | Identifiers.push_back(Id->second); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2535 | // We need to search the tables in all files. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2536 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2537 | ASTIdentifierLookupTable *IdTable |
| 2538 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2539 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2540 | // ones. |
| 2541 | if (!IdTable) |
| 2542 | continue; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2543 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2544 | IdentifierInfo *II = Identifiers[I]; |
| 2545 | // 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] | 2546 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2547 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2548 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2549 | if (Pos == IdTable->end()) |
| 2550 | continue; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2551 | |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2552 | // Dereferencing the iterator has the effect of populating the |
| 2553 | // IdentifierInfo node with the various declarations it needs. |
| 2554 | (void)*Pos; |
| 2555 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2556 | } |
| 2557 | } |
| 2558 | |
| 2559 | if (Context) |
| 2560 | InitializeContext(*Context); |
| 2561 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2562 | if (DeserializationListener) |
| 2563 | DeserializationListener->ReaderInitialized(this); |
| 2564 | |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2565 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2566 | // the source manager to the file source file from which the preamble was |
| 2567 | // built. This is the only valid way to use a precompiled preamble. |
| 2568 | if (Type == Preamble) { |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2569 | if (OriginalFileID.isInvalid()) { |
| 2570 | SourceLocation Loc |
| 2571 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2572 | if (Loc.isValid()) |
| 2573 | OriginalFileID = SourceMgr.getDecomposedLoc(Loc).first; |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2574 | } |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2575 | |
| 2576 | if (!OriginalFileID.isInvalid()) |
| 2577 | SourceMgr.SetPreambleFileID(OriginalFileID); |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2578 | } |
| 2579 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2580 | return Success; |
| 2581 | } |
| 2582 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2583 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2584 | ASTFileType Type) { |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2585 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2586 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2587 | PerFileData &F = *Chain.back(); |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2588 | if (Prev) |
| 2589 | Prev->NextInSource = &F; |
| 2590 | else |
| 2591 | FirstInSource = &F; |
| 2592 | F.Loaders.push_back(Prev); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2593 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2594 | // Set the AST file name. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2595 | F.FileName = FileName; |
| 2596 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2597 | if (FileName != "-") { |
| 2598 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2599 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2600 | } |
| 2601 | |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 2602 | if (!ASTBuffers.empty()) { |
Sebastian Redl | 5655837 | 2011-04-14 14:07:41 +0000 | [diff] [blame] | 2603 | F.Buffer.reset(ASTBuffers.back()); |
| 2604 | ASTBuffers.pop_back(); |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 2605 | assert(F.Buffer && "Passed null buffer"); |
| 2606 | } else { |
| 2607 | // Open the AST file. |
| 2608 | // |
| 2609 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2610 | std::string ErrStr; |
| 2611 | llvm::error_code ec; |
| 2612 | if (FileName == "-") { |
| 2613 | ec = llvm::MemoryBuffer::getSTDIN(F.Buffer); |
| 2614 | if (ec) |
| 2615 | ErrStr = ec.message(); |
| 2616 | } else |
| 2617 | F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr)); |
| 2618 | if (!F.Buffer) { |
| 2619 | Error(ErrStr.c_str()); |
| 2620 | return IgnorePCH; |
| 2621 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | // Initialize the stream |
| 2625 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2626 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2627 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2628 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2629 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2630 | |
| 2631 | // Sniff for the signature. |
| 2632 | if (Stream.Read(8) != 'C' || |
| 2633 | Stream.Read(8) != 'P' || |
| 2634 | Stream.Read(8) != 'C' || |
| 2635 | Stream.Read(8) != 'H') { |
| 2636 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2637 | return Failure; |
| 2638 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2639 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2640 | while (!Stream.AtEndOfStream()) { |
| 2641 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2642 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2643 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2644 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2645 | return Failure; |
| 2646 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2647 | |
| 2648 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2649 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2650 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2651 | switch (BlockID) { |
| 2652 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2653 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2654 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2655 | return Failure; |
| 2656 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2657 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2658 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2659 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2660 | case Success: |
| 2661 | break; |
| 2662 | |
| 2663 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2664 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2665 | |
| 2666 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2667 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2668 | // AST block, skipping subblocks, to see if there are other |
| 2669 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2670 | |
| 2671 | // Clear out any preallocated source location entries, so that |
| 2672 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2673 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2674 | |
| 2675 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2676 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2677 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2678 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2679 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2680 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2681 | break; |
| 2682 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2683 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2684 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2685 | return Failure; |
| 2686 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2687 | break; |
| 2688 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2689 | } |
| 2690 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2691 | return Success; |
| 2692 | } |
| 2693 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2694 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2695 | PP = &pp; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2696 | |
| 2697 | unsigned TotalNum = 0; |
| 2698 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2699 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2700 | if (TotalNum) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2701 | if (!PP->getPreprocessingRecord()) |
Douglas Gregor | dca8ee8 | 2011-05-06 16:33:08 +0000 | [diff] [blame] | 2702 | PP->createPreprocessingRecord(true); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2703 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2704 | } |
| 2705 | } |
| 2706 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2707 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2708 | Context = &Ctx; |
| 2709 | assert(Context && "Passed null context!"); |
| 2710 | |
| 2711 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2712 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2713 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2714 | PP->setExternalSource(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2715 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2716 | |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2717 | // If we have an update block for the TU waiting, we have to add it before |
| 2718 | // deserializing the decl. |
| 2719 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2720 | if (DCU != DeclContextOffsets.end()) { |
| 2721 | // Insertion could invalidate map, so grab vector. |
| 2722 | DeclContextInfos T; |
| 2723 | T.swap(DCU->second); |
| 2724 | DeclContextOffsets.erase(DCU); |
| 2725 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2726 | } |
| 2727 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2728 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2729 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2730 | |
| 2731 | // Load the special types. |
| 2732 | Context->setBuiltinVaListType( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2733 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2734 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2735 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2736 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2737 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2738 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2739 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2740 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2741 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2742 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2743 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2744 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2745 | if (unsigned FastEnum |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2746 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2747 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2748 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2749 | QualType FileType = GetType(File); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2750 | if (FileType.isNull()) { |
| 2751 | Error("FILE type is NULL"); |
| 2752 | return; |
| 2753 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2754 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2755 | Context->setFILEDecl(Typedef->getDecl()); |
| 2756 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2757 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2758 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2759 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2760 | return; |
| 2761 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2762 | Context->setFILEDecl(Tag->getDecl()); |
| 2763 | } |
| 2764 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2765 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2766 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2767 | if (Jmp_bufType.isNull()) { |
| 2768 | Error("jmp_bug type is NULL"); |
| 2769 | return; |
| 2770 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2771 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2772 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2773 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2774 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2775 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2776 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2777 | return; |
| 2778 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2779 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2780 | } |
| 2781 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2782 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2783 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2784 | if (Sigjmp_bufType.isNull()) { |
| 2785 | Error("sigjmp_buf type is NULL"); |
| 2786 | return; |
| 2787 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2788 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2789 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2790 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2791 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2792 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2793 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2794 | } |
| 2795 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2796 | if (unsigned ObjCIdRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2797 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2798 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2799 | if (unsigned ObjCClassRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2800 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2801 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2802 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2803 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2804 | if (unsigned String |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2805 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2806 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2807 | if (unsigned ObjCSelRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2808 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2809 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2810 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2811 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2812 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2813 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2814 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2815 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2816 | if (unsigned AutoDeduct = SpecialTypes[SPECIAL_TYPE_AUTO_DEDUCT]) |
| 2817 | Context->AutoDeductTy = GetType(AutoDeduct); |
| 2818 | if (unsigned AutoRRefDeduct = SpecialTypes[SPECIAL_TYPE_AUTO_RREF_DEDUCT]) |
| 2819 | Context->AutoRRefDeductTy = GetType(AutoRRefDeduct); |
| 2820 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2821 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2822 | |
| 2823 | // If there were any CUDA special declarations, deserialize them. |
| 2824 | if (!CUDASpecialDeclRefs.empty()) { |
| 2825 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 2826 | Context->setcudaConfigureCallDecl( |
| 2827 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2828 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2829 | } |
| 2830 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2831 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2832 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2833 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2834 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2835 | FileManager &FileMgr, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2836 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2837 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2838 | std::string ErrStr; |
| 2839 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2840 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2841 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2842 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2843 | return std::string(); |
| 2844 | } |
| 2845 | |
| 2846 | // Initialize the stream |
| 2847 | llvm::BitstreamReader StreamFile; |
| 2848 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2849 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2850 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2851 | Stream.init(StreamFile); |
| 2852 | |
| 2853 | // Sniff for the signature. |
| 2854 | if (Stream.Read(8) != 'C' || |
| 2855 | Stream.Read(8) != 'P' || |
| 2856 | Stream.Read(8) != 'C' || |
| 2857 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2858 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2859 | return std::string(); |
| 2860 | } |
| 2861 | |
| 2862 | RecordData Record; |
| 2863 | while (!Stream.AtEndOfStream()) { |
| 2864 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2865 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2866 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2867 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2868 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2869 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2870 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2871 | case AST_BLOCK_ID: |
| 2872 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2873 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2874 | return std::string(); |
| 2875 | } |
| 2876 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2877 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2878 | default: |
| 2879 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2880 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2881 | return std::string(); |
| 2882 | } |
| 2883 | break; |
| 2884 | } |
| 2885 | continue; |
| 2886 | } |
| 2887 | |
| 2888 | if (Code == llvm::bitc::END_BLOCK) { |
| 2889 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2890 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2891 | return std::string(); |
| 2892 | } |
| 2893 | continue; |
| 2894 | } |
| 2895 | |
| 2896 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2897 | Stream.ReadAbbrevRecord(); |
| 2898 | continue; |
| 2899 | } |
| 2900 | |
| 2901 | Record.clear(); |
| 2902 | const char *BlobStart = 0; |
| 2903 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2904 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2905 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2906 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2907 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2908 | |
| 2909 | return std::string(); |
| 2910 | } |
| 2911 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2912 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2913 | /// structure. |
| 2914 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2915 | /// This routine parses the language options from the AST file and then gives |
| 2916 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2917 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2918 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2919 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2920 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2921 | if (Listener) { |
| 2922 | LangOptions LangOpts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2923 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2924 | #define PARSE_LANGOPT(Option) \ |
| 2925 | LangOpts.Option = Record[Idx]; \ |
| 2926 | ++Idx |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2927 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2928 | unsigned Idx = 0; |
| 2929 | PARSE_LANGOPT(Trigraphs); |
| 2930 | PARSE_LANGOPT(BCPLComment); |
| 2931 | PARSE_LANGOPT(DollarIdents); |
| 2932 | PARSE_LANGOPT(AsmPreprocessor); |
| 2933 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2934 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2935 | PARSE_LANGOPT(ImplicitInt); |
| 2936 | PARSE_LANGOPT(Digraphs); |
| 2937 | PARSE_LANGOPT(HexFloats); |
| 2938 | PARSE_LANGOPT(C99); |
Peter Collingbourne | 7e7fbd0 | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 2939 | PARSE_LANGOPT(C1X); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2940 | PARSE_LANGOPT(Microsoft); |
| 2941 | PARSE_LANGOPT(CPlusPlus); |
| 2942 | PARSE_LANGOPT(CPlusPlus0x); |
| 2943 | PARSE_LANGOPT(CXXOperatorNames); |
| 2944 | PARSE_LANGOPT(ObjC1); |
| 2945 | PARSE_LANGOPT(ObjC2); |
| 2946 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 2947 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 2948 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 2949 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Douglas Gregor | 74da19f | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 2950 | PARSE_LANGOPT(ObjCInferRelatedResultType); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 2951 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2952 | PARSE_LANGOPT(PascalStrings); |
| 2953 | PARSE_LANGOPT(WritableStrings); |
| 2954 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2955 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2956 | PARSE_LANGOPT(Exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 2957 | PARSE_LANGOPT(ObjCExceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 2958 | PARSE_LANGOPT(CXXExceptions); |
| 2959 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 2960 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2961 | PARSE_LANGOPT(NeXTRuntime); |
| 2962 | PARSE_LANGOPT(Freestanding); |
| 2963 | PARSE_LANGOPT(NoBuiltin); |
| 2964 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 2965 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2966 | PARSE_LANGOPT(Blocks); |
| 2967 | PARSE_LANGOPT(EmitAllDecls); |
| 2968 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2969 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 2970 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2971 | PARSE_LANGOPT(HeinousExtensions); |
| 2972 | PARSE_LANGOPT(Optimize); |
| 2973 | PARSE_LANGOPT(OptimizeSize); |
| 2974 | PARSE_LANGOPT(Static); |
| 2975 | PARSE_LANGOPT(PICLevel); |
| 2976 | PARSE_LANGOPT(GNUInline); |
| 2977 | PARSE_LANGOPT(NoInline); |
Chandler Carruth | 0d2d1bc | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 2978 | PARSE_LANGOPT(Deprecated); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2979 | PARSE_LANGOPT(AccessControl); |
| 2980 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2981 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | b1bdced | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 2982 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2983 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2984 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 2985 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2986 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2987 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2988 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 2989 | PARSE_LANGOPT(CUDA); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2990 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2991 | PARSE_LANGOPT(DefaultFPContract); |
Roman Divacky | 1c51b1c | 2011-03-01 17:36:40 +0000 | [diff] [blame] | 2992 | PARSE_LANGOPT(ElideConstructors); |
| 2993 | PARSE_LANGOPT(SpellChecking); |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 2994 | PARSE_LANGOPT(MRTD); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2995 | PARSE_LANGOPT(ObjCAutoRefCount); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2996 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2997 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2998 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2999 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3000 | |
| 3001 | return false; |
| 3002 | } |
| 3003 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3004 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3005 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3006 | PerFileData &F = *Chain[I]; |
| 3007 | if (!F.PreprocessorDetailCursor.getBitStreamReader()) |
| 3008 | continue; |
| 3009 | |
| 3010 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 3011 | F.PreprocessorDetailCursor.JumpToBit(F.PreprocessorDetailStartOffset); |
| 3012 | while (LoadPreprocessedEntity(F)) { } |
| 3013 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3014 | } |
| 3015 | |
Douglas Gregor | 0a48029 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 3016 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3017 | PerFileData *F = 0; |
| 3018 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3019 | if (Offset < Chain[I]->SizeInBits) { |
| 3020 | F = Chain[I]; |
| 3021 | break; |
| 3022 | } |
| 3023 | |
| 3024 | Offset -= Chain[I]->SizeInBits; |
| 3025 | } |
| 3026 | |
| 3027 | if (!F) { |
| 3028 | Error("Malformed preprocessed entity offset"); |
| 3029 | return 0; |
| 3030 | } |
| 3031 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3032 | // Keep track of where we are in the stream, then jump back there |
| 3033 | // after reading this entity. |
| 3034 | SavedStreamPosition SavedPosition(F->PreprocessorDetailCursor); |
| 3035 | F->PreprocessorDetailCursor.JumpToBit(Offset); |
| 3036 | return LoadPreprocessedEntity(*F); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3039 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
| 3040 | HeaderFileInfoTrait Trait(FE->getName()); |
| 3041 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3042 | PerFileData &F = *Chain[I]; |
| 3043 | HeaderFileInfoLookupTable *Table |
| 3044 | = static_cast<HeaderFileInfoLookupTable *>(F.HeaderFileInfoTable); |
| 3045 | if (!Table) |
| 3046 | continue; |
| 3047 | |
| 3048 | // Look in the on-disk hash table for an entry for this file name. |
| 3049 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE->getName(), |
| 3050 | &Trait); |
| 3051 | if (Pos == Table->end()) |
| 3052 | continue; |
| 3053 | |
| 3054 | HeaderFileInfo HFI = *Pos; |
| 3055 | if (Listener) |
| 3056 | Listener->ReadHeaderFileInfo(HFI, FE->getUID()); |
| 3057 | |
| 3058 | return HFI; |
| 3059 | } |
| 3060 | |
| 3061 | return HeaderFileInfo(); |
| 3062 | } |
| 3063 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3064 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3065 | unsigned Idx = 0; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3066 | while (Idx < PragmaDiagMappings.size()) { |
| 3067 | SourceLocation |
| 3068 | Loc = SourceLocation::getFromRawEncoding(PragmaDiagMappings[Idx++]); |
| 3069 | while (1) { |
| 3070 | assert(Idx < PragmaDiagMappings.size() && |
| 3071 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 3072 | if (Idx >= PragmaDiagMappings.size()) |
| 3073 | break; // Something is messed up but at least avoid infinite loop in |
| 3074 | // release build. |
| 3075 | unsigned DiagID = PragmaDiagMappings[Idx++]; |
| 3076 | if (DiagID == (unsigned)-1) |
| 3077 | break; // no more diag/map pairs for this location. |
| 3078 | diag::Mapping Map = (diag::Mapping)PragmaDiagMappings[Idx++]; |
| 3079 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 3080 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3081 | } |
| 3082 | } |
| 3083 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3084 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3085 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3086 | PerFileData *F = 0; |
| 3087 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3088 | F = Chain[N - I - 1]; |
| 3089 | if (Index < F->LocalNumTypes) |
| 3090 | break; |
| 3091 | Index -= F->LocalNumTypes; |
| 3092 | } |
| 3093 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3094 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3095 | } |
| 3096 | |
| 3097 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3098 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3099 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 3100 | /// routine actually reads the record corresponding to the type at the given |
| 3101 | /// location. It is a helper routine for GetType, which deals with reading type |
| 3102 | /// IDs. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3103 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3104 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3105 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3106 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3107 | // Keep track of where we are in the stream, then jump back there |
| 3108 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3109 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3110 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3111 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3112 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3113 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3114 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3115 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3116 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3117 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3118 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3119 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 3120 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3121 | if (Record.size() != 2) { |
| 3122 | Error("Incorrect encoding of extended qualifier type"); |
| 3123 | return QualType(); |
| 3124 | } |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3125 | QualType Base = GetType(Record[0]); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3126 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 3127 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3128 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3129 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3130 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3131 | if (Record.size() != 1) { |
| 3132 | Error("Incorrect encoding of complex type"); |
| 3133 | return QualType(); |
| 3134 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3135 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3136 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3137 | } |
| 3138 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3139 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3140 | if (Record.size() != 1) { |
| 3141 | Error("Incorrect encoding of pointer type"); |
| 3142 | return QualType(); |
| 3143 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3144 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3145 | return Context->getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3146 | } |
| 3147 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3148 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3149 | if (Record.size() != 1) { |
| 3150 | Error("Incorrect encoding of block pointer type"); |
| 3151 | return QualType(); |
| 3152 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3153 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3154 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3155 | } |
| 3156 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3157 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3158 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3159 | Error("Incorrect encoding of lvalue reference type"); |
| 3160 | return QualType(); |
| 3161 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3162 | QualType PointeeType = GetType(Record[0]); |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3163 | return Context->getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3164 | } |
| 3165 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3166 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3167 | if (Record.size() != 1) { |
| 3168 | Error("Incorrect encoding of rvalue reference type"); |
| 3169 | return QualType(); |
| 3170 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3171 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3172 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3173 | } |
| 3174 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3175 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3176 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3177 | Error("Incorrect encoding of member pointer type"); |
| 3178 | return QualType(); |
| 3179 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3180 | QualType PointeeType = GetType(Record[0]); |
| 3181 | QualType ClassType = GetType(Record[1]); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3182 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3183 | return QualType(); |
| 3184 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3185 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3186 | } |
| 3187 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3188 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3189 | QualType ElementType = GetType(Record[0]); |
| 3190 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3191 | unsigned IndexTypeQuals = Record[2]; |
| 3192 | unsigned Idx = 3; |
| 3193 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3194 | return Context->getConstantArrayType(ElementType, Size, |
| 3195 | ASM, IndexTypeQuals); |
| 3196 | } |
| 3197 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3198 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3199 | QualType ElementType = GetType(Record[0]); |
| 3200 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3201 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3202 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3203 | } |
| 3204 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3205 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3206 | QualType ElementType = GetType(Record[0]); |
| 3207 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3208 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3209 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3210 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 3211 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3212 | ASM, IndexTypeQuals, |
| 3213 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3214 | } |
| 3215 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3216 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3217 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3218 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3219 | return QualType(); |
| 3220 | } |
| 3221 | |
| 3222 | QualType ElementType = GetType(Record[0]); |
| 3223 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3224 | unsigned VecKind = Record[2]; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3225 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3226 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3227 | } |
| 3228 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3229 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3230 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3231 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3232 | return QualType(); |
| 3233 | } |
| 3234 | |
| 3235 | QualType ElementType = GetType(Record[0]); |
| 3236 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3237 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3238 | } |
| 3239 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3240 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3241 | if (Record.size() != 6) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3242 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3243 | return QualType(); |
| 3244 | } |
| 3245 | QualType ResultType = GetType(Record[0]); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3246 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 3247 | (CallingConv)Record[4], Record[5]); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 3248 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3249 | } |
| 3250 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3251 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3252 | QualType ResultType = GetType(Record[0]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3253 | |
| 3254 | FunctionProtoType::ExtProtoInfo EPI; |
| 3255 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3256 | /*hasregparm*/ Record[2], |
| 3257 | /*regparm*/ Record[3], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3258 | static_cast<CallingConv>(Record[4]), |
| 3259 | /*produces*/ Record[5]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3260 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3261 | unsigned Idx = 6; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3262 | unsigned NumParams = Record[Idx++]; |
| 3263 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 3264 | for (unsigned I = 0; I != NumParams; ++I) |
| 3265 | ParamTypes.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3266 | |
| 3267 | EPI.Variadic = Record[Idx++]; |
| 3268 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3269 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3270 | ExceptionSpecificationType EST = |
| 3271 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3272 | EPI.ExceptionSpecType = EST; |
| 3273 | if (EST == EST_Dynamic) { |
| 3274 | EPI.NumExceptions = Record[Idx++]; |
| 3275 | llvm::SmallVector<QualType, 2> Exceptions; |
| 3276 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
| 3277 | Exceptions.push_back(GetType(Record[Idx++])); |
| 3278 | EPI.Exceptions = Exceptions.data(); |
| 3279 | } else if (EST == EST_ComputedNoexcept) { |
| 3280 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
| 3281 | } |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 3282 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3283 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3284 | } |
| 3285 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3286 | case TYPE_UNRESOLVED_USING: |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3287 | return Context->getTypeDeclType( |
| 3288 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 3289 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3290 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3291 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3292 | Error("incorrect encoding of typedef type"); |
| 3293 | return QualType(); |
| 3294 | } |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3295 | TypedefNameDecl *Decl = cast<TypedefNameDecl>(GetDecl(Record[0])); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3296 | QualType Canonical = GetType(Record[1]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3297 | if (!Canonical.isNull()) |
| 3298 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3299 | return Context->getTypedefType(Decl, Canonical); |
| 3300 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3301 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3302 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3303 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3304 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3305 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3306 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3307 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3308 | return QualType(); |
| 3309 | } |
| 3310 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3311 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3312 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3313 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3314 | case TYPE_DECLTYPE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3315 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3316 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3317 | case TYPE_UNARY_TRANSFORM: { |
| 3318 | QualType BaseType = GetType(Record[0]); |
| 3319 | QualType UnderlyingType = GetType(Record[1]); |
| 3320 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
| 3321 | return Context->getUnaryTransformType(BaseType, UnderlyingType, UKind); |
| 3322 | } |
| 3323 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3324 | case TYPE_AUTO: |
| 3325 | return Context->getAutoType(GetType(Record[0])); |
| 3326 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3327 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3328 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3329 | Error("incorrect encoding of record type"); |
| 3330 | return QualType(); |
| 3331 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3332 | bool IsDependent = Record[0]; |
| 3333 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3334 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3335 | return T; |
| 3336 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3337 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3338 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3339 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3340 | Error("incorrect encoding of enum type"); |
| 3341 | return QualType(); |
| 3342 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3343 | bool IsDependent = Record[0]; |
| 3344 | QualType T = Context->getEnumType(cast<EnumDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3345 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3346 | return T; |
| 3347 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3348 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3349 | case TYPE_ATTRIBUTED: { |
| 3350 | if (Record.size() != 3) { |
| 3351 | Error("incorrect encoding of attributed type"); |
| 3352 | return QualType(); |
| 3353 | } |
| 3354 | QualType modifiedType = GetType(Record[0]); |
| 3355 | QualType equivalentType = GetType(Record[1]); |
| 3356 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 3357 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 3358 | } |
| 3359 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3360 | case TYPE_PAREN: { |
| 3361 | if (Record.size() != 1) { |
| 3362 | Error("incorrect encoding of paren type"); |
| 3363 | return QualType(); |
| 3364 | } |
| 3365 | QualType InnerType = GetType(Record[0]); |
| 3366 | return Context->getParenType(InnerType); |
| 3367 | } |
| 3368 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3369 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3370 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3371 | Error("incorrect encoding of pack expansion type"); |
| 3372 | return QualType(); |
| 3373 | } |
| 3374 | QualType Pattern = GetType(Record[0]); |
| 3375 | if (Pattern.isNull()) |
| 3376 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3377 | llvm::Optional<unsigned> NumExpansions; |
| 3378 | if (Record[1]) |
| 3379 | NumExpansions = Record[1] - 1; |
| 3380 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3381 | } |
| 3382 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3383 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3384 | unsigned Idx = 0; |
| 3385 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3386 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3387 | QualType NamedType = GetType(Record[Idx++]); |
| 3388 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3389 | } |
| 3390 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3391 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3392 | unsigned Idx = 0; |
| 3393 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3394 | return Context->getObjCInterfaceType(ItfD); |
| 3395 | } |
| 3396 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3397 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3398 | unsigned Idx = 0; |
| 3399 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3400 | unsigned NumProtos = Record[Idx++]; |
| 3401 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 3402 | for (unsigned I = 0; I != NumProtos; ++I) |
| 3403 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3404 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3405 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3406 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3407 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3408 | unsigned Idx = 0; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3409 | QualType Pointee = GetType(Record[Idx++]); |
| 3410 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3411 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3412 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3413 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3414 | unsigned Idx = 0; |
| 3415 | QualType Parm = GetType(Record[Idx++]); |
| 3416 | QualType Replacement = GetType(Record[Idx++]); |
| 3417 | return |
| 3418 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3419 | Replacement); |
| 3420 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3421 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3422 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3423 | unsigned Idx = 0; |
| 3424 | QualType Parm = GetType(Record[Idx++]); |
| 3425 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3426 | return Context->getSubstTemplateTypeParmPackType( |
| 3427 | cast<TemplateTypeParmType>(Parm), |
| 3428 | ArgPack); |
| 3429 | } |
| 3430 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3431 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3432 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 3433 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3434 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3435 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3436 | return |
| 3437 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3438 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3439 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3440 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3441 | unsigned Idx = 0; |
| 3442 | unsigned Depth = Record[Idx++]; |
| 3443 | unsigned Index = Record[Idx++]; |
| 3444 | bool Pack = Record[Idx++]; |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 3445 | TemplateTypeParmDecl *D = |
| 3446 | cast_or_null<TemplateTypeParmDecl>(GetDecl(Record[Idx++])); |
| 3447 | return Context->getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3448 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3449 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3450 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3451 | unsigned Idx = 0; |
| 3452 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3453 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3454 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3455 | QualType Canon = GetType(Record[Idx++]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3456 | if (!Canon.isNull()) |
| 3457 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3458 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3459 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3460 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3461 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3462 | unsigned Idx = 0; |
| 3463 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3464 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3465 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
| 3466 | unsigned NumArgs = Record[Idx++]; |
| 3467 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 3468 | Args.reserve(NumArgs); |
| 3469 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3470 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3471 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3472 | Args.size(), Args.data()); |
| 3473 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3474 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3475 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3476 | unsigned Idx = 0; |
| 3477 | |
| 3478 | // ArrayType |
| 3479 | QualType ElementType = GetType(Record[Idx++]); |
| 3480 | ArrayType::ArraySizeModifier ASM |
| 3481 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3482 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3483 | |
| 3484 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3485 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3486 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3487 | |
| 3488 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3489 | IndexTypeQuals, Brackets); |
| 3490 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3491 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3492 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3493 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3494 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3495 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3496 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3497 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3498 | QualType Underlying = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3499 | QualType T; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3500 | if (Underlying.isNull()) |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3501 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3502 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3503 | else |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3504 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3505 | Args.size(), Underlying); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3506 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3507 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3508 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3509 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3510 | // Suppress a GCC warning |
| 3511 | return QualType(); |
| 3512 | } |
| 3513 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3514 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3515 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3516 | ASTReader::PerFileData &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3517 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3518 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3519 | unsigned &Idx; |
| 3520 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3521 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3522 | unsigned &I) { |
| 3523 | return Reader.ReadSourceLocation(F, R, I); |
| 3524 | } |
| 3525 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3526 | public: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3527 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3528 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3529 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3530 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3531 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3532 | // We want compile-time assurance that we've enumerated all of |
| 3533 | // these, so unfortunately we have to declare them first, then |
| 3534 | // define them out-of-line. |
| 3535 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3536 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3537 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3538 | #include "clang/AST/TypeLocNodes.def" |
| 3539 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3540 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3541 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3542 | }; |
| 3543 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3544 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3545 | // nothing to do |
| 3546 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3547 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3548 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3549 | if (TL.needsExtraLocalData()) { |
| 3550 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3551 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3552 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3553 | TL.setModeAttr(Record[Idx++]); |
| 3554 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3555 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3556 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3557 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3558 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3559 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3560 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3561 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3562 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3563 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3564 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3565 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3566 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3567 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3568 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3569 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3570 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3571 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3572 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3573 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3574 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3575 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3576 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3577 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3578 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3579 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3580 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3581 | TL.setSizeExpr(0); |
| 3582 | } |
| 3583 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3584 | VisitArrayTypeLoc(TL); |
| 3585 | } |
| 3586 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3587 | VisitArrayTypeLoc(TL); |
| 3588 | } |
| 3589 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3590 | VisitArrayTypeLoc(TL); |
| 3591 | } |
| 3592 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3593 | DependentSizedArrayTypeLoc TL) { |
| 3594 | VisitArrayTypeLoc(TL); |
| 3595 | } |
| 3596 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3597 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3598 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3599 | } |
| 3600 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3601 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3602 | } |
| 3603 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3604 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3605 | } |
| 3606 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3607 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 3608 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3609 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3610 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | 86acc2a | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 3611 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3612 | } |
| 3613 | } |
| 3614 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3615 | VisitFunctionTypeLoc(TL); |
| 3616 | } |
| 3617 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3618 | VisitFunctionTypeLoc(TL); |
| 3619 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3620 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3621 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3622 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3623 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3624 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3625 | } |
| 3626 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3627 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3628 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3629 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3630 | } |
| 3631 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3632 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3633 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3634 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3635 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3636 | } |
| 3637 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3638 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3639 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3640 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 3641 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 3642 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3643 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3644 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 3645 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3646 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3647 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3648 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3649 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3650 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3651 | } |
| 3652 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3653 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3654 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3655 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3656 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3657 | if (TL.hasAttrOperand()) { |
| 3658 | SourceRange range; |
| 3659 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3660 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3661 | TL.setAttrOperandParensRange(range); |
| 3662 | } |
| 3663 | if (TL.hasAttrExprOperand()) { |
| 3664 | if (Record[Idx++]) |
| 3665 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3666 | else |
| 3667 | TL.setAttrExprOperand(0); |
| 3668 | } else if (TL.hasAttrEnumOperand()) |
| 3669 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3670 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3671 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3672 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3673 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3674 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3675 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3676 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3677 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3678 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3679 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3680 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3681 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3682 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3683 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3684 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3685 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3686 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3687 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3688 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3689 | Reader.GetTemplateArgumentLocInfo(F, |
| 3690 | TL.getTypePtr()->getArg(i).getKind(), |
| 3691 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3692 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3693 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3694 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3695 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3696 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3697 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3698 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3699 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3700 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3701 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3702 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3703 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3704 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3705 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3706 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3707 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3708 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3709 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3710 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3711 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3712 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3713 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3714 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3715 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3716 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3717 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3718 | Reader.GetTemplateArgumentLocInfo(F, |
| 3719 | TL.getTypePtr()->getArg(I).getKind(), |
| 3720 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3721 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3722 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3723 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3724 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3725 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3726 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3727 | } |
| 3728 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3729 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3730 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3731 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3732 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3733 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3734 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3735 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3736 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3737 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3738 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3739 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3740 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3741 | unsigned &Idx) { |
| 3742 | QualType InfoTy = GetType(Record[Idx++]); |
| 3743 | if (InfoTy.isNull()) |
| 3744 | return 0; |
| 3745 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3746 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3747 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3748 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3749 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3750 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3751 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3752 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3753 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3754 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3755 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3756 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3757 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3758 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3759 | switch ((PredefinedTypeIDs)Index) { |
| 3760 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3761 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3762 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3763 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3764 | case PREDEF_TYPE_CHAR_U_ID: |
| 3765 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3766 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3767 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3768 | break; |
| 3769 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3770 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3771 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3772 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3773 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3774 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3775 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3776 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3777 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3778 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3779 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3780 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3781 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3782 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3783 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3784 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3785 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3786 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 3787 | case PREDEF_TYPE_BOUND_MEMBER: T = Context->BoundMemberTy; break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3788 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
John McCall | 1de4d4e | 2011-04-07 08:22:57 +0000 | [diff] [blame] | 3789 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context->UnknownAnyTy; break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3790 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3791 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3792 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3793 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3794 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3795 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3799 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3800 | } |
| 3801 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3802 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3803 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3804 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3805 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3806 | if (TypesLoaded[Index].isNull()) |
| 3807 | return QualType(); |
| 3808 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3809 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3810 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3811 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3812 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3813 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3814 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3815 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3816 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3817 | } |
| 3818 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3819 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3820 | return MakeTypeID(T, |
| 3821 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3822 | } |
| 3823 | |
| 3824 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3825 | if (T.isNull()) |
| 3826 | return TypeIdx(); |
| 3827 | assert(!T.getLocalFastQualifiers()); |
| 3828 | |
| 3829 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3830 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3831 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3832 | // If the type didn't come from the AST file use a specially marked index |
| 3833 | // so that any hash/key comparison fail since no such index is stored |
| 3834 | // in a AST file. |
| 3835 | if (I == TypeIdxs.end()) |
| 3836 | return TypeIdx(-1); |
| 3837 | return I->second; |
| 3838 | } |
| 3839 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3840 | unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const { |
| 3841 | unsigned Result = 0; |
| 3842 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 3843 | Result += Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3844 | |
| 3845 | return Result; |
| 3846 | } |
| 3847 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3848 | TemplateArgumentLocInfo |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3849 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3850 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3851 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3852 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3853 | switch (Kind) { |
| 3854 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3855 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3856 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3857 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3858 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3859 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3860 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3861 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3862 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3863 | SourceLocation()); |
| 3864 | } |
| 3865 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3866 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3867 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3868 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3869 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3870 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3871 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3872 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3873 | case TemplateArgument::Null: |
| 3874 | case TemplateArgument::Integral: |
| 3875 | case TemplateArgument::Declaration: |
| 3876 | case TemplateArgument::Pack: |
| 3877 | return TemplateArgumentLocInfo(); |
| 3878 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3879 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3880 | return TemplateArgumentLocInfo(); |
| 3881 | } |
| 3882 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3883 | TemplateArgumentLoc |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3884 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3885 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3886 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3887 | |
| 3888 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3889 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3890 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3891 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3892 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3893 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3894 | } |
| 3895 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3896 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3897 | return GetDecl(ID); |
| 3898 | } |
| 3899 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3900 | uint64_t |
| 3901 | ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) { |
| 3902 | if (ID == 0) |
| 3903 | return 0; |
| 3904 | |
| 3905 | --ID; |
| 3906 | uint64_t Offset = 0; |
| 3907 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3908 | PerFileData &F = *Chain[N - I - 1]; |
| 3909 | |
| 3910 | if (ID < F.LocalNumCXXBaseSpecifiers) |
| 3911 | return Offset + F.CXXBaseSpecifiersOffsets[ID]; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3912 | |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3913 | ID -= F.LocalNumCXXBaseSpecifiers; |
| 3914 | Offset += F.SizeInBits; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | assert(false && "CXXBaseSpecifiers not found"); |
| 3918 | return 0; |
| 3919 | } |
| 3920 | |
| 3921 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 3922 | // Figure out which AST file contains this offset. |
| 3923 | PerFileData *F = 0; |
| 3924 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3925 | if (Offset < Chain[N - I - 1]->SizeInBits) { |
| 3926 | F = Chain[N - I - 1]; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3927 | break; |
| 3928 | } |
| 3929 | |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3930 | Offset -= Chain[N - I - 1]->SizeInBits; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3931 | } |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3932 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3933 | if (!F) { |
| 3934 | Error("Malformed AST file: C++ base specifiers at impossible offset"); |
| 3935 | return 0; |
| 3936 | } |
| 3937 | |
| 3938 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3939 | SavedStreamPosition SavedPosition(Cursor); |
| 3940 | Cursor.JumpToBit(Offset); |
| 3941 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3942 | RecordData Record; |
| 3943 | unsigned Code = Cursor.ReadCode(); |
| 3944 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 3945 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 3946 | Error("Malformed AST file: missing C++ base specifiers"); |
| 3947 | return 0; |
| 3948 | } |
| 3949 | |
| 3950 | unsigned Idx = 0; |
| 3951 | unsigned NumBases = Record[Idx++]; |
| 3952 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 3953 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 3954 | for (unsigned I = 0; I != NumBases; ++I) |
| 3955 | Bases[I] = ReadCXXBaseSpecifier(*F, Record, Idx); |
| 3956 | return Bases; |
| 3957 | } |
| 3958 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3959 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3960 | if (!DeclsLoaded[0]) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 3961 | ReadDeclRecord(0, 1); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3962 | if (DeserializationListener) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3963 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3964 | } |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 3965 | |
| 3966 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 3967 | } |
| 3968 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3969 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3970 | if (ID == 0) |
| 3971 | return 0; |
| 3972 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3973 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3974 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3975 | return 0; |
| 3976 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3977 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3978 | unsigned Index = ID - 1; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3979 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3980 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3981 | if (DeserializationListener) |
| 3982 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3983 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3984 | |
| 3985 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3986 | } |
| 3987 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3988 | /// \brief Resolve the offset of a statement into a statement. |
| 3989 | /// |
| 3990 | /// This operation will read a new statement from the external |
| 3991 | /// source each time it is called, and is meant to be used via a |
| 3992 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3993 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 3994 | // Switch case IDs are per Decl. |
| 3995 | ClearSwitchCaseIDs(); |
| 3996 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3997 | // Offset here is a global offset across the entire chain. |
| 3998 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3999 | PerFileData &F = *Chain[N - I - 1]; |
| 4000 | if (Offset < F.SizeInBits) { |
| 4001 | // Since we know that this statement is part of a decl, make sure to use |
| 4002 | // the decl cursor to read it. |
| 4003 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4004 | return ReadStmtFromStream(F); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4005 | } |
| 4006 | Offset -= F.SizeInBits; |
| 4007 | } |
| 4008 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 4009 | } |
| 4010 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4011 | bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4012 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4013 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4014 | assert(DC->hasExternalLexicalStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4015 | "DeclContext has no lexical decls in storage"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4016 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4017 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 4018 | // at least. |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 4019 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 4020 | // so make a copy of the vector. |
| 4021 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4022 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 4023 | I != E; ++I) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4024 | // IDs can be 0 if this context doesn't contain declarations. |
| 4025 | if (!I->LexicalDecls) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4026 | continue; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4027 | |
| 4028 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4029 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 4030 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 4031 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 4032 | continue; |
| 4033 | |
| 4034 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 4035 | assert(D && "Null decl in lexical decls"); |
| 4036 | Decls.push_back(D); |
| 4037 | } |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4038 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4039 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4040 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4041 | return false; |
| 4042 | } |
| 4043 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4044 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4045 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4046 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4047 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4048 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4049 | if (!Name) |
| 4050 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 4051 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4052 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4053 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 8b12273 | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 4054 | // 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] | 4055 | // and namespaces. For any given name, the last available results replace |
| 4056 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4057 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 4058 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4059 | I != E; ++I) { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4060 | if (!I->NameLookupTableData) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4061 | continue; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4062 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4063 | ASTDeclContextNameLookupTable *LookupTable = |
| 4064 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 4065 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 4066 | if (Pos == LookupTable->end()) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4067 | continue; |
| 4068 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4069 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 4070 | for (; Data.first != Data.second; ++Data.first) |
| 4071 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 4072 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4073 | } |
| 4074 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4075 | ++NumVisibleDeclContextsRead; |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4076 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4077 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4078 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4079 | } |
| 4080 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 4081 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 4082 | assert(DC->hasExternalVisibleStorage() && |
| 4083 | "DeclContext has no visible decls in storage"); |
| 4084 | |
| 4085 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 4086 | // There might be visible decls in multiple parts of the chain, for the TU |
| 4087 | // and namespaces. |
| 4088 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 4089 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 4090 | I != E; ++I) { |
| 4091 | if (!I->NameLookupTableData) |
| 4092 | continue; |
| 4093 | |
| 4094 | ASTDeclContextNameLookupTable *LookupTable = |
| 4095 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 4096 | for (ASTDeclContextNameLookupTable::item_iterator |
| 4097 | ItemI = LookupTable->item_begin(), |
| 4098 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 4099 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 4100 | = *ItemI; |
| 4101 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 4102 | Decls.clear(); |
| 4103 | for (; Data.first != Data.second; ++Data.first) |
| 4104 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 4105 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 4106 | } |
| 4107 | } |
| 4108 | } |
| 4109 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4110 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4111 | assert(Consumer); |
| 4112 | while (!InterestingDecls.empty()) { |
| 4113 | DeclGroupRef DG(InterestingDecls.front()); |
| 4114 | InterestingDecls.pop_front(); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 4115 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4116 | } |
| 4117 | } |
| 4118 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4119 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 4120 | this->Consumer = Consumer; |
| 4121 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4122 | if (!Consumer) |
| 4123 | return; |
| 4124 | |
| 4125 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4126 | // Force deserialization of this decl, which will cause it to be queued for |
| 4127 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 4128 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4129 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 4130 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4131 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4132 | } |
| 4133 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4134 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4135 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4136 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4137 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4138 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4139 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4140 | unsigned NumDeclsLoaded |
| 4141 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 4142 | (Decl *)0); |
| 4143 | unsigned NumIdentifiersLoaded |
| 4144 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 4145 | IdentifiersLoaded.end(), |
| 4146 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4147 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4148 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 4149 | SelectorsLoaded.end(), |
| 4150 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 4151 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4152 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 4153 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4154 | if (TotalNumSLocEntries) |
| 4155 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 4156 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 4157 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4158 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4159 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4160 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 4161 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 4162 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4163 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4164 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 4165 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4166 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4167 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4168 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4169 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4170 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4171 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4172 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4173 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4174 | if (TotalNumStatements) |
| 4175 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4176 | NumStatementsRead, TotalNumStatements, |
| 4177 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4178 | if (TotalNumMacros) |
| 4179 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4180 | NumMacrosRead, TotalNumMacros, |
| 4181 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4182 | if (TotalLexicalDeclContexts) |
| 4183 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4184 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4185 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4186 | * 100)); |
| 4187 | if (TotalVisibleDeclContexts) |
| 4188 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4189 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4190 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4191 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4192 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4193 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4194 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4195 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4196 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4197 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4198 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4199 | std::fprintf(stderr, "\n"); |
| 4200 | } |
| 4201 | |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4202 | /// Return the amount of memory used by memory buffers, breaking down |
| 4203 | /// by heap-backed versus mmap'ed memory. |
| 4204 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
| 4205 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 4206 | if (llvm::MemoryBuffer *buf = Chain[i]->Buffer.get()) { |
| 4207 | size_t bytes = buf->getBufferSize(); |
| 4208 | switch (buf->getBufferKind()) { |
| 4209 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 4210 | sizes.malloc_bytes += bytes; |
| 4211 | break; |
| 4212 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 4213 | sizes.mmap_bytes += bytes; |
| 4214 | break; |
| 4215 | } |
| 4216 | } |
| 4217 | } |
| 4218 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4219 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4220 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4221 | S.ExternalSource = this; |
| 4222 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4223 | // Makes sure any declarations that were deserialized "too early" |
| 4224 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4225 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4226 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4227 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4228 | |
| 4229 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4230 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4231 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4232 | |
| 4233 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4234 | // them to Sema's list of tentative definitions. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4235 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4236 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4237 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4238 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 4239 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4240 | // If there were any unused file scoped decls, deserialize them and add to |
| 4241 | // Sema's list of unused file scoped decls. |
| 4242 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4243 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4244 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 4245 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4246 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4247 | // If there were any delegating constructors, add them to Sema's list |
| 4248 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 4249 | CXXConstructorDecl *D |
| 4250 | = cast<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 4251 | SemaObj->DelegatingCtorDecls.push_back(D); |
| 4252 | } |
| 4253 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4254 | // If there were any locally-scoped external declarations, |
| 4255 | // deserialize them and add them to Sema's table of locally-scoped |
| 4256 | // external declarations. |
| 4257 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4258 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4259 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 4260 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4261 | |
| 4262 | // If there were any ext_vector type declarations, deserialize them |
| 4263 | // and add them to Sema's vector of such declarations. |
| 4264 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 4265 | SemaObj->ExtVectorDecls.push_back( |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4266 | cast<TypedefNameDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4267 | |
| 4268 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 4269 | // Can we cut them down before writing them ? |
| 4270 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4271 | // If there were any dynamic classes declarations, deserialize them |
| 4272 | // and add them to Sema's vector of such declarations. |
| 4273 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 4274 | SemaObj->DynamicClasses.push_back( |
| 4275 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4276 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4277 | // Load the offsets of the declarations that Sema references. |
| 4278 | // They will be lazily deserialized when needed. |
| 4279 | if (!SemaDeclRefs.empty()) { |
| 4280 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 4281 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4282 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 4283 | } |
| 4284 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4285 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 4286 | |
| 4287 | // If there are @selector references added them to its pool. This is for |
| 4288 | // implementation of -Wselector. |
| 4289 | if (!F->ReferencedSelectorsData.empty()) { |
| 4290 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 4291 | unsigned I = 0; |
| 4292 | while (I < DataSize) { |
| 4293 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 4294 | SourceLocation SelLoc = ReadSourceLocation( |
| 4295 | *F, F->ReferencedSelectorsData, I); |
| 4296 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 4297 | } |
| 4298 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4299 | } |
| 4300 | |
Sebastian Redl | c1d3ffb | 2011-04-24 16:27:30 +0000 | [diff] [blame] | 4301 | // The special data sets below always come from the most recent PCH, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4302 | // which is at the front of the chain. |
| 4303 | PerFileData &F = *Chain.front(); |
| 4304 | |
Sebastian Redl | c1d3ffb | 2011-04-24 16:27:30 +0000 | [diff] [blame] | 4305 | // If there were any pending implicit instantiations, deserialize them |
| 4306 | // and add them to Sema's queue of such instantiations. |
| 4307 | assert(F.PendingInstantiations.size() % 2 == 0 && |
| 4308 | "Expected pairs of entries"); |
| 4309 | for (unsigned Idx = 0, N = F.PendingInstantiations.size(); Idx < N;) { |
| 4310 | ValueDecl *D=cast<ValueDecl>(GetDecl(F.PendingInstantiations[Idx++])); |
| 4311 | SourceLocation Loc = ReadSourceLocation(F, F.PendingInstantiations,Idx); |
| 4312 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 4313 | } |
| 4314 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4315 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 4316 | // Sema's list of weak undeclared identifiers. |
| 4317 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 4318 | unsigned Idx = 0; |
| 4319 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 4320 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4321 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4322 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 4323 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 4324 | Sema::WeakInfo WI(AliasId, Loc); |
| 4325 | WI.setUsed(Used); |
| 4326 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 4327 | } |
| 4328 | } |
| 4329 | |
| 4330 | // If there were any VTable uses, deserialize the information and add it |
| 4331 | // to Sema's vector and map of VTable uses. |
| 4332 | if (!VTableUses.empty()) { |
| 4333 | unsigned Idx = 0; |
| 4334 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 4335 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4336 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 4337 | bool DefinitionRequired = VTableUses[Idx++]; |
| 4338 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 4339 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4340 | } |
| 4341 | } |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4342 | |
| 4343 | if (!FPPragmaOptions.empty()) { |
| 4344 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4345 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4346 | } |
| 4347 | |
| 4348 | if (!OpenCLExtensions.empty()) { |
| 4349 | unsigned I = 0; |
| 4350 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4351 | #include "clang/Basic/OpenCLExtensions.def" |
| 4352 | |
| 4353 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4354 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4355 | } |
| 4356 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4357 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4358 | // Try to find this name within our on-disk hash tables. We start with the |
| 4359 | // 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] | 4360 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4361 | ASTIdentifierLookupTable *IdTable |
| 4362 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4363 | if (!IdTable) |
| 4364 | continue; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4365 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4366 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4367 | if (Pos == IdTable->end()) |
| 4368 | continue; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4369 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4370 | // Dereferencing the iterator has the effect of building the |
| 4371 | // IdentifierInfo node and populating it with the various |
| 4372 | // declarations it needs. |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4373 | return *Pos; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4374 | } |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4375 | return 0; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4376 | } |
| 4377 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4378 | namespace clang { |
| 4379 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4380 | /// identifiers stored within a set of AST files. |
| 4381 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4382 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4383 | const ASTReader &Reader; |
| 4384 | |
| 4385 | /// \brief The current index into the chain of AST files stored in |
| 4386 | /// the AST reader. |
| 4387 | unsigned Index; |
| 4388 | |
| 4389 | /// \brief The current position within the identifier lookup table |
| 4390 | /// of the current AST file. |
| 4391 | ASTIdentifierLookupTable::key_iterator Current; |
| 4392 | |
| 4393 | /// \brief The end position within the identifier lookup table of |
| 4394 | /// the current AST file. |
| 4395 | ASTIdentifierLookupTable::key_iterator End; |
| 4396 | |
| 4397 | public: |
| 4398 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4399 | |
| 4400 | virtual llvm::StringRef Next(); |
| 4401 | }; |
| 4402 | } |
| 4403 | |
| 4404 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 4405 | : Reader(Reader), Index(Reader.Chain.size() - 1) { |
| 4406 | ASTIdentifierLookupTable *IdTable |
| 4407 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4408 | Current = IdTable->key_begin(); |
| 4409 | End = IdTable->key_end(); |
| 4410 | } |
| 4411 | |
| 4412 | llvm::StringRef ASTIdentifierIterator::Next() { |
| 4413 | while (Current == End) { |
| 4414 | // If we have exhausted all of our AST files, we're done. |
| 4415 | if (Index == 0) |
| 4416 | return llvm::StringRef(); |
| 4417 | |
| 4418 | --Index; |
| 4419 | ASTIdentifierLookupTable *IdTable |
| 4420 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4421 | Current = IdTable->key_begin(); |
| 4422 | End = IdTable->key_end(); |
| 4423 | } |
| 4424 | |
| 4425 | // We have any identifiers remaining in the current AST file; return |
| 4426 | // the next one. |
| 4427 | std::pair<const char*, unsigned> Key = *Current; |
| 4428 | ++Current; |
| 4429 | return llvm::StringRef(Key.first, Key.second); |
| 4430 | } |
| 4431 | |
| 4432 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4433 | return new ASTIdentifierIterator(*this); |
| 4434 | } |
| 4435 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4436 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4437 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4438 | // Find this selector in a hash table. We want to find the most recent entry. |
| 4439 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4440 | PerFileData &F = *Chain[I]; |
| 4441 | if (!F.SelectorLookupTable) |
| 4442 | continue; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4443 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4444 | ASTSelectorLookupTable *PoolTable |
| 4445 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 4446 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4447 | if (Pos != PoolTable->end()) { |
| 4448 | ++NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4449 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4450 | // disable this tracking when called via LoadSelector. |
| 4451 | // Also, should entries without methods count as misses? |
| 4452 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4453 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4454 | if (DeserializationListener) |
| 4455 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 4456 | return std::make_pair(Data.Instance, Data.Factory); |
| 4457 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4458 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4459 | |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4460 | ++NumMethodPoolMisses; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4461 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4464 | void ASTReader::ReadKnownNamespaces( |
| 4465 | llvm::SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
| 4466 | Namespaces.clear(); |
| 4467 | |
| 4468 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 4469 | if (NamespaceDecl *Namespace |
| 4470 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 4471 | Namespaces.push_back(Namespace); |
| 4472 | } |
| 4473 | } |
| 4474 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4475 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4476 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4477 | ReadMethodPool(Sel); |
| 4478 | } |
| 4479 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4480 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4481 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4482 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4483 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4484 | if (DeserializationListener) |
| 4485 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4486 | } |
| 4487 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4488 | /// \brief Set the globally-visible declarations associated with the given |
| 4489 | /// identifier. |
| 4490 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4491 | /// 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] | 4492 | /// 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] | 4493 | /// them. |
| 4494 | /// |
| 4495 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4496 | /// declarations. |
| 4497 | /// |
| 4498 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4499 | /// visible at global scope. |
| 4500 | /// |
| 4501 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4502 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4503 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4504 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4505 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4506 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 4507 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4508 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4509 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4510 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4511 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4512 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4513 | return; |
| 4514 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4515 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4516 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4517 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4518 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4519 | if (SemaObj->TUScope) { |
| 4520 | // Introduce this declaration into the translation-unit scope |
| 4521 | // and add it to the declaration chain for this identifier, so |
| 4522 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4523 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4524 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4525 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4526 | } else { |
| 4527 | // Queue this declaration so that it will be added to the |
| 4528 | // translation unit scope and identifier's declaration chain |
| 4529 | // once a Sema object is known. |
| 4530 | PreloadedDecls.push_back(D); |
| 4531 | } |
| 4532 | } |
| 4533 | } |
| 4534 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4535 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4536 | if (ID == 0) |
| 4537 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4538 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4539 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4540 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4541 | return 0; |
| 4542 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4543 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4544 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4545 | ID -= 1; |
| 4546 | if (!IdentifiersLoaded[ID]) { |
| 4547 | unsigned Index = ID; |
| 4548 | const char *Str = 0; |
| 4549 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4550 | PerFileData *F = Chain[N - I - 1]; |
| 4551 | if (Index < F->LocalNumIdentifiers) { |
| 4552 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 4553 | Str = F->IdentifierTableData + Offset; |
| 4554 | break; |
| 4555 | } |
| 4556 | Index -= F->LocalNumIdentifiers; |
| 4557 | } |
| 4558 | assert(Str && "Broken Chain"); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4559 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4560 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4561 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4562 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4563 | // unsigned integers. This is important to avoid integer overflow when |
| 4564 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4565 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4566 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4567 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4568 | IdentifiersLoaded[ID] |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 4569 | = &PP->getIdentifierTable().get(llvm::StringRef(Str, StrLen)); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4570 | if (DeserializationListener) |
| 4571 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4572 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4573 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4574 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4575 | } |
| 4576 | |
Douglas Gregor | e23ac65 | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 4577 | bool ASTReader::ReadSLocEntry(unsigned ID) { |
| 4578 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4579 | } |
| 4580 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4581 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4582 | if (ID == 0) |
| 4583 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4584 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4585 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4586 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4587 | return Selector(); |
| 4588 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4589 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4590 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4591 | // Load this selector from the selector table. |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4592 | unsigned Idx = ID - 1; |
| 4593 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4594 | PerFileData &F = *Chain[N - I - 1]; |
| 4595 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4596 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4597 | SelectorsLoaded[ID - 1] = |
| 4598 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 4599 | if (DeserializationListener) |
| 4600 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 4601 | break; |
| 4602 | } |
| 4603 | Idx -= F.LocalNumSelectors; |
| 4604 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4605 | } |
| 4606 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4607 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4608 | } |
| 4609 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4610 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4611 | return DecodeSelector(ID); |
| 4612 | } |
| 4613 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4614 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4615 | // ID 0 (the null selector) is considered an external selector. |
| 4616 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4617 | } |
| 4618 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4619 | DeclarationName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4620 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4621 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4622 | switch (Kind) { |
| 4623 | case DeclarationName::Identifier: |
| 4624 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 4625 | |
| 4626 | case DeclarationName::ObjCZeroArgSelector: |
| 4627 | case DeclarationName::ObjCOneArgSelector: |
| 4628 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 4629 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4630 | |
| 4631 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4632 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4633 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4634 | |
| 4635 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4636 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4637 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4638 | |
| 4639 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4640 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4641 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4642 | |
| 4643 | case DeclarationName::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4644 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4645 | (OverloadedOperatorKind)Record[Idx++]); |
| 4646 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4647 | case DeclarationName::CXXLiteralOperatorName: |
| 4648 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 4649 | GetIdentifierInfo(Record, Idx)); |
| 4650 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4651 | case DeclarationName::CXXUsingDirective: |
| 4652 | return DeclarationName::getUsingDirectiveName(); |
| 4653 | } |
| 4654 | |
| 4655 | // Required to silence GCC warning |
| 4656 | return DeclarationName(); |
| 4657 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4658 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4659 | void ASTReader::ReadDeclarationNameLoc(PerFileData &F, |
| 4660 | DeclarationNameLoc &DNLoc, |
| 4661 | DeclarationName Name, |
| 4662 | const RecordData &Record, unsigned &Idx) { |
| 4663 | switch (Name.getNameKind()) { |
| 4664 | case DeclarationName::CXXConstructorName: |
| 4665 | case DeclarationName::CXXDestructorName: |
| 4666 | case DeclarationName::CXXConversionFunctionName: |
| 4667 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4668 | break; |
| 4669 | |
| 4670 | case DeclarationName::CXXOperatorName: |
| 4671 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4672 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4673 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4674 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4675 | break; |
| 4676 | |
| 4677 | case DeclarationName::CXXLiteralOperatorName: |
| 4678 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4679 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4680 | break; |
| 4681 | |
| 4682 | case DeclarationName::Identifier: |
| 4683 | case DeclarationName::ObjCZeroArgSelector: |
| 4684 | case DeclarationName::ObjCOneArgSelector: |
| 4685 | case DeclarationName::ObjCMultiArgSelector: |
| 4686 | case DeclarationName::CXXUsingDirective: |
| 4687 | break; |
| 4688 | } |
| 4689 | } |
| 4690 | |
| 4691 | void ASTReader::ReadDeclarationNameInfo(PerFileData &F, |
| 4692 | DeclarationNameInfo &NameInfo, |
| 4693 | const RecordData &Record, unsigned &Idx) { |
| 4694 | NameInfo.setName(ReadDeclarationName(Record, Idx)); |
| 4695 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4696 | DeclarationNameLoc DNLoc; |
| 4697 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4698 | NameInfo.setInfo(DNLoc); |
| 4699 | } |
| 4700 | |
| 4701 | void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info, |
| 4702 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4703 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4704 | unsigned NumTPLists = Record[Idx++]; |
| 4705 | Info.NumTemplParamLists = NumTPLists; |
| 4706 | if (NumTPLists) { |
| 4707 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 4708 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4709 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4710 | } |
| 4711 | } |
| 4712 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4713 | TemplateName |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4714 | ASTReader::ReadTemplateName(PerFileData &F, const RecordData &Record, |
| 4715 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4716 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4717 | switch (Kind) { |
| 4718 | case TemplateName::Template: |
| 4719 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 4720 | |
| 4721 | case TemplateName::OverloadedTemplate: { |
| 4722 | unsigned size = Record[Idx++]; |
| 4723 | UnresolvedSet<8> Decls; |
| 4724 | while (size--) |
| 4725 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 4726 | |
| 4727 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 4728 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4729 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4730 | case TemplateName::QualifiedTemplate: { |
| 4731 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4732 | bool hasTemplKeyword = Record[Idx++]; |
| 4733 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 4734 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 4735 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4736 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4737 | case TemplateName::DependentTemplate: { |
| 4738 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4739 | if (Record[Idx++]) // isIdentifier |
| 4740 | return Context->getDependentTemplateName(NNS, |
| 4741 | GetIdentifierInfo(Record, Idx)); |
| 4742 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4743 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4744 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 4745 | |
| 4746 | case TemplateName::SubstTemplateTemplateParm: { |
| 4747 | TemplateTemplateParmDecl *param |
| 4748 | = cast_or_null<TemplateTemplateParmDecl>(GetDecl(Record[Idx++])); |
| 4749 | if (!param) return TemplateName(); |
| 4750 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
| 4751 | return Context->getSubstTemplateTemplateParm(param, replacement); |
| 4752 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4753 | |
| 4754 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4755 | TemplateTemplateParmDecl *Param |
| 4756 | = cast_or_null<TemplateTemplateParmDecl>(GetDecl(Record[Idx++])); |
| 4757 | if (!Param) |
| 4758 | return TemplateName(); |
| 4759 | |
| 4760 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 4761 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 4762 | return TemplateName(); |
| 4763 | |
| 4764 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 4765 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4766 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4767 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4768 | assert(0 && "Unhandled template name kind!"); |
| 4769 | return TemplateName(); |
| 4770 | } |
| 4771 | |
| 4772 | TemplateArgument |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4773 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4774 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4775 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 4776 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4777 | case TemplateArgument::Null: |
| 4778 | return TemplateArgument(); |
| 4779 | case TemplateArgument::Type: |
| 4780 | return TemplateArgument(GetType(Record[Idx++])); |
| 4781 | case TemplateArgument::Declaration: |
| 4782 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4783 | case TemplateArgument::Integral: { |
| 4784 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 4785 | QualType T = GetType(Record[Idx++]); |
| 4786 | return TemplateArgument(Value, T); |
| 4787 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4788 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4789 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4790 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4791 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4792 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 4793 | if (unsigned NumExpansions = Record[Idx++]) |
| 4794 | NumTemplateExpansions = NumExpansions - 1; |
| 4795 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4796 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4797 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4798 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4799 | case TemplateArgument::Pack: { |
| 4800 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4801 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 4802 | for (unsigned I = 0; I != NumArgs; ++I) |
| 4803 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 4804 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4805 | } |
| 4806 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4807 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4808 | assert(0 && "Unhandled template argument kind!"); |
| 4809 | return TemplateArgument(); |
| 4810 | } |
| 4811 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4812 | TemplateParameterList * |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4813 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 4814 | const RecordData &Record, unsigned &Idx) { |
| 4815 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 4816 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 4817 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4818 | |
| 4819 | unsigned NumParams = Record[Idx++]; |
| 4820 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 4821 | Params.reserve(NumParams); |
| 4822 | while (NumParams--) |
| 4823 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4824 | |
| 4825 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4826 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 4827 | Params.data(), Params.size(), RAngleLoc); |
| 4828 | return TemplateParams; |
| 4829 | } |
| 4830 | |
| 4831 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4832 | ASTReader:: |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4833 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4834 | PerFileData &F, const RecordData &Record, |
| 4835 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4836 | unsigned NumTemplateArgs = Record[Idx++]; |
| 4837 | TemplArgs.reserve(NumTemplateArgs); |
| 4838 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4839 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4840 | } |
| 4841 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4842 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4843 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4844 | const RecordData &Record, unsigned &Idx) { |
| 4845 | unsigned NumDecls = Record[Idx++]; |
| 4846 | while (NumDecls--) { |
| 4847 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 4848 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 4849 | Set.addDecl(D, AS); |
| 4850 | } |
| 4851 | } |
| 4852 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4853 | CXXBaseSpecifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4854 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4855 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4856 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 4857 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 4858 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4859 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4860 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4861 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4862 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4863 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4864 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4865 | Result.setInheritConstructors(inheritConstructors); |
| 4866 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4867 | } |
| 4868 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4869 | std::pair<CXXCtorInitializer **, unsigned> |
| 4870 | ASTReader::ReadCXXCtorInitializers(PerFileData &F, const RecordData &Record, |
| 4871 | unsigned &Idx) { |
| 4872 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4873 | unsigned NumInitializers = Record[Idx++]; |
| 4874 | if (NumInitializers) { |
| 4875 | ASTContext &C = *getContext(); |
| 4876 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4877 | CtorInitializers |
| 4878 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4879 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 4880 | TypeSourceInfo *BaseClassInfo = 0; |
| 4881 | bool IsBaseVirtual = false; |
| 4882 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4883 | IndirectFieldDecl *IndirectMember = 0; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4884 | CXXConstructorDecl *Target = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4885 | |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4886 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 4887 | switch (Type) { |
| 4888 | case CTOR_INITIALIZER_BASE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4889 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4890 | IsBaseVirtual = Record[Idx++]; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4891 | break; |
| 4892 | |
| 4893 | case CTOR_INITIALIZER_DELEGATING: |
| 4894 | Target = cast<CXXConstructorDecl>(GetDecl(Record[Idx++])); |
| 4895 | break; |
| 4896 | |
| 4897 | case CTOR_INITIALIZER_MEMBER: |
| 4898 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
| 4899 | break; |
| 4900 | |
| 4901 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
| 4902 | IndirectMember = cast<IndirectFieldDecl>(GetDecl(Record[Idx++])); |
| 4903 | break; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4904 | } |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4905 | |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 4906 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4907 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4908 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 4909 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4910 | bool IsWritten = Record[Idx++]; |
| 4911 | unsigned SourceOrderOrNumArrayIndices; |
| 4912 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 4913 | if (IsWritten) { |
| 4914 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4915 | } else { |
| 4916 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4917 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 4918 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 4919 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 4920 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4921 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4922 | CXXCtorInitializer *BOMInit; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4923 | if (Type == CTOR_INITIALIZER_BASE) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4924 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 4925 | LParenLoc, Init, RParenLoc, |
| 4926 | MemberOrEllipsisLoc); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4927 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
| 4928 | BOMInit = new (C) CXXCtorInitializer(C, MemberOrEllipsisLoc, LParenLoc, |
| 4929 | Target, Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4930 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4931 | if (Member) |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4932 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 4933 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4934 | else |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4935 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 4936 | MemberOrEllipsisLoc, LParenLoc, |
| 4937 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4938 | } else { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4939 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 4940 | LParenLoc, Init, RParenLoc, |
| 4941 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 4944 | if (IsWritten) |
| 4945 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4946 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4947 | } |
| 4948 | } |
| 4949 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4950 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4951 | } |
| 4952 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4953 | NestedNameSpecifier * |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4954 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4955 | unsigned N = Record[Idx++]; |
| 4956 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 4957 | for (unsigned I = 0; I != N; ++I) { |
| 4958 | NestedNameSpecifier::SpecifierKind Kind |
| 4959 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4960 | switch (Kind) { |
| 4961 | case NestedNameSpecifier::Identifier: { |
| 4962 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 4963 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 4964 | break; |
| 4965 | } |
| 4966 | |
| 4967 | case NestedNameSpecifier::Namespace: { |
| 4968 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 4969 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 4970 | break; |
| 4971 | } |
| 4972 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 4973 | case NestedNameSpecifier::NamespaceAlias: { |
| 4974 | NamespaceAliasDecl *Alias |
| 4975 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
| 4976 | NNS = NestedNameSpecifier::Create(*Context, Prev, Alias); |
| 4977 | break; |
| 4978 | } |
| 4979 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4980 | case NestedNameSpecifier::TypeSpec: |
| 4981 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4982 | const Type *T = GetType(Record[Idx++]).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 4983 | if (!T) |
| 4984 | return 0; |
| 4985 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4986 | bool Template = Record[Idx++]; |
| 4987 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 4988 | break; |
| 4989 | } |
| 4990 | |
| 4991 | case NestedNameSpecifier::Global: { |
| 4992 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4993 | // No associated value, and there can't be a prefix. |
| 4994 | break; |
| 4995 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4996 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 4997 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4998 | } |
| 4999 | return NNS; |
| 5000 | } |
| 5001 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5002 | NestedNameSpecifierLoc |
| 5003 | ASTReader::ReadNestedNameSpecifierLoc(PerFileData &F, const RecordData &Record, |
| 5004 | unsigned &Idx) { |
| 5005 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5006 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5007 | for (unsigned I = 0; I != N; ++I) { |
| 5008 | NestedNameSpecifier::SpecifierKind Kind |
| 5009 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5010 | switch (Kind) { |
| 5011 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5012 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5013 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5014 | Builder.Extend(*Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5015 | break; |
| 5016 | } |
| 5017 | |
| 5018 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5019 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5020 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5021 | Builder.Extend(*Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5022 | break; |
| 5023 | } |
| 5024 | |
| 5025 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5026 | NamespaceAliasDecl *Alias |
| 5027 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5028 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5029 | Builder.Extend(*Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5030 | break; |
| 5031 | } |
| 5032 | |
| 5033 | case NestedNameSpecifier::TypeSpec: |
| 5034 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5035 | bool Template = Record[Idx++]; |
| 5036 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 5037 | if (!T) |
| 5038 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5039 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5040 | |
| 5041 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
| 5042 | Builder.Extend(*Context, |
| 5043 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 5044 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5045 | break; |
| 5046 | } |
| 5047 | |
| 5048 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5049 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5050 | Builder.MakeGlobal(*Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5051 | break; |
| 5052 | } |
| 5053 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5054 | } |
| 5055 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5056 | return Builder.getWithLocInContext(*Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5057 | } |
| 5058 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5059 | SourceRange |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5060 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 5061 | unsigned &Idx) { |
| 5062 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 5063 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 5064 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5065 | } |
| 5066 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5067 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5068 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5069 | unsigned BitWidth = Record[Idx++]; |
| 5070 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 5071 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 5072 | Idx += NumWords; |
| 5073 | return Result; |
| 5074 | } |
| 5075 | |
| 5076 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5077 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5078 | bool isUnsigned = Record[Idx++]; |
| 5079 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 5080 | } |
| 5081 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5082 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5083 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5084 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 5085 | } |
| 5086 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5087 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5088 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5089 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 5090 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5091 | Idx += Len; |
| 5092 | return Result; |
| 5093 | } |
| 5094 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 5095 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 5096 | unsigned &Idx) { |
| 5097 | unsigned Major = Record[Idx++]; |
| 5098 | unsigned Minor = Record[Idx++]; |
| 5099 | unsigned Subminor = Record[Idx++]; |
| 5100 | if (Minor == 0) |
| 5101 | return VersionTuple(Major); |
| 5102 | if (Subminor == 0) |
| 5103 | return VersionTuple(Major, Minor - 1); |
| 5104 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 5105 | } |
| 5106 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5107 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5108 | unsigned &Idx) { |
| 5109 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 5110 | return CXXTemporary::Create(*Context, Decl); |
| 5111 | } |
| 5112 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5113 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 5114 | return Diag(SourceLocation(), DiagID); |
| 5115 | } |
| 5116 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5117 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5118 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5119 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5120 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5121 | /// \brief Retrieve the identifier table associated with the |
| 5122 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5123 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 5124 | assert(PP && "Forgot to set Preprocessor ?"); |
| 5125 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5126 | } |
| 5127 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5128 | /// \brief Record that the given ID maps to the given switch-case |
| 5129 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5130 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5131 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 5132 | SwitchCaseStmts[ID] = SC; |
| 5133 | } |
| 5134 | |
| 5135 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5136 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5137 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 5138 | return SwitchCaseStmts[ID]; |
| 5139 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 5140 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 5141 | void ASTReader::ClearSwitchCaseIDs() { |
| 5142 | SwitchCaseStmts.clear(); |
| 5143 | } |
| 5144 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5145 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5146 | assert(NumCurrentElementsDeserializing && |
| 5147 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 5148 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5149 | // If any identifiers with corresponding top-level declarations have |
| 5150 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5151 | while (!PendingIdentifierInfos.empty()) { |
| 5152 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 5153 | PendingIdentifierInfos.front().DeclIDs, true); |
| 5154 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5155 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5156 | |
Argyrios Kyrtzidis | 0895d15 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 5157 | // Ready to load previous declarations of Decls that were delayed. |
| 5158 | while (!PendingPreviousDecls.empty()) { |
| 5159 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 5160 | PendingPreviousDecls.front().second); |
| 5161 | PendingPreviousDecls.pop_front(); |
| 5162 | } |
| 5163 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5164 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 5165 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5166 | if (Consumer) |
| 5167 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 5168 | |
| 5169 | assert(PendingForwardRefs.size() == 0 && |
| 5170 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5171 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5172 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5173 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5174 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5175 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5176 | const char *isysroot, bool DisableValidation, |
| 5177 | bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5178 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 5179 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 5180 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
| 5181 | Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5182 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 5183 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), NextSLocOffset(0), |
| 5184 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 5185 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 5186 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 5187 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
| 5188 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 5189 | NumCurrentElementsDeserializing(0) |
| 5190 | { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5191 | RelocatablePCH = false; |
| 5192 | } |
| 5193 | |
| 5194 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 5195 | Diagnostic &Diags, const char *isysroot, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5196 | bool DisableValidation, bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5197 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
| 5198 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5199 | isysroot(isysroot), DisableValidation(DisableValidation), |
| 5200 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
| 5201 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 5202 | NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0), |
| 5203 | NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), |
| 5204 | NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
| 5205 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 5206 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 5207 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5208 | RelocatablePCH = false; |
| 5209 | } |
| 5210 | |
| 5211 | ASTReader::~ASTReader() { |
| 5212 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 5213 | delete Chain[e - i - 1]; |
| 5214 | // Delete all visible decl lookup tables |
| 5215 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 5216 | E = DeclContextOffsets.end(); |
| 5217 | I != E; ++I) { |
| 5218 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 5219 | J != F; ++J) { |
| 5220 | if (J->NameLookupTableData) |
| 5221 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 5222 | J->NameLookupTableData); |
| 5223 | } |
| 5224 | } |
| 5225 | for (DeclContextVisibleUpdatesPending::iterator |
| 5226 | I = PendingVisibleUpdates.begin(), |
| 5227 | E = PendingVisibleUpdates.end(); |
| 5228 | I != E; ++I) { |
| 5229 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5230 | F = I->second.end(); |
| 5231 | J != F; ++J) |
| 5232 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 5233 | } |
| 5234 | } |
| 5235 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 5236 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 5237 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), |
| 5238 | SLocFileOffsets(0), LocalSLocSize(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5239 | LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), |
| 5240 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5241 | MacroDefinitionOffsets(0), |
| 5242 | LocalNumHeaderFileInfos(0), HeaderFileInfoTableData(0), |
| 5243 | HeaderFileInfoTable(0), |
| 5244 | LocalNumSelectors(0), SelectorOffsets(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5245 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5246 | DeclOffsets(0), LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
| 5247 | LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 5248 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5249 | {} |
| 5250 | |
| 5251 | ASTReader::PerFileData::~PerFileData() { |
| 5252 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5253 | delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5254 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 5255 | } |