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 | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 52 | #include <iostream> |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 53 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 54 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 55 | using namespace clang::serialization; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 56 | |
| 57 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 58 | // PCH validator implementation |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 59 | //===----------------------------------------------------------------------===// |
| 60 | |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 61 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 62 | |
| 63 | bool |
| 64 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 65 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 66 | #define PARSE_LANGOPT_BENIGN(Option) |
| 67 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 68 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 69 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 70 | return true; \ |
| 71 | } |
| 72 | |
| 73 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 74 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 75 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 76 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 77 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 78 | PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 79 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 80 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 81 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 82 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
Peter Collingbourne | 7e7fbd0 | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 83 | PARSE_LANGOPT_IMPORTANT(C1X, diag::warn_pch_c1x); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 84 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 85 | PARSE_LANGOPT_BENIGN(MSCVersion); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 86 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 87 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 88 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 89 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 90 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 91 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 92 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 93 | PARSE_LANGOPT_IMPORTANT(AppleKext, diag::warn_pch_apple_kext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 94 | PARSE_LANGOPT_IMPORTANT(ObjCDefaultSynthProperties, |
| 95 | diag::warn_pch_objc_auto_properties); |
Douglas Gregor | 74da19f | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 96 | PARSE_LANGOPT_BENIGN(ObjCInferRelatedResultType) |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 97 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 98 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 99 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 100 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 101 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 102 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 103 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 104 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 105 | PARSE_LANGOPT_IMPORTANT(ObjCExceptions, diag::warn_pch_objc_exceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 106 | PARSE_LANGOPT_IMPORTANT(CXXExceptions, diag::warn_pch_cxx_exceptions); |
| 107 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 108 | PARSE_LANGOPT_IMPORTANT(MSBitfields, diag::warn_pch_ms_bitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 109 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 110 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 111 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 112 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 113 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 114 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 115 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 116 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 117 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 118 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 119 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 120 | diag::warn_pch_heinous_extensions); |
| 121 | // FIXME: Most of the options below are benign if the macro wasn't |
| 122 | // used. Unfortunately, this means that a PCH compiled without |
| 123 | // optimization can't be used with optimization turned on, even |
| 124 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 125 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 126 | // doesn't matter. We could consider making this some special kind |
| 127 | // of check. |
| 128 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 129 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 130 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 131 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 132 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 133 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
Chandler Carruth | 0d2d1bc | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 134 | PARSE_LANGOPT_IMPORTANT(Deprecated, diag::warn_pch_deprecated); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 135 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 136 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 137 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 138 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 139 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 140 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 141 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 142 | return true; |
| 143 | } |
| 144 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 145 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 146 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 147 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 148 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 149 | PARSE_LANGOPT_IMPORTANT(CUDA, diag::warn_pch_cuda); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 150 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 151 | PARSE_LANGOPT_BENIGN(DefaultFPContract); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 152 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 153 | PARSE_LANGOPT_BENIGN(SpellChecking); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 154 | PARSE_LANGOPT_IMPORTANT(ObjCAutoRefCount, diag::warn_pch_auto_ref_count); |
| 155 | PARSE_LANGOPT_BENIGN(ObjCInferRelatedReturnType); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 156 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 157 | #undef PARSE_LANGOPT_BENIGN |
| 158 | |
| 159 | return false; |
| 160 | } |
| 161 | |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 162 | bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) { |
| 163 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 164 | return false; |
| 165 | |
| 166 | Reader.Diag(diag::warn_pch_target_triple) |
| 167 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 168 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 171 | namespace { |
| 172 | struct EmptyStringRef { |
| 173 | bool operator ()(llvm::StringRef r) const { return r.empty(); } |
| 174 | }; |
| 175 | struct EmptyBlock { |
| 176 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 177 | }; |
| 178 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 179 | |
| 180 | static bool EqualConcatenations(llvm::SmallVector<llvm::StringRef, 2> L, |
| 181 | PCHPredefinesBlocks R) { |
| 182 | // First, sum up the lengths. |
| 183 | unsigned LL = 0, RL = 0; |
| 184 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 185 | LL += L[I].size(); |
| 186 | } |
| 187 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 188 | RL += R[I].Data.size(); |
| 189 | } |
| 190 | if (LL != RL) |
| 191 | return false; |
| 192 | if (LL == 0 && RL == 0) |
| 193 | return true; |
| 194 | |
| 195 | // Kick out empty parts, they confuse the algorithm below. |
| 196 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 197 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 198 | |
| 199 | // Do it the hard way. At this point, both vectors must be non-empty. |
| 200 | llvm::StringRef LR = L[0], RR = R[0].Data; |
| 201 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 202 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 203 | for (;;) { |
| 204 | // Compare the current pieces. |
| 205 | if (LR.size() == RR.size()) { |
| 206 | // If they're the same length, it's pretty easy. |
| 207 | if (LR != RR) |
| 208 | return false; |
| 209 | // Both pieces are done, advance. |
| 210 | ++LI; |
| 211 | ++RI; |
| 212 | // If either string is done, they're both done, since they're the same |
| 213 | // length. |
| 214 | if (LI == LN) { |
| 215 | assert(RI == RN && "Strings not the same length after all?"); |
| 216 | return true; |
| 217 | } |
| 218 | LR = L[LI]; |
| 219 | RR = R[RI].Data; |
| 220 | } else if (LR.size() < RR.size()) { |
| 221 | // Right piece is longer. |
| 222 | if (!RR.startswith(LR)) |
| 223 | return false; |
| 224 | ++LI; |
| 225 | assert(LI != LN && "Strings not the same length after all?"); |
| 226 | RR = RR.substr(LR.size()); |
| 227 | LR = L[LI]; |
| 228 | } else { |
| 229 | // Left piece is longer. |
| 230 | if (!LR.startswith(RR)) |
| 231 | return false; |
| 232 | ++RI; |
| 233 | assert(RI != RN && "Strings not the same length after all?"); |
| 234 | LR = LR.substr(RR.size()); |
| 235 | RR = R[RI].Data; |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | static std::pair<FileID, llvm::StringRef::size_type> |
| 241 | FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) { |
| 242 | std::pair<FileID, llvm::StringRef::size_type> Res; |
| 243 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 244 | Res.second = Buffers[I].Data.find(MacroDef); |
| 245 | if (Res.second != llvm::StringRef::npos) { |
| 246 | Res.first = Buffers[I].BufferID; |
| 247 | break; |
| 248 | } |
| 249 | } |
| 250 | return Res; |
| 251 | } |
| 252 | |
| 253 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 254 | llvm::StringRef OriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 255 | std::string &SuggestedPredefines, |
| 256 | FileManager &FileMgr) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 257 | // We are in the context of an implicit include, so the predefines buffer will |
| 258 | // have a #include entry for the PCH file itself (as normalized by the |
| 259 | // preprocessor initialization). Find it and skip over it in the checking |
| 260 | // below. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 261 | llvm::SmallString<256> PCHInclude; |
| 262 | PCHInclude += "#include \""; |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 263 | PCHInclude += NormalizeDashIncludePath(OriginalFileName, FileMgr); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 264 | PCHInclude += "\"\n"; |
| 265 | std::pair<llvm::StringRef,llvm::StringRef> Split = |
| 266 | llvm::StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 267 | llvm::StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 268 | if (Left == PP.getPredefines()) { |
| 269 | Error("Missing PCH include entry!"); |
| 270 | return true; |
| 271 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 272 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 273 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 274 | // command line, we're done. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 275 | llvm::SmallVector<llvm::StringRef, 2> CommandLine; |
| 276 | CommandLine.push_back(Left); |
| 277 | CommandLine.push_back(Right); |
| 278 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 279 | return false; |
| 280 | |
| 281 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 283 | // The predefines buffers are different. Determine what the differences are, |
| 284 | // and whether they require us to reject the PCH file. |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 285 | llvm::SmallVector<llvm::StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 286 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 287 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 288 | |
| 289 | llvm::SmallVector<llvm::StringRef, 8> CmdLineLines; |
| 290 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 291 | |
| 292 | // Pick out implicit #includes after the PCH and don't consider them for |
| 293 | // validation; we will insert them into SuggestedPredefines so that the |
| 294 | // preprocessor includes them. |
| 295 | std::string IncludesAfterPCH; |
| 296 | llvm::SmallVector<llvm::StringRef, 8> AfterPCHLines; |
| 297 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 298 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 299 | if (AfterPCHLines[i].startswith("#include ")) { |
| 300 | IncludesAfterPCH += AfterPCHLines[i]; |
| 301 | IncludesAfterPCH += '\n'; |
| 302 | } else { |
| 303 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | // Make sure we add the includes last into SuggestedPredefines before we |
| 308 | // exit this function. |
| 309 | struct AddIncludesRAII { |
| 310 | std::string &SuggestedPredefines; |
| 311 | std::string &IncludesAfterPCH; |
| 312 | |
| 313 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 314 | std::string &IncludesAfterPCH) |
| 315 | : SuggestedPredefines(SuggestedPredefines), |
| 316 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 317 | ~AddIncludesRAII() { |
| 318 | SuggestedPredefines += IncludesAfterPCH; |
| 319 | } |
| 320 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 321 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 322 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 323 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 324 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 325 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 326 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 327 | // Determine which predefines that were used to build the PCH file are missing |
| 328 | // from the command line. |
| 329 | std::vector<llvm::StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 330 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 331 | CmdLineLines.begin(), CmdLineLines.end(), |
| 332 | std::back_inserter(MissingPredefines)); |
| 333 | |
| 334 | bool MissingDefines = false; |
| 335 | bool ConflictingDefines = false; |
| 336 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 337 | llvm::StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 338 | if (Missing.startswith("#include ")) { |
| 339 | // An -include was specified when generating the PCH; it is included in |
| 340 | // the PCH, just ignore it. |
| 341 | continue; |
| 342 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 343 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 344 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 345 | return true; |
| 346 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 347 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 348 | // This is a macro definition. Determine the name of the macro we're |
| 349 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 350 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 351 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 352 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 353 | assert(EndOfMacroName != std::string::npos && |
| 354 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 355 | llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 356 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 357 | // Determine whether this macro was given a different definition on the |
| 358 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 359 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 360 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 361 | llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 362 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 363 | MacroDefStart); |
| 364 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 365 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 366 | // Different macro; we're done. |
| 367 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 368 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 369 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 370 | |
| 371 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 372 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 374 | (*ConflictPos)[MacroDefLen] != '(') |
| 375 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 376 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 377 | // We found a conflicting macro definition. |
| 378 | break; |
| 379 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 380 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 381 | if (ConflictPos != CmdLineLines.end()) { |
| 382 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 383 | << MacroName; |
| 384 | |
| 385 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 386 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 387 | FindMacro(Buffers, Missing); |
| 388 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 389 | SourceLocation PCHMissingLoc = |
| 390 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 391 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 392 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 393 | |
| 394 | ConflictingDefines = true; |
| 395 | continue; |
| 396 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 397 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 398 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 399 | // 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] | 400 | if (ConflictingDefines) |
| 401 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 402 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 403 | if (!MissingDefines) { |
| 404 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 405 | MissingDefines = true; |
| 406 | } |
| 407 | |
| 408 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 409 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 410 | FindMacro(Buffers, Missing); |
| 411 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 412 | SourceLocation PCHMissingLoc = |
| 413 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 414 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 415 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 416 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 418 | if (ConflictingDefines) |
| 419 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 421 | // Determine what predefines were introduced based on command-line |
| 422 | // parameters that were not present when building the PCH |
| 423 | // file. Extra #defines are okay, so long as the identifiers being |
| 424 | // defined were not used within the precompiled header. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 425 | std::vector<llvm::StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 426 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 427 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 429 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 430 | llvm::StringRef &Extra = ExtraPredefines[I]; |
| 431 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 432 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 433 | return true; |
| 434 | } |
| 435 | |
| 436 | // This is an extra macro definition. Determine the name of the |
| 437 | // macro we're defining. |
| 438 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 439 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 440 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 441 | assert(EndOfMacroName != std::string::npos && |
| 442 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 443 | llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 444 | |
| 445 | // Check whether this name was used somewhere in the PCH file. If |
| 446 | // so, defining it as a macro could change behavior, so we reject |
| 447 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 448 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 449 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 450 | return true; |
| 451 | } |
| 452 | |
| 453 | // Add this definition to the suggested predefines buffer. |
| 454 | SuggestedPredefines += Extra; |
| 455 | SuggestedPredefines += '\n'; |
| 456 | } |
| 457 | |
| 458 | // If we get here, it's because the predefines buffer had compatible |
| 459 | // contents. Accept the PCH file. |
| 460 | return false; |
| 461 | } |
| 462 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 463 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 464 | unsigned ID) { |
| 465 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 466 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | void PCHValidator::ReadCounter(unsigned Value) { |
| 470 | PP.setCounterValue(Value); |
| 471 | } |
| 472 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 473 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 474 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 475 | //===----------------------------------------------------------------------===// |
| 476 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 477 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 478 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 479 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 482 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 483 | namespace { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 484 | class ASTSelectorLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 485 | ASTReader &Reader; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 486 | |
| 487 | public: |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 488 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 489 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 490 | ObjCMethodList Instance, Factory; |
| 491 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 492 | |
| 493 | typedef Selector external_key_type; |
| 494 | typedef external_key_type internal_key_type; |
| 495 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 496 | explicit ASTSelectorLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 497 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 498 | static bool EqualKey(const internal_key_type& a, |
| 499 | const internal_key_type& b) { |
| 500 | return a == b; |
| 501 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 503 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 504 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 505 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 507 | // This hopefully will just get inlined and removed by the optimizer. |
| 508 | static const internal_key_type& |
| 509 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 510 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 511 | static std::pair<unsigned, unsigned> |
| 512 | ReadKeyDataLength(const unsigned char*& d) { |
| 513 | using namespace clang::io; |
| 514 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 515 | unsigned DataLen = ReadUnalignedLE16(d); |
| 516 | return std::make_pair(KeyLen, DataLen); |
| 517 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 518 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 519 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 520 | using namespace clang::io; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 521 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 522 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 523 | IdentifierInfo *FirstII |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 524 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 525 | if (N == 0) |
| 526 | return SelTable.getNullarySelector(FirstII); |
| 527 | else if (N == 1) |
| 528 | return SelTable.getUnarySelector(FirstII); |
| 529 | |
| 530 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 531 | Args.push_back(FirstII); |
| 532 | for (unsigned I = 1; I != N; ++I) |
| 533 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 534 | |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 535 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 536 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 538 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 539 | using namespace clang::io; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 540 | |
| 541 | data_type Result; |
| 542 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 543 | Result.ID = ReadUnalignedLE32(d); |
| 544 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 545 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 546 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 547 | // Load instance methods |
| 548 | ObjCMethodList *Prev = 0; |
| 549 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 550 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 551 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 552 | if (!Result.Instance.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 553 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 554 | Result.Instance.Method = Method; |
| 555 | Prev = &Result.Instance; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 556 | continue; |
| 557 | } |
| 558 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 559 | ObjCMethodList *Mem = |
| 560 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 561 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 562 | Prev = Prev->Next; |
| 563 | } |
| 564 | |
| 565 | // Load factory methods |
| 566 | Prev = 0; |
| 567 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 568 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 569 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 570 | if (!Result.Factory.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 571 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 572 | Result.Factory.Method = Method; |
| 573 | Prev = &Result.Factory; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 574 | continue; |
| 575 | } |
| 576 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 577 | ObjCMethodList *Mem = |
| 578 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 579 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 580 | Prev = Prev->Next; |
| 581 | } |
| 582 | |
| 583 | return Result; |
| 584 | } |
| 585 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 586 | |
| 587 | } // end anonymous namespace |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 588 | |
| 589 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 590 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 591 | ASTSelectorLookupTable; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 592 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 593 | namespace clang { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 594 | class ASTIdentifierLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 595 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 596 | ASTReader::PerFileData &F; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 597 | |
| 598 | // If we know the IdentifierInfo in advance, it is here and we will |
| 599 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 600 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 601 | IdentifierInfo *KnownII; |
| 602 | |
| 603 | public: |
| 604 | typedef IdentifierInfo * data_type; |
| 605 | |
| 606 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 607 | |
| 608 | typedef external_key_type internal_key_type; |
| 609 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 610 | ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 611 | IdentifierInfo *II = 0) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 612 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 613 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 614 | static bool EqualKey(const internal_key_type& a, |
| 615 | const internal_key_type& b) { |
| 616 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 617 | : false; |
| 618 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 619 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 620 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 621 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 622 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 623 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 624 | // This hopefully will just get inlined and removed by the optimizer. |
| 625 | static const internal_key_type& |
| 626 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 627 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 628 | // This hopefully will just get inlined and removed by the optimizer. |
| 629 | static const external_key_type& |
| 630 | GetExternalKey(const internal_key_type& x) { return x; } |
| 631 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 632 | static std::pair<unsigned, unsigned> |
| 633 | ReadKeyDataLength(const unsigned char*& d) { |
| 634 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 635 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 636 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 637 | return std::make_pair(KeyLen, DataLen); |
| 638 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 639 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 640 | static std::pair<const char*, unsigned> |
| 641 | ReadKey(const unsigned char* d, unsigned n) { |
| 642 | assert(n >= 2 && d[n-1] == '\0'); |
| 643 | return std::make_pair((const char*) d, n-1); |
| 644 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 645 | |
| 646 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 647 | const unsigned char* d, |
| 648 | unsigned DataLen) { |
| 649 | using namespace clang::io; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 650 | IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 651 | bool IsInteresting = ID & 0x01; |
| 652 | |
| 653 | // Wipe out the "is interesting" bit. |
| 654 | ID = ID >> 1; |
| 655 | |
| 656 | if (!IsInteresting) { |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 657 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 658 | // and associate it with the persistent ID. |
| 659 | IdentifierInfo *II = KnownII; |
| 660 | if (!II) |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 661 | II = &Reader.getIdentifierTable().getOwn(llvm::StringRef(k.first, |
| 662 | k.second)); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 663 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 664 | II->setIsFromAST(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 665 | return II; |
| 666 | } |
| 667 | |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 668 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 669 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 670 | Bits >>= 1; |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 671 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 672 | Bits >>= 1; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 673 | bool Poisoned = Bits & 0x01; |
| 674 | Bits >>= 1; |
| 675 | bool ExtensionToken = Bits & 0x01; |
| 676 | Bits >>= 1; |
| 677 | bool hasMacroDefinition = Bits & 0x01; |
| 678 | Bits >>= 1; |
| 679 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 680 | Bits >>= 10; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 681 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 682 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 683 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 684 | |
| 685 | // Build the IdentifierInfo itself and link the identifier ID with |
| 686 | // the new IdentifierInfo. |
| 687 | IdentifierInfo *II = KnownII; |
| 688 | if (!II) |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 689 | II = &Reader.getIdentifierTable().getOwn(llvm::StringRef(k.first, |
| 690 | k.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 691 | Reader.SetIdentifierInfo(ID, II); |
| 692 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 693 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 694 | // Token IDs are read-only. |
| 695 | if (HasRevertedTokenIDToIdentifier) |
| 696 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 697 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 698 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 699 | "Incorrect extension token flag"); |
| 700 | (void)ExtensionToken; |
| 701 | II->setIsPoisoned(Poisoned); |
| 702 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 703 | "Incorrect C++ operator keyword flag"); |
| 704 | (void)CPlusPlusOperatorKeyword; |
| 705 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 706 | // If this identifier is a macro, deserialize the macro |
| 707 | // definition. |
| 708 | if (hasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 709 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 710 | Reader.SetIdentifierIsMacro(II, F, Offset); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 711 | DataLen -= 4; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 712 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 713 | |
| 714 | // Read all of the declarations visible at global scope with this |
| 715 | // name. |
Chris Lattner | 6bf690f | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 716 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 717 | if (DataLen > 0) { |
| 718 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 719 | for (; DataLen > 0; DataLen -= 4) |
| 720 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 721 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 722 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 723 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 724 | II->setIsFromAST(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 725 | return II; |
| 726 | } |
| 727 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 728 | |
| 729 | } // end anonymous namespace |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 730 | |
| 731 | /// \brief The on-disk hash table used to contain information about |
| 732 | /// all of the identifiers in the program. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 733 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 734 | ASTIdentifierLookupTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 735 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 736 | namespace { |
| 737 | class ASTDeclContextNameLookupTrait { |
| 738 | ASTReader &Reader; |
| 739 | |
| 740 | public: |
| 741 | /// \brief Pair of begin/end iterators for DeclIDs. |
| 742 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 743 | |
| 744 | /// \brief Special internal key for declaration names. |
| 745 | /// The hash table creates keys for comparison; we do not create |
| 746 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 747 | struct DeclNameKey { |
| 748 | DeclarationName::NameKind Kind; |
| 749 | uint64_t Data; |
| 750 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 751 | }; |
| 752 | |
| 753 | typedef DeclarationName external_key_type; |
| 754 | typedef DeclNameKey internal_key_type; |
| 755 | |
| 756 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
| 757 | |
| 758 | static bool EqualKey(const internal_key_type& a, |
| 759 | const internal_key_type& b) { |
| 760 | return a.Kind == b.Kind && a.Data == b.Data; |
| 761 | } |
| 762 | |
| 763 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 764 | llvm::FoldingSetNodeID ID; |
| 765 | ID.AddInteger(Key.Kind); |
| 766 | |
| 767 | switch (Key.Kind) { |
| 768 | case DeclarationName::Identifier: |
| 769 | case DeclarationName::CXXLiteralOperatorName: |
| 770 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 771 | break; |
| 772 | case DeclarationName::ObjCZeroArgSelector: |
| 773 | case DeclarationName::ObjCOneArgSelector: |
| 774 | case DeclarationName::ObjCMultiArgSelector: |
| 775 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 776 | break; |
| 777 | case DeclarationName::CXXConstructorName: |
| 778 | case DeclarationName::CXXDestructorName: |
| 779 | case DeclarationName::CXXConversionFunctionName: |
| 780 | ID.AddInteger((TypeID)Key.Data); |
| 781 | break; |
| 782 | case DeclarationName::CXXOperatorName: |
| 783 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 784 | break; |
| 785 | case DeclarationName::CXXUsingDirective: |
| 786 | break; |
| 787 | } |
| 788 | |
| 789 | return ID.ComputeHash(); |
| 790 | } |
| 791 | |
| 792 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 793 | DeclNameKey Key; |
| 794 | Key.Kind = Name.getNameKind(); |
| 795 | switch (Name.getNameKind()) { |
| 796 | case DeclarationName::Identifier: |
| 797 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 798 | break; |
| 799 | case DeclarationName::ObjCZeroArgSelector: |
| 800 | case DeclarationName::ObjCOneArgSelector: |
| 801 | case DeclarationName::ObjCMultiArgSelector: |
| 802 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 803 | break; |
| 804 | case DeclarationName::CXXConstructorName: |
| 805 | case DeclarationName::CXXDestructorName: |
| 806 | case DeclarationName::CXXConversionFunctionName: |
| 807 | Key.Data = Reader.GetTypeID(Name.getCXXNameType()); |
| 808 | break; |
| 809 | case DeclarationName::CXXOperatorName: |
| 810 | Key.Data = Name.getCXXOverloadedOperator(); |
| 811 | break; |
| 812 | case DeclarationName::CXXLiteralOperatorName: |
| 813 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 814 | break; |
| 815 | case DeclarationName::CXXUsingDirective: |
| 816 | break; |
| 817 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 818 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 819 | return Key; |
| 820 | } |
| 821 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 822 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 823 | ASTContext *Context = Reader.getContext(); |
| 824 | switch (Key.Kind) { |
| 825 | case DeclarationName::Identifier: |
| 826 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 827 | |
| 828 | case DeclarationName::ObjCZeroArgSelector: |
| 829 | case DeclarationName::ObjCOneArgSelector: |
| 830 | case DeclarationName::ObjCMultiArgSelector: |
| 831 | return DeclarationName(Selector(Key.Data)); |
| 832 | |
| 833 | case DeclarationName::CXXConstructorName: |
| 834 | return Context->DeclarationNames.getCXXConstructorName( |
| 835 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 836 | |
| 837 | case DeclarationName::CXXDestructorName: |
| 838 | return Context->DeclarationNames.getCXXDestructorName( |
| 839 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 840 | |
| 841 | case DeclarationName::CXXConversionFunctionName: |
| 842 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 843 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 844 | |
| 845 | case DeclarationName::CXXOperatorName: |
| 846 | return Context->DeclarationNames.getCXXOperatorName( |
| 847 | (OverloadedOperatorKind)Key.Data); |
| 848 | |
| 849 | case DeclarationName::CXXLiteralOperatorName: |
| 850 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 851 | (IdentifierInfo*)Key.Data); |
| 852 | |
| 853 | case DeclarationName::CXXUsingDirective: |
| 854 | return DeclarationName::getUsingDirectiveName(); |
| 855 | } |
| 856 | |
| 857 | llvm_unreachable("Invalid Name Kind ?"); |
| 858 | } |
| 859 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 860 | static std::pair<unsigned, unsigned> |
| 861 | ReadKeyDataLength(const unsigned char*& d) { |
| 862 | using namespace clang::io; |
| 863 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 864 | unsigned DataLen = ReadUnalignedLE16(d); |
| 865 | return std::make_pair(KeyLen, DataLen); |
| 866 | } |
| 867 | |
| 868 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 869 | using namespace clang::io; |
| 870 | |
| 871 | DeclNameKey Key; |
| 872 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 873 | switch (Key.Kind) { |
| 874 | case DeclarationName::Identifier: |
| 875 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 876 | break; |
| 877 | case DeclarationName::ObjCZeroArgSelector: |
| 878 | case DeclarationName::ObjCOneArgSelector: |
| 879 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 880 | Key.Data = |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 881 | (uint64_t)Reader.DecodeSelector(ReadUnalignedLE32(d)).getAsOpaquePtr(); |
| 882 | break; |
| 883 | case DeclarationName::CXXConstructorName: |
| 884 | case DeclarationName::CXXDestructorName: |
| 885 | case DeclarationName::CXXConversionFunctionName: |
| 886 | Key.Data = ReadUnalignedLE32(d); // TypeID |
| 887 | break; |
| 888 | case DeclarationName::CXXOperatorName: |
| 889 | Key.Data = *d++; // OverloadedOperatorKind |
| 890 | break; |
| 891 | case DeclarationName::CXXLiteralOperatorName: |
| 892 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 893 | break; |
| 894 | case DeclarationName::CXXUsingDirective: |
| 895 | break; |
| 896 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 897 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 898 | return Key; |
| 899 | } |
| 900 | |
| 901 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 902 | unsigned DataLen) { |
| 903 | using namespace clang::io; |
| 904 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 905 | DeclID *Start = (DeclID *)d; |
| 906 | return std::make_pair(Start, Start + NumDecls); |
| 907 | } |
| 908 | }; |
| 909 | |
| 910 | } // end anonymous namespace |
| 911 | |
| 912 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 913 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 914 | ASTDeclContextNameLookupTable; |
| 915 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 916 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 917 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 918 | DeclContextInfo &Info) { |
| 919 | SavedStreamPosition SavedPosition(Cursor); |
| 920 | // First the lexical decls. |
| 921 | if (Offsets.first != 0) { |
| 922 | Cursor.JumpToBit(Offsets.first); |
| 923 | |
| 924 | RecordData Record; |
| 925 | const char *Blob; |
| 926 | unsigned BlobLen; |
| 927 | unsigned Code = Cursor.ReadCode(); |
| 928 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 929 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 930 | Error("Expected lexical block"); |
| 931 | return true; |
| 932 | } |
| 933 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 934 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 935 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 936 | } else { |
| 937 | Info.LexicalDecls = 0; |
| 938 | Info.NumLexicalDecls = 0; |
| 939 | } |
| 940 | |
| 941 | // Now the lookup table. |
| 942 | if (Offsets.second != 0) { |
| 943 | Cursor.JumpToBit(Offsets.second); |
| 944 | |
| 945 | RecordData Record; |
| 946 | const char *Blob; |
| 947 | unsigned BlobLen; |
| 948 | unsigned Code = Cursor.ReadCode(); |
| 949 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 950 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 951 | Error("Expected visible lookup table block"); |
| 952 | return true; |
| 953 | } |
| 954 | Info.NameLookupTableData |
| 955 | = ASTDeclContextNameLookupTable::Create( |
| 956 | (const unsigned char *)Blob + Record[0], |
| 957 | (const unsigned char *)Blob, |
| 958 | ASTDeclContextNameLookupTrait(*this)); |
Sebastian Redl | 0ea8f7f | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 959 | } else { |
| 960 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | return false; |
| 964 | } |
| 965 | |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 966 | void ASTReader::Error(llvm::StringRef Msg) { |
| 967 | Error(diag::err_fe_pch_malformed, Msg); |
| 968 | } |
| 969 | |
| 970 | void ASTReader::Error(unsigned DiagID, |
| 971 | llvm::StringRef Arg1, llvm::StringRef Arg2) { |
| 972 | if (Diags.isDiagnosticInFlight()) |
| 973 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 974 | else |
| 975 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 976 | } |
| 977 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 978 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 979 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 980 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 981 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 982 | ActualOriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 983 | SuggestedPredefines, |
| 984 | FileMgr); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 985 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 986 | } |
| 987 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 988 | //===----------------------------------------------------------------------===// |
| 989 | // Source Manager Deserialization |
| 990 | //===----------------------------------------------------------------------===// |
| 991 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 992 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 993 | /// \returns true if there was an error. |
| 994 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 995 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 996 | unsigned Idx = 0; |
| 997 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 998 | |
| 999 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 1000 | std::map<int, int> FileIDs; |
| 1001 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1002 | // Extract the file name |
| 1003 | unsigned FilenameLen = Record[Idx++]; |
| 1004 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 1005 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1006 | MaybeAddSystemRootToFilename(Filename); |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 1007 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | // Parse the line entries |
| 1011 | std::vector<LineEntry> Entries; |
| 1012 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1013 | int FID = Record[Idx++]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1014 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 1015 | // Remap FileID from 1-based old view. |
| 1016 | FID += F.SLocEntryBaseID - 1; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1017 | |
| 1018 | // Extract the line entries |
| 1019 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1020 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1021 | Entries.clear(); |
| 1022 | Entries.reserve(NumEntries); |
| 1023 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1024 | unsigned FileOffset = Record[Idx++]; |
| 1025 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1026 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1027 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1028 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1029 | unsigned IncludeOffset = Record[Idx++]; |
| 1030 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1031 | FileKind, IncludeOffset)); |
| 1032 | } |
| 1033 | LineTable.AddEntry(FID, Entries); |
| 1034 | } |
| 1035 | |
| 1036 | return false; |
| 1037 | } |
| 1038 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1039 | namespace { |
| 1040 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1041 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1042 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1043 | const ino_t ino; |
| 1044 | const dev_t dev; |
| 1045 | const mode_t mode; |
| 1046 | const time_t mtime; |
| 1047 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1049 | 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] | 1050 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1051 | }; |
| 1052 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1053 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1054 | public: |
| 1055 | typedef const char *external_key_type; |
| 1056 | typedef const char *internal_key_type; |
| 1057 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1058 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1059 | |
| 1060 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1061 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1065 | |
| 1066 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1067 | return strcmp(a, b) == 0; |
| 1068 | } |
| 1069 | |
| 1070 | static std::pair<unsigned, unsigned> |
| 1071 | ReadKeyDataLength(const unsigned char*& d) { |
| 1072 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1073 | unsigned DataLen = (unsigned) *d++; |
| 1074 | return std::make_pair(KeyLen + 1, DataLen); |
| 1075 | } |
| 1076 | |
| 1077 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1078 | return (const char *)d; |
| 1079 | } |
| 1080 | |
| 1081 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1082 | unsigned /*DataLen*/) { |
| 1083 | using namespace clang::io; |
| 1084 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1085 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1086 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1087 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1088 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1089 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1090 | return data_type(ino, dev, mode, mtime, size); |
| 1091 | } |
| 1092 | }; |
| 1093 | |
| 1094 | /// \brief stat() cache for precompiled headers. |
| 1095 | /// |
| 1096 | /// This cache is very similar to the stat cache used by pretokenized |
| 1097 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1098 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1099 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1100 | CacheTy *Cache; |
| 1101 | |
| 1102 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1103 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1104 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1105 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1106 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1107 | Cache = CacheTy::Create(Buckets, Base); |
| 1108 | } |
| 1109 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1110 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1111 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1112 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1113 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1114 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1115 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1116 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1117 | // 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] | 1118 | if (I == Cache->end()) { |
| 1119 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1120 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1121 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1122 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1123 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1124 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1125 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1126 | StatBuf.st_ino = Data.ino; |
| 1127 | StatBuf.st_dev = Data.dev; |
| 1128 | StatBuf.st_mtime = Data.mtime; |
| 1129 | StatBuf.st_mode = Data.mode; |
| 1130 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1131 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1132 | } |
| 1133 | }; |
| 1134 | } // end anonymous namespace |
| 1135 | |
| 1136 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1137 | /// \brief Read a source manager block |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1138 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1139 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1140 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1141 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1142 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1143 | // Set the source-location entry cursor to the current position in |
| 1144 | // the stream. This cursor will be used to read the contents of the |
| 1145 | // source manager block initially, and then lazily read |
| 1146 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1147 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1148 | |
| 1149 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1150 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1151 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1152 | return Failure; |
| 1153 | } |
| 1154 | |
| 1155 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1156 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1157 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1158 | return Failure; |
| 1159 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1160 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1161 | RecordData Record; |
| 1162 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1163 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1164 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1165 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1166 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1167 | return Failure; |
| 1168 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1169 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1170 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1171 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1172 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1173 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1174 | SLocEntryCursor.ReadSubBlockID(); |
| 1175 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1176 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1177 | return Failure; |
| 1178 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1179 | continue; |
| 1180 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1181 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1182 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1183 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1184 | continue; |
| 1185 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1186 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1187 | // Read a record. |
| 1188 | const char *BlobStart; |
| 1189 | unsigned BlobLen; |
| 1190 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1191 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1192 | default: // Default behavior: ignore. |
| 1193 | break; |
| 1194 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1195 | case SM_SLOC_FILE_ENTRY: |
| 1196 | case SM_SLOC_BUFFER_ENTRY: |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1197 | case SM_SLOC_EXPANSION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1198 | // Once we hit one of the source location entries, we're done. |
| 1199 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1200 | } |
| 1201 | } |
| 1202 | } |
| 1203 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1204 | /// \brief If a header file is not found at the path that we expect it to be |
| 1205 | /// and the PCH file was moved from its original location, try to resolve the |
| 1206 | /// file by assuming that header+PCH were moved together and the header is in |
| 1207 | /// the same place relative to the PCH. |
| 1208 | static std::string |
| 1209 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1210 | const std::string &OriginalDir, |
| 1211 | const std::string &CurrDir) { |
| 1212 | assert(OriginalDir != CurrDir && |
| 1213 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1214 | using namespace llvm::sys; |
| 1215 | llvm::SmallString<128> filePath(Filename); |
| 1216 | fs::make_absolute(filePath); |
| 1217 | assert(path::is_absolute(OriginalDir)); |
| 1218 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1219 | |
| 1220 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1221 | fileDirE = path::end(path::parent_path(filePath)); |
| 1222 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1223 | origDirE = path::end(OriginalDir); |
| 1224 | // Skip the common path components from filePath and OriginalDir. |
| 1225 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1226 | *fileDirI == *origDirI) { |
| 1227 | ++fileDirI; |
| 1228 | ++origDirI; |
| 1229 | } |
| 1230 | for (; origDirI != origDirE; ++origDirI) |
| 1231 | path::append(currPCHPath, ".."); |
| 1232 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1233 | path::append(currPCHPath, path::filename(Filename)); |
| 1234 | return currPCHPath.str(); |
| 1235 | } |
| 1236 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1237 | /// \brief Read in the source location entry with the given ID. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1238 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(int ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1239 | if (ID == 0) |
| 1240 | return Success; |
| 1241 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1242 | if (unsigned(-ID) - 2 >= TotalNumSLocEntries || ID > 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1243 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1244 | return Failure; |
| 1245 | } |
| 1246 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1247 | PerFileData *F = GlobalSLocEntryMap.find(-ID)->second; |
| 1248 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1249 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1250 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1251 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1252 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1253 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1254 | if (Code == llvm::bitc::END_BLOCK || |
| 1255 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1256 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1257 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1258 | return Failure; |
| 1259 | } |
| 1260 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1261 | RecordData Record; |
| 1262 | const char *BlobStart; |
| 1263 | unsigned BlobLen; |
| 1264 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1265 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1266 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1267 | return Failure; |
| 1268 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1269 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1270 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1271 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1272 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1273 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1274 | OriginalDir != CurrentDir) { |
| 1275 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1276 | OriginalDir, |
| 1277 | CurrentDir); |
| 1278 | if (!resolved.empty()) |
| 1279 | File = FileMgr.getFile(resolved); |
| 1280 | } |
Axel Naumann | 0433116 | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1281 | if (File == 0) |
| 1282 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1283 | (time_t)Record[5]); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1284 | if (File == 0) { |
| 1285 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1286 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1287 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1288 | Error(ErrorStr.c_str()); |
| 1289 | return Failure; |
| 1290 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1291 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1292 | if (Record.size() < 6) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1293 | Error("source location entry is incorrect"); |
| 1294 | return Failure; |
| 1295 | } |
| 1296 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1297 | if (!DisableValidation && |
| 1298 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1299 | #if !defined(LLVM_ON_WIN32) |
| 1300 | // In our regression testing, the Windows file system seems to |
| 1301 | // have inconsistent modification times that sometimes |
| 1302 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1303 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1304 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1305 | )) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1306 | Error(diag::err_fe_pch_file_modified, Filename); |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1307 | return Failure; |
| 1308 | } |
| 1309 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1310 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
| 1311 | if (IncludeLoc.isInvalid() && F->Type != MainFile) { |
| 1312 | // This is the module's main file. |
| 1313 | IncludeLoc = getImportLocation(F); |
| 1314 | } |
| 1315 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1316 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1317 | ID, BaseOffset + Record[0]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1318 | if (Record[3]) |
| 1319 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1320 | .setHasLineDirectives(); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1321 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1322 | break; |
| 1323 | } |
| 1324 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1325 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1326 | const char *Name = BlobStart; |
| 1327 | unsigned Offset = Record[0]; |
| 1328 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1329 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1331 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1332 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1333 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1334 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1335 | return Failure; |
| 1336 | } |
| 1337 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1338 | llvm::MemoryBuffer *Buffer |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1339 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1340 | Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1341 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, |
| 1342 | BaseOffset + Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1343 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1344 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1345 | PCHPredefinesBlock Block = { |
| 1346 | BufferID, |
| 1347 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1348 | }; |
| 1349 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1350 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1351 | |
| 1352 | break; |
| 1353 | } |
| 1354 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1355 | case SM_SLOC_EXPANSION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1356 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1357 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1358 | ReadSourceLocation(*F, Record[2]), |
| 1359 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1360 | Record[4], |
| 1361 | ID, |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1362 | BaseOffset + Record[0]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1363 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1364 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | return Success; |
| 1368 | } |
| 1369 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1370 | /// \brief Find the location where the module F is imported. |
| 1371 | SourceLocation ASTReader::getImportLocation(PerFileData *F) { |
| 1372 | if (F->ImportLoc.isValid()) |
| 1373 | return F->ImportLoc; |
| 1374 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1375 | // location of its includer. |
| 1376 | if (F->Loaders.empty() || !F->Loaders[0]) { |
| 1377 | // Main file is the importer. We assume that it is the first entry in the |
| 1378 | // entry table. We can't ask the manager, because at the time of PCH loading |
| 1379 | // the main file entry doesn't exist yet. |
| 1380 | // The very first entry is the invalid instantiation loc, which takes up |
| 1381 | // offsets 0 and 1. |
| 1382 | return SourceLocation::getFromRawEncoding(2U); |
| 1383 | } |
| 1384 | return F->Loaders[0]->FirstLoc; |
| 1385 | } |
| 1386 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1387 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1388 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1389 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1390 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1391 | unsigned BlockID) { |
| 1392 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1393 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1394 | return Failure; |
| 1395 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1396 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1397 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1398 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1399 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1400 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1401 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1402 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1403 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1404 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1405 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1406 | Cursor.ReadAbbrevRecord(); |
| 1407 | } |
| 1408 | } |
| 1409 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1410 | PreprocessedEntity *ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1411 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1412 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1413 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1414 | // Keep track of where we are in the stream, then jump back there |
| 1415 | // after reading this macro. |
| 1416 | SavedStreamPosition SavedPosition(Stream); |
| 1417 | |
| 1418 | Stream.JumpToBit(Offset); |
| 1419 | RecordData Record; |
| 1420 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1421 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1422 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1423 | while (true) { |
| 1424 | unsigned Code = Stream.ReadCode(); |
| 1425 | switch (Code) { |
| 1426 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1427 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1428 | |
| 1429 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1430 | // No known subblocks, always skip them. |
| 1431 | Stream.ReadSubBlockID(); |
| 1432 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1433 | Error("malformed block record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1434 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1435 | } |
| 1436 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1437 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1438 | case llvm::bitc::DEFINE_ABBREV: |
| 1439 | Stream.ReadAbbrevRecord(); |
| 1440 | continue; |
| 1441 | default: break; |
| 1442 | } |
| 1443 | |
| 1444 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1445 | const char *BlobStart = 0; |
| 1446 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1447 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1448 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1449 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1450 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1451 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1452 | case PP_MACRO_OBJECT_LIKE: |
| 1453 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1454 | // If we already have a macro, that means that we've hit the end |
| 1455 | // of the definition of the macro we were looking for. We're |
| 1456 | // done. |
| 1457 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1458 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1459 | |
| 1460 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1461 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1462 | Error("macro must have a name in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1463 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1464 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1465 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1466 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1467 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1468 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1469 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1470 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1471 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1472 | unsigned NextIndex = 3; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1473 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1474 | // Decode function-like macro info. |
| 1475 | bool isC99VarArgs = Record[3]; |
| 1476 | bool isGNUVarArgs = Record[4]; |
| 1477 | MacroArgs.clear(); |
| 1478 | unsigned NumArgs = Record[5]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1479 | NextIndex = 6 + NumArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1480 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1481 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1482 | |
| 1483 | // Install function-like macro info. |
| 1484 | MI->setIsFunctionLike(); |
| 1485 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1486 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1487 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1488 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1492 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1493 | |
| 1494 | // Remember that we saw this macro last so that we add the tokens that |
| 1495 | // form its body to it. |
| 1496 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1497 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1498 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1499 | // We have a macro definition. Load it now. |
| 1500 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1501 | getMacroDefinition(Record[NextIndex])); |
| 1502 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1503 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1504 | ++NumMacrosRead; |
| 1505 | break; |
| 1506 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1507 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1508 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1509 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1510 | // erroneous, just pretend we didn't see this. |
| 1511 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1512 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1513 | Token Tok; |
| 1514 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1515 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1516 | Tok.setLength(Record[1]); |
| 1517 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1518 | Tok.setIdentifierInfo(II); |
| 1519 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1520 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1521 | Macro->AddTokenToBody(Tok); |
| 1522 | break; |
| 1523 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1524 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1525 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1526 | |
| 1527 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1530 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(PerFileData &F) { |
| 1531 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1532 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1533 | switch (Code) { |
| 1534 | case llvm::bitc::END_BLOCK: |
| 1535 | return 0; |
| 1536 | |
| 1537 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1538 | Error("unexpected subblock record in preprocessor detail block"); |
| 1539 | return 0; |
| 1540 | |
| 1541 | case llvm::bitc::DEFINE_ABBREV: |
| 1542 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1543 | return 0; |
| 1544 | |
| 1545 | default: |
| 1546 | break; |
| 1547 | } |
| 1548 | |
| 1549 | if (!PP->getPreprocessingRecord()) { |
| 1550 | Error("no preprocessing record"); |
| 1551 | return 0; |
| 1552 | } |
| 1553 | |
| 1554 | // Read the record. |
| 1555 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1556 | const char *BlobStart = 0; |
| 1557 | unsigned BlobLen = 0; |
| 1558 | RecordData Record; |
| 1559 | PreprocessorDetailRecordTypes RecType = |
| 1560 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1561 | Code, Record, BlobStart, BlobLen); |
| 1562 | switch (RecType) { |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1563 | case PPD_MACRO_EXPANSION: { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1564 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1565 | return PE; |
| 1566 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1567 | MacroExpansion *ME = |
| 1568 | new (PPRec) MacroExpansion(DecodeIdentifierInfo(Record[3]), |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1569 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1570 | ReadSourceLocation(F, Record[2])), |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1571 | getMacroDefinition(Record[4])); |
| 1572 | PPRec.SetPreallocatedEntity(Record[0], ME); |
| 1573 | return ME; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | case PPD_MACRO_DEFINITION: { |
| 1577 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1578 | return PE; |
| 1579 | |
| 1580 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
| 1581 | Error("out-of-bounds macro definition record"); |
| 1582 | return 0; |
| 1583 | } |
| 1584 | |
| 1585 | // Decode the identifier info and then check again; if the macro is |
| 1586 | // still defined and associated with the identifier, |
| 1587 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1588 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1589 | MacroDefinition *MD |
| 1590 | = new (PPRec) MacroDefinition(II, |
| 1591 | ReadSourceLocation(F, Record[5]), |
| 1592 | SourceRange( |
| 1593 | ReadSourceLocation(F, Record[2]), |
| 1594 | ReadSourceLocation(F, Record[3]))); |
| 1595 | |
| 1596 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1597 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
| 1598 | |
| 1599 | if (DeserializationListener) |
| 1600 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1601 | } |
| 1602 | |
| 1603 | return MacroDefinitionsLoaded[Record[1] - 1]; |
| 1604 | } |
| 1605 | |
| 1606 | case PPD_INCLUSION_DIRECTIVE: { |
| 1607 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1608 | return PE; |
| 1609 | |
| 1610 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1611 | const FileEntry *File |
| 1612 | = PP->getFileManager().getFile(llvm::StringRef(FullFileNameStart, |
| 1613 | BlobLen - Record[3])); |
| 1614 | |
| 1615 | // FIXME: Stable encoding |
| 1616 | InclusionDirective::InclusionKind Kind |
| 1617 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1618 | InclusionDirective *ID |
| 1619 | = new (PPRec) InclusionDirective(PPRec, Kind, |
| 1620 | llvm::StringRef(BlobStart, Record[3]), |
| 1621 | Record[4], |
| 1622 | File, |
| 1623 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1624 | ReadSourceLocation(F, Record[2]))); |
| 1625 | PPRec.SetPreallocatedEntity(Record[0], ID); |
| 1626 | return ID; |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | Error("invalid offset in preprocessor detail block"); |
| 1631 | return 0; |
| 1632 | } |
| 1633 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1634 | namespace { |
| 1635 | /// \brief Trait class used to search the on-disk hash table containing all of |
| 1636 | /// the header search information. |
| 1637 | /// |
| 1638 | /// The on-disk hash table contains a mapping from each header path to |
| 1639 | /// information about that header (how many times it has been included, its |
| 1640 | /// controlling macro, etc.). Note that we actually hash based on the |
| 1641 | /// filename, and support "deep" comparisons of file names based on current |
| 1642 | /// inode numbers, so that the search can cope with non-normalized path names |
| 1643 | /// and symlinks. |
| 1644 | class HeaderFileInfoTrait { |
| 1645 | const char *SearchPath; |
| 1646 | struct stat SearchPathStatBuf; |
| 1647 | llvm::Optional<int> SearchPathStatResult; |
| 1648 | |
| 1649 | int StatSimpleCache(const char *Path, struct stat *StatBuf) { |
| 1650 | if (Path == SearchPath) { |
| 1651 | if (!SearchPathStatResult) |
| 1652 | SearchPathStatResult = stat(Path, &SearchPathStatBuf); |
| 1653 | |
| 1654 | *StatBuf = SearchPathStatBuf; |
| 1655 | return *SearchPathStatResult; |
| 1656 | } |
| 1657 | |
| 1658 | return stat(Path, StatBuf); |
| 1659 | } |
| 1660 | |
| 1661 | public: |
| 1662 | typedef const char *external_key_type; |
| 1663 | typedef const char *internal_key_type; |
| 1664 | |
| 1665 | typedef HeaderFileInfo data_type; |
| 1666 | |
| 1667 | HeaderFileInfoTrait(const char *SearchPath = 0) : SearchPath(SearchPath) { } |
| 1668 | |
| 1669 | static unsigned ComputeHash(const char *path) { |
| 1670 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1671 | } |
| 1672 | |
| 1673 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1674 | |
| 1675 | bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1676 | if (strcmp(a, b) == 0) |
| 1677 | return true; |
| 1678 | |
| 1679 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1680 | return false; |
| 1681 | |
| 1682 | // The file names match, but the path names don't. stat() the files to |
| 1683 | // see if they are the same. |
| 1684 | struct stat StatBufA, StatBufB; |
| 1685 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1686 | return false; |
| 1687 | |
| 1688 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1689 | } |
| 1690 | |
| 1691 | static std::pair<unsigned, unsigned> |
| 1692 | ReadKeyDataLength(const unsigned char*& d) { |
| 1693 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1694 | unsigned DataLen = (unsigned) *d++; |
| 1695 | return std::make_pair(KeyLen + 1, DataLen); |
| 1696 | } |
| 1697 | |
| 1698 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1699 | return (const char *)d; |
| 1700 | } |
| 1701 | |
| 1702 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1703 | unsigned DataLen) { |
| 1704 | const unsigned char *End = d + DataLen; |
| 1705 | using namespace clang::io; |
| 1706 | HeaderFileInfo HFI; |
| 1707 | unsigned Flags = *d++; |
Douglas Gregor | dd3e554 | 2011-05-04 00:14:37 +0000 | [diff] [blame] | 1708 | HFI.isImport = (Flags >> 4) & 0x01; |
| 1709 | HFI.isPragmaOnce = (Flags >> 3) & 0x01; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1710 | HFI.DirInfo = (Flags >> 1) & 0x03; |
| 1711 | HFI.Resolved = Flags & 0x01; |
| 1712 | HFI.NumIncludes = ReadUnalignedLE16(d); |
| 1713 | HFI.ControllingMacroID = ReadUnalignedLE32(d); |
| 1714 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1715 | (void)End; |
| 1716 | |
| 1717 | // This HeaderFileInfo was externally loaded. |
| 1718 | HFI.External = true; |
| 1719 | return HFI; |
| 1720 | } |
| 1721 | }; |
| 1722 | } |
| 1723 | |
| 1724 | /// \brief The on-disk hash table used for the global method pool. |
| 1725 | typedef OnDiskChainedHashTable<HeaderFileInfoTrait> |
| 1726 | HeaderFileInfoLookupTable; |
| 1727 | |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1728 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F, |
| 1729 | uint64_t Offset) { |
| 1730 | // Note that this identifier has a macro definition. |
| 1731 | II->setHasMacroDefinition(true); |
| 1732 | |
| 1733 | // Adjust the offset based on our position in the chain. |
| 1734 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1735 | if (Chain[I] == &F) |
| 1736 | break; |
| 1737 | |
| 1738 | Offset += Chain[I]->SizeInBits; |
| 1739 | } |
| 1740 | |
| 1741 | UnreadMacroRecordOffsets[II] = Offset; |
| 1742 | } |
| 1743 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1744 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1745 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1746 | PerFileData &F = *Chain[N - I - 1]; |
| 1747 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1748 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1749 | // If there was no preprocessor block, skip this file. |
| 1750 | if (!MacroCursor.getBitStreamReader()) |
| 1751 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1752 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1753 | llvm::BitstreamCursor Cursor = MacroCursor; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1754 | Cursor.JumpToBit(F.MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1755 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1756 | RecordData Record; |
| 1757 | while (true) { |
| 1758 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1759 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1760 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1761 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1762 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1763 | // No known subblocks, always skip them. |
| 1764 | Cursor.ReadSubBlockID(); |
| 1765 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1766 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1767 | return; |
| 1768 | } |
| 1769 | continue; |
| 1770 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1771 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1772 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1773 | Cursor.ReadAbbrevRecord(); |
| 1774 | continue; |
| 1775 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1776 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1777 | // Read a record. |
| 1778 | const char *BlobStart; |
| 1779 | unsigned BlobLen; |
| 1780 | Record.clear(); |
| 1781 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1782 | default: // Default behavior: ignore. |
| 1783 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1784 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1785 | case PP_MACRO_OBJECT_LIKE: |
| 1786 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1787 | DecodeIdentifierInfo(Record[0]); |
| 1788 | break; |
| 1789 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1790 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1791 | // Ignore tokens. |
| 1792 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1793 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1794 | } |
| 1795 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1796 | |
| 1797 | // Drain the unread macro-record offsets map. |
| 1798 | while (!UnreadMacroRecordOffsets.empty()) |
| 1799 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1800 | } |
| 1801 | |
| 1802 | void ASTReader::LoadMacroDefinition( |
| 1803 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1804 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
| 1805 | PerFileData *F = 0; |
| 1806 | uint64_t Offset = Pos->second; |
| 1807 | UnreadMacroRecordOffsets.erase(Pos); |
| 1808 | |
| 1809 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1810 | if (Offset < Chain[I]->SizeInBits) { |
| 1811 | F = Chain[I]; |
| 1812 | break; |
| 1813 | } |
| 1814 | |
| 1815 | Offset -= Chain[I]->SizeInBits; |
| 1816 | } |
| 1817 | if (!F) { |
| 1818 | Error("Malformed macro record offset"); |
| 1819 | return; |
| 1820 | } |
| 1821 | |
| 1822 | ReadMacroRecord(*F, Offset); |
| 1823 | } |
| 1824 | |
| 1825 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1826 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1827 | = UnreadMacroRecordOffsets.find(II); |
| 1828 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1831 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1832 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1833 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1834 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1835 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1836 | unsigned Index = ID - 1; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1837 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1838 | PerFileData &F = *Chain[N - I - 1]; |
| 1839 | if (Index < F.LocalNumMacroDefinitions) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1840 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 1841 | F.PreprocessorDetailCursor.JumpToBit(F.MacroDefinitionOffsets[Index]); |
| 1842 | LoadPreprocessedEntity(F); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1843 | break; |
| 1844 | } |
| 1845 | Index -= F.LocalNumMacroDefinitions; |
| 1846 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1847 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1850 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1853 | const FileEntry *ASTReader::getFileEntry(llvm::StringRef filenameStrRef) { |
| 1854 | std::string Filename = filenameStrRef; |
| 1855 | MaybeAddSystemRootToFilename(Filename); |
| 1856 | const FileEntry *File = FileMgr.getFile(Filename); |
| 1857 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1858 | OriginalDir != CurrentDir) { |
| 1859 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1860 | OriginalDir, |
| 1861 | CurrentDir); |
| 1862 | if (!resolved.empty()) |
| 1863 | File = FileMgr.getFile(resolved); |
| 1864 | } |
| 1865 | |
| 1866 | return File; |
| 1867 | } |
| 1868 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1869 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1870 | /// not an absolute path, add the system root to the beginning of the file |
| 1871 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1872 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1873 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1874 | if (!RelocatablePCH) |
| 1875 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1876 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1877 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1878 | return; |
| 1879 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1880 | if (isysroot == 0) { |
| 1881 | // If no system root was given, default to '/' |
| 1882 | Filename.insert(Filename.begin(), '/'); |
| 1883 | return; |
| 1884 | } |
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 | unsigned Length = strlen(isysroot); |
| 1887 | if (isysroot[Length - 1] != '/') |
| 1888 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1889 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1890 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1891 | } |
| 1892 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1893 | ASTReader::ASTReadResult |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1894 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1895 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1896 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1897 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1898 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1899 | return Failure; |
| 1900 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1901 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1902 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1903 | RecordData Record; |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1904 | bool First = true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1905 | while (!Stream.AtEndOfStream()) { |
| 1906 | unsigned Code = Stream.ReadCode(); |
| 1907 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1908 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1909 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1910 | return Failure; |
| 1911 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1912 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1913 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1917 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1918 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1919 | // We lazily load the decls block, but we want to set up the |
| 1920 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1921 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1922 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1923 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1924 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1925 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1926 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1927 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1928 | return Failure; |
| 1929 | } |
| 1930 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1931 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1932 | case DECL_UPDATES_BLOCK_ID: |
| 1933 | if (Stream.SkipBlock()) { |
| 1934 | Error("malformed block record in AST file"); |
| 1935 | return Failure; |
| 1936 | } |
| 1937 | break; |
| 1938 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1939 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1940 | F.MacroCursor = Stream; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1941 | if (PP) |
| 1942 | PP->setExternalSource(this); |
| 1943 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1944 | if (Stream.SkipBlock() || |
| 1945 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1946 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1947 | return Failure; |
| 1948 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1949 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1950 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1951 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1952 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1953 | F.PreprocessorDetailCursor = Stream; |
| 1954 | if (Stream.SkipBlock() || |
| 1955 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1956 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1957 | Error("malformed preprocessor detail record in AST file"); |
| 1958 | return Failure; |
| 1959 | } |
| 1960 | F.PreprocessorDetailStartOffset |
| 1961 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 1962 | break; |
| 1963 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1964 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1965 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1966 | case Success: |
| 1967 | break; |
| 1968 | |
| 1969 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1970 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1971 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1972 | |
| 1973 | case IgnorePCH: |
| 1974 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1975 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1976 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1977 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1978 | First = false; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1979 | continue; |
| 1980 | } |
| 1981 | |
| 1982 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1983 | Stream.ReadAbbrevRecord(); |
| 1984 | continue; |
| 1985 | } |
| 1986 | |
| 1987 | // Read and process a record. |
| 1988 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1989 | const char *BlobStart = 0; |
| 1990 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1991 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1992 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1993 | default: // Default behavior: ignore. |
| 1994 | break; |
| 1995 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1996 | case METADATA: { |
| 1997 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1998 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1999 | : diag::warn_pch_version_too_new); |
| 2000 | return IgnorePCH; |
| 2001 | } |
| 2002 | |
| 2003 | RelocatablePCH = Record[4]; |
| 2004 | if (Listener) { |
| 2005 | std::string TargetTriple(BlobStart, BlobLen); |
| 2006 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 2007 | return IgnorePCH; |
| 2008 | } |
| 2009 | break; |
| 2010 | } |
| 2011 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2012 | case CHAINED_METADATA: { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2013 | if (!First) { |
| 2014 | Error("CHAINED_METADATA is not first record in block"); |
| 2015 | return Failure; |
| 2016 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2017 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 2018 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2019 | : diag::warn_pch_version_too_new); |
| 2020 | return IgnorePCH; |
| 2021 | } |
| 2022 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2023 | // Load the chained file, which is always a PCH file. |
| 2024 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2025 | case Failure: return Failure; |
| 2026 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 2027 | case IgnorePCH: return IgnorePCH; |
| 2028 | case Success: break; |
| 2029 | } |
| 2030 | break; |
| 2031 | } |
| 2032 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2033 | case TYPE_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2034 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2035 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2036 | return Failure; |
| 2037 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2038 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 2039 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2040 | break; |
| 2041 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2042 | case DECL_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2043 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2044 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2045 | return Failure; |
| 2046 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2047 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 2048 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 96e973f | 2011-07-20 00:27:43 +0000 | [diff] [blame^] | 2049 | |
| 2050 | // Introduce the global -> local mapping for declarations within this |
| 2051 | GlobalDeclMap.insert(std::make_pair(getTotalNumDecls() + 1, |
| 2052 | std::make_pair(&F, |
| 2053 | -getTotalNumDecls()))); |
| 2054 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 2055 | |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2056 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2057 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2058 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2059 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2060 | /* No visible information */ 0, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2061 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 2062 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2063 | }; |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2064 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 2065 | .push_back(Info); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2066 | break; |
| 2067 | } |
| 2068 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2069 | case UPDATE_VISIBLE: { |
| 2070 | serialization::DeclID ID = Record[0]; |
| 2071 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 2072 | (const unsigned char *)BlobStart + Record[1], |
| 2073 | (const unsigned char *)BlobStart, |
| 2074 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2075 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2076 | DeclContextInfo Info = { |
| 2077 | Table, /* No lexical inforamtion */ 0, 0 |
| 2078 | }; |
| 2079 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 2080 | } else |
| 2081 | PendingVisibleUpdates[ID].push_back(Table); |
| 2082 | break; |
| 2083 | } |
| 2084 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2085 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2086 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 2087 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2088 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2089 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 2090 | Latest > FirstLatestDeclIDs[First]) && |
| 2091 | "The new latest is supposed to come after the previous latest"); |
| 2092 | FirstLatestDeclIDs[First] = Latest; |
| 2093 | } |
| 2094 | break; |
| 2095 | } |
| 2096 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2097 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2098 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2099 | return IgnorePCH; |
| 2100 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2101 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2102 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2103 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2104 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2105 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2106 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2107 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2108 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2109 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2110 | if (PP) |
| 2111 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2112 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2113 | break; |
| 2114 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2115 | case IDENTIFIER_OFFSET: |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2116 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2117 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2118 | return Failure; |
| 2119 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2120 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2121 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2122 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2123 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2124 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2125 | // Optimization for the first block. |
| 2126 | if (ExternalDefinitions.empty()) |
| 2127 | ExternalDefinitions.swap(Record); |
| 2128 | else |
| 2129 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 2130 | Record.begin(), Record.end()); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2131 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2132 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2133 | case SPECIAL_TYPES: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2134 | // Optimization for the first block |
| 2135 | if (SpecialTypes.empty()) |
| 2136 | SpecialTypes.swap(Record); |
| 2137 | else |
| 2138 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2139 | break; |
| 2140 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2141 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2142 | TotalNumStatements += Record[0]; |
| 2143 | TotalNumMacros += Record[1]; |
| 2144 | TotalLexicalDeclContexts += Record[2]; |
| 2145 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2146 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2147 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2148 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2149 | // Optimization for the first block. |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2150 | if (UnusedFileScopedDecls.empty()) |
| 2151 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2152 | else |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2153 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 2154 | Record.begin(), Record.end()); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2155 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2156 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2157 | case DELEGATING_CTORS: |
| 2158 | // Optimization for the first block. |
| 2159 | if (DelegatingCtorDecls.empty()) |
| 2160 | DelegatingCtorDecls.swap(Record); |
| 2161 | else |
| 2162 | DelegatingCtorDecls.insert(DelegatingCtorDecls.end(), |
| 2163 | Record.begin(), Record.end()); |
| 2164 | break; |
| 2165 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2166 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2167 | // Later blocks overwrite earlier ones. |
| 2168 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2169 | break; |
| 2170 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2171 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2172 | // Optimization for the first block. |
| 2173 | if (LocallyScopedExternalDecls.empty()) |
| 2174 | LocallyScopedExternalDecls.swap(Record); |
| 2175 | else |
| 2176 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 2177 | Record.begin(), Record.end()); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2178 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2179 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2180 | case SELECTOR_OFFSETS: |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2181 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2182 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2183 | break; |
| 2184 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2185 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2186 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2187 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2188 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2189 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2190 | F.SelectorLookupTableData + Record[0], |
| 2191 | F.SelectorLookupTableData, |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2192 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2193 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2194 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2195 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2196 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2197 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2198 | break; |
| 2199 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2200 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2201 | if (!Record.empty() && Listener) |
| 2202 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2203 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2204 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2205 | case SOURCE_LOCATION_OFFSETS: { |
| 2206 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2207 | F.LocalNumSLocEntries = Record[0]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2208 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
| 2209 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, Record[1]); |
| 2210 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2211 | // we invert it. Because we invert it, though, we need the other end of |
| 2212 | // the range. |
| 2213 | unsigned RangeStart = |
| 2214 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2215 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2216 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2217 | |
| 2218 | // Initialize the remapping table. |
| 2219 | // Invalid stays invalid. |
| 2220 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2221 | // This module. Base was 2 when being compiled. |
| 2222 | F.SLocRemap.insert(std::make_pair(2U, |
| 2223 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
| 2224 | break; |
| 2225 | } |
| 2226 | |
| 2227 | case SOURCE_LOCATION_MAP: { |
| 2228 | // Additional remapping information. |
| 2229 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2230 | const unsigned char *DataEnd = Data + BlobLen; |
| 2231 | while(Data < DataEnd) { |
| 2232 | uint32_t Offset = io::ReadUnalignedLE32(Data); |
| 2233 | uint16_t Len = io::ReadUnalignedLE16(Data); |
| 2234 | llvm::StringRef Name = llvm::StringRef((const char*)Data, Len); |
| 2235 | PerFileData *OM = Modules.lookup(Name); |
| 2236 | if (!OM) { |
| 2237 | Error("SourceLocation remap refers to unknown module"); |
| 2238 | return Failure; |
| 2239 | } |
| 2240 | // My Offset is mapped to OM->SLocEntryBaseOffset. |
| 2241 | F.SLocRemap.insert(std::make_pair(Offset, |
| 2242 | static_cast<int>(OM->SLocEntryBaseOffset - Offset))); |
| 2243 | Data += Len; |
| 2244 | } |
| 2245 | break; |
| 2246 | } |
| 2247 | |
| 2248 | |
| 2249 | case SOURCE_MANAGER_LINE_TABLE: |
| 2250 | if (ParseLineTable(F, Record)) |
| 2251 | return Failure; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2252 | break; |
| 2253 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2254 | case FILE_SOURCE_LOCATION_OFFSETS: |
| 2255 | F.SLocFileOffsets = (const uint32_t *)BlobStart; |
| 2256 | F.LocalNumSLocFileEntries = Record[0]; |
| 2257 | break; |
| 2258 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2259 | case SOURCE_LOCATION_PRELOADS: { |
| 2260 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2261 | // which is based off F.SLocEntryBaseID. |
| 2262 | PreloadSLocEntries.reserve(PreloadSLocEntries.size() + Record.size()); |
| 2263 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2264 | PreloadSLocEntries.push_back(int(Record[I] - 1) + F.SLocEntryBaseID); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2265 | break; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2266 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2267 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2268 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2269 | if (!DisableStatCache) { |
| 2270 | ASTStatCache *MyStatCache = |
| 2271 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2272 | (const unsigned char *)BlobStart, |
| 2273 | NumStatHits, NumStatMisses); |
| 2274 | FileMgr.addStatCache(MyStatCache); |
| 2275 | F.StatCache = MyStatCache; |
| 2276 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2277 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2278 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2279 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2280 | case EXT_VECTOR_DECLS: |
Sebastian Redl | a9f2368 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 2281 | // Optimization for the first block. |
| 2282 | if (ExtVectorDecls.empty()) |
| 2283 | ExtVectorDecls.swap(Record); |
| 2284 | else |
| 2285 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 2286 | Record.begin(), Record.end()); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2287 | break; |
| 2288 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2289 | case VTABLE_USES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2290 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2291 | VTableUses.swap(Record); |
| 2292 | break; |
| 2293 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2294 | case DYNAMIC_CLASSES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2295 | // Optimization for the first block. |
| 2296 | if (DynamicClasses.empty()) |
| 2297 | DynamicClasses.swap(Record); |
| 2298 | else |
| 2299 | DynamicClasses.insert(DynamicClasses.end(), |
| 2300 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2301 | break; |
| 2302 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2303 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2304 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2305 | break; |
| 2306 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2307 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2308 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2309 | SemaDeclRefs.swap(Record); |
| 2310 | break; |
| 2311 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2312 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2313 | // 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] | 2314 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2315 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2316 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2317 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2318 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2319 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2320 | case ORIGINAL_FILE_ID: |
| 2321 | OriginalFileID = FileID::get(Record[0]); |
| 2322 | break; |
| 2323 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2324 | case ORIGINAL_PCH_DIR: |
| 2325 | // The primary AST will be the last to get here, so it will be the one |
| 2326 | // that's used. |
| 2327 | OriginalDir.assign(BlobStart, BlobLen); |
| 2328 | break; |
| 2329 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2330 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2331 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2332 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 2333 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2334 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2335 | return IgnorePCH; |
| 2336 | } |
| 2337 | break; |
| 2338 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2339 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2340 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2341 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2342 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2343 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2344 | break; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2345 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2346 | case DECL_UPDATE_OFFSETS: { |
| 2347 | if (Record.size() % 2 != 0) { |
| 2348 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2349 | return Failure; |
| 2350 | } |
| 2351 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
| 2352 | DeclUpdateOffsets[static_cast<DeclID>(Record[I])] |
| 2353 | .push_back(std::make_pair(&F, Record[I+1])); |
| 2354 | break; |
| 2355 | } |
| 2356 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2357 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2358 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2359 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2360 | return Failure; |
| 2361 | } |
| 2362 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2363 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2364 | std::make_pair(&F, Record[I+1]); |
| 2365 | break; |
| 2366 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2367 | |
| 2368 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2369 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2370 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2371 | return Failure; |
| 2372 | } |
| 2373 | |
| 2374 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2375 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
| 2376 | break; |
| 2377 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2378 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2379 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2380 | if (Record.size() % 2 != 0) { |
| 2381 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2382 | return Failure; |
| 2383 | } |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2384 | |
| 2385 | if (F.PragmaDiagMappings.empty()) |
| 2386 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2387 | else |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2388 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2389 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2390 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2391 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2392 | case CUDA_SPECIAL_DECL_REFS: |
| 2393 | // Later tables overwrite earlier ones. |
| 2394 | CUDASpecialDeclRefs.swap(Record); |
| 2395 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2396 | |
| 2397 | case HEADER_SEARCH_TABLE: |
| 2398 | F.HeaderFileInfoTableData = BlobStart; |
| 2399 | F.LocalNumHeaderFileInfos = Record[1]; |
| 2400 | if (Record[0]) { |
| 2401 | F.HeaderFileInfoTable |
| 2402 | = HeaderFileInfoLookupTable::Create( |
| 2403 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 2404 | (const unsigned char *)F.HeaderFileInfoTableData); |
| 2405 | if (PP) |
| 2406 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2407 | } |
| 2408 | break; |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2409 | |
| 2410 | case FP_PRAGMA_OPTIONS: |
| 2411 | // Later tables overwrite earlier ones. |
| 2412 | FPPragmaOptions.swap(Record); |
| 2413 | break; |
| 2414 | |
| 2415 | case OPENCL_EXTENSIONS: |
| 2416 | // Later tables overwrite earlier ones. |
| 2417 | OpenCLExtensions.swap(Record); |
| 2418 | break; |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2419 | |
| 2420 | case TENTATIVE_DEFINITIONS: |
| 2421 | // Optimization for the first block. |
| 2422 | if (TentativeDefinitions.empty()) |
| 2423 | TentativeDefinitions.swap(Record); |
| 2424 | else |
| 2425 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 2426 | Record.begin(), Record.end()); |
| 2427 | break; |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2428 | |
| 2429 | case KNOWN_NAMESPACES: |
| 2430 | // Optimization for the first block. |
| 2431 | if (KnownNamespaces.empty()) |
| 2432 | KnownNamespaces.swap(Record); |
| 2433 | else |
| 2434 | KnownNamespaces.insert(KnownNamespaces.end(), |
| 2435 | Record.begin(), Record.end()); |
| 2436 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2437 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2438 | First = false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2439 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2440 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2441 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2442 | } |
| 2443 | |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2444 | ASTReader::ASTReadResult ASTReader::validateFileEntries() { |
| 2445 | for (unsigned CI = 0, CN = Chain.size(); CI != CN; ++CI) { |
| 2446 | PerFileData *F = Chain[CI]; |
| 2447 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
| 2448 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2449 | for (unsigned i = 0, e = F->LocalNumSLocFileEntries; i != e; ++i) { |
| 2450 | SLocEntryCursor.JumpToBit(F->SLocFileOffsets[i]); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2451 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 2452 | if (Code == llvm::bitc::END_BLOCK || |
| 2453 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 2454 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 2455 | Error("incorrectly-formatted source location entry in AST file"); |
| 2456 | return Failure; |
| 2457 | } |
| 2458 | |
| 2459 | RecordData Record; |
| 2460 | const char *BlobStart; |
| 2461 | unsigned BlobLen; |
| 2462 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 2463 | default: |
| 2464 | Error("incorrectly-formatted source location entry in AST file"); |
| 2465 | return Failure; |
| 2466 | |
| 2467 | case SM_SLOC_FILE_ENTRY: { |
| 2468 | llvm::StringRef Filename(BlobStart, BlobLen); |
| 2469 | const FileEntry *File = getFileEntry(Filename); |
| 2470 | |
| 2471 | if (File == 0) { |
| 2472 | std::string ErrorStr = "could not find file '"; |
| 2473 | ErrorStr += Filename; |
| 2474 | ErrorStr += "' referenced by AST file"; |
| 2475 | Error(ErrorStr.c_str()); |
| 2476 | return IgnorePCH; |
| 2477 | } |
| 2478 | |
| 2479 | if (Record.size() < 6) { |
| 2480 | Error("source location entry is incorrect"); |
| 2481 | return Failure; |
| 2482 | } |
| 2483 | |
| 2484 | // The stat info from the FileEntry came from the cached stat |
| 2485 | // info of the PCH, so we cannot trust it. |
| 2486 | struct stat StatBuf; |
| 2487 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 2488 | StatBuf.st_size = File->getSize(); |
| 2489 | StatBuf.st_mtime = File->getModificationTime(); |
| 2490 | } |
| 2491 | |
| 2492 | if (((off_t)Record[4] != StatBuf.st_size |
| 2493 | #if !defined(LLVM_ON_WIN32) |
| 2494 | // In our regression testing, the Windows file system seems to |
| 2495 | // have inconsistent modification times that sometimes |
| 2496 | // erroneously trigger this error-handling path. |
| 2497 | || (time_t)Record[5] != StatBuf.st_mtime |
| 2498 | #endif |
| 2499 | )) { |
| 2500 | Error(diag::err_fe_pch_file_modified, Filename); |
| 2501 | return IgnorePCH; |
| 2502 | } |
| 2503 | |
| 2504 | break; |
| 2505 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2506 | } |
| 2507 | } |
| 2508 | } |
| 2509 | |
| 2510 | return Success; |
| 2511 | } |
| 2512 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2513 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2514 | ASTFileType Type) { |
| 2515 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2516 | case Failure: return Failure; |
| 2517 | case IgnorePCH: return IgnorePCH; |
| 2518 | case Success: break; |
| 2519 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2520 | |
| 2521 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2522 | |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2523 | if (!DisableValidation) { |
| 2524 | switch(validateFileEntries()) { |
| 2525 | case Failure: return Failure; |
| 2526 | case IgnorePCH: return IgnorePCH; |
| 2527 | case Success: break; |
| 2528 | } |
| 2529 | } |
| 2530 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2531 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Douglas Gregor | 96e973f | 2011-07-20 00:27:43 +0000 | [diff] [blame^] | 2532 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2533 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2534 | TotalNumSelectors = 0; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2535 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2536 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2537 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2538 | TotalNumTypes += Chain[I]->LocalNumTypes; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2539 | TotalNumPreallocatedPreprocessingEntities += |
| 2540 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2541 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2542 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2543 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2544 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2545 | TypesLoaded.resize(TotalNumTypes); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2546 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2547 | if (PP) { |
| 2548 | if (TotalNumIdentifiers > 0) |
| 2549 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2550 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2551 | if (!PP->getPreprocessingRecord()) |
Douglas Gregor | dca8ee8 | 2011-05-06 16:33:08 +0000 | [diff] [blame] | 2552 | PP->createPreprocessingRecord(true); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2553 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2554 | TotalNumPreallocatedPreprocessingEntities); |
| 2555 | } |
| 2556 | } |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2557 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2558 | // Preload SLocEntries. |
| 2559 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2560 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2561 | if (Result != Success) |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2562 | return Failure; |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2563 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2564 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2565 | // Check the predefines buffers. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2566 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2567 | return IgnorePCH; |
| 2568 | |
| 2569 | if (PP) { |
| 2570 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2571 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2572 | // loaded into the IdentifierTable before we intercepted the |
| 2573 | // creation of identifiers. Iterate through the list of known |
| 2574 | // identifiers and determine whether we have to establish |
| 2575 | // preprocessor definitions or top-level identifier declaration |
| 2576 | // chains for those identifiers. |
| 2577 | // |
| 2578 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2579 | // since de-serializing declarations or macro definitions can add |
| 2580 | // new entries into the identifier table, invalidating the |
| 2581 | // iterators. |
| 2582 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2583 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2584 | IdEnd = PP->getIdentifierTable().end(); |
| 2585 | Id != IdEnd; ++Id) |
| 2586 | Identifiers.push_back(Id->second); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2587 | // We need to search the tables in all files. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2588 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2589 | ASTIdentifierLookupTable *IdTable |
| 2590 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2591 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2592 | // ones. |
| 2593 | if (!IdTable) |
| 2594 | continue; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2595 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2596 | IdentifierInfo *II = Identifiers[I]; |
| 2597 | // 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] | 2598 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2599 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2600 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2601 | if (Pos == IdTable->end()) |
| 2602 | continue; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2603 | |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2604 | // Dereferencing the iterator has the effect of populating the |
| 2605 | // IdentifierInfo node with the various declarations it needs. |
| 2606 | (void)*Pos; |
| 2607 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2608 | } |
| 2609 | } |
| 2610 | |
| 2611 | if (Context) |
| 2612 | InitializeContext(*Context); |
| 2613 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2614 | if (DeserializationListener) |
| 2615 | DeserializationListener->ReaderInitialized(this); |
| 2616 | |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2617 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2618 | // the source manager to the file source file from which the preamble was |
| 2619 | // built. This is the only valid way to use a precompiled preamble. |
| 2620 | if (Type == Preamble) { |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2621 | if (OriginalFileID.isInvalid()) { |
| 2622 | SourceLocation Loc |
| 2623 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2624 | if (Loc.isValid()) |
| 2625 | OriginalFileID = SourceMgr.getDecomposedLoc(Loc).first; |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2626 | } |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2627 | else { |
| 2628 | OriginalFileID = FileID::get(Chain[0]->SLocEntryBaseID |
| 2629 | + OriginalFileID.getOpaqueValue() - 1); |
| 2630 | } |
| 2631 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2632 | if (!OriginalFileID.isInvalid()) |
| 2633 | SourceMgr.SetPreambleFileID(OriginalFileID); |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2634 | } |
| 2635 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2636 | return Success; |
| 2637 | } |
| 2638 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2639 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2640 | ASTFileType Type) { |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2641 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2642 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2643 | PerFileData &F = *Chain.back(); |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2644 | if (Prev) |
| 2645 | Prev->NextInSource = &F; |
| 2646 | else |
| 2647 | FirstInSource = &F; |
| 2648 | F.Loaders.push_back(Prev); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2649 | // A non-module AST file's module name is $filename. |
| 2650 | Modules["$" + FileName.str()] = &F; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2651 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2652 | // Set the AST file name. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2653 | F.FileName = FileName; |
| 2654 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2655 | if (FileName != "-") { |
| 2656 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2657 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2658 | } |
| 2659 | |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 2660 | if (!ASTBuffers.empty()) { |
Sebastian Redl | 5655837 | 2011-04-14 14:07:41 +0000 | [diff] [blame] | 2661 | F.Buffer.reset(ASTBuffers.back()); |
| 2662 | ASTBuffers.pop_back(); |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 2663 | assert(F.Buffer && "Passed null buffer"); |
| 2664 | } else { |
| 2665 | // Open the AST file. |
| 2666 | // |
| 2667 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2668 | std::string ErrStr; |
| 2669 | llvm::error_code ec; |
| 2670 | if (FileName == "-") { |
| 2671 | ec = llvm::MemoryBuffer::getSTDIN(F.Buffer); |
| 2672 | if (ec) |
| 2673 | ErrStr = ec.message(); |
| 2674 | } else |
| 2675 | F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr)); |
| 2676 | if (!F.Buffer) { |
| 2677 | Error(ErrStr.c_str()); |
| 2678 | return IgnorePCH; |
| 2679 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2680 | } |
| 2681 | |
| 2682 | // Initialize the stream |
| 2683 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2684 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2685 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2686 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2687 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2688 | |
| 2689 | // Sniff for the signature. |
| 2690 | if (Stream.Read(8) != 'C' || |
| 2691 | Stream.Read(8) != 'P' || |
| 2692 | Stream.Read(8) != 'C' || |
| 2693 | Stream.Read(8) != 'H') { |
| 2694 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2695 | return Failure; |
| 2696 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2697 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2698 | while (!Stream.AtEndOfStream()) { |
| 2699 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2700 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2701 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2702 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2703 | return Failure; |
| 2704 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2705 | |
| 2706 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2707 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2708 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2709 | switch (BlockID) { |
| 2710 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2711 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2712 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2713 | return Failure; |
| 2714 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2715 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2716 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2717 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2718 | case Success: |
| 2719 | break; |
| 2720 | |
| 2721 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2722 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2723 | |
| 2724 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2725 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2726 | // AST block, skipping subblocks, to see if there are other |
| 2727 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2728 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2729 | // FIXME: We can't clear loaded slocentries anymore. |
| 2730 | //SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2731 | |
| 2732 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2733 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2734 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2735 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2736 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2737 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2738 | break; |
| 2739 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2740 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2741 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2742 | return Failure; |
| 2743 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2744 | break; |
| 2745 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2746 | } |
| 2747 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2748 | return Success; |
| 2749 | } |
| 2750 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2751 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2752 | PP = &pp; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2753 | |
| 2754 | unsigned TotalNum = 0; |
| 2755 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2756 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2757 | if (TotalNum) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2758 | if (!PP->getPreprocessingRecord()) |
Douglas Gregor | dca8ee8 | 2011-05-06 16:33:08 +0000 | [diff] [blame] | 2759 | PP->createPreprocessingRecord(true); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2760 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2761 | } |
| 2762 | } |
| 2763 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2764 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2765 | Context = &Ctx; |
| 2766 | assert(Context && "Passed null context!"); |
| 2767 | |
| 2768 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2769 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2770 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2771 | PP->setExternalSource(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2772 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2773 | |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2774 | // If we have an update block for the TU waiting, we have to add it before |
| 2775 | // deserializing the decl. |
| 2776 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2777 | if (DCU != DeclContextOffsets.end()) { |
| 2778 | // Insertion could invalidate map, so grab vector. |
| 2779 | DeclContextInfos T; |
| 2780 | T.swap(DCU->second); |
| 2781 | DeclContextOffsets.erase(DCU); |
| 2782 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2783 | } |
| 2784 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2785 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2786 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2787 | |
| 2788 | // Load the special types. |
| 2789 | Context->setBuiltinVaListType( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2790 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2791 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2792 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2793 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2794 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2795 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2796 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2797 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2798 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2799 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2800 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2801 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2802 | if (unsigned FastEnum |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2803 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2804 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2805 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2806 | QualType FileType = GetType(File); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2807 | if (FileType.isNull()) { |
| 2808 | Error("FILE type is NULL"); |
| 2809 | return; |
| 2810 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2811 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2812 | Context->setFILEDecl(Typedef->getDecl()); |
| 2813 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2814 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2815 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2816 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2817 | return; |
| 2818 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2819 | Context->setFILEDecl(Tag->getDecl()); |
| 2820 | } |
| 2821 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2822 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2823 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2824 | if (Jmp_bufType.isNull()) { |
| 2825 | Error("jmp_bug type is NULL"); |
| 2826 | return; |
| 2827 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2828 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2829 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2830 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2831 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2832 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2833 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2834 | return; |
| 2835 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2836 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2837 | } |
| 2838 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2839 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2840 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2841 | if (Sigjmp_bufType.isNull()) { |
| 2842 | Error("sigjmp_buf type is NULL"); |
| 2843 | return; |
| 2844 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2845 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2846 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2847 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2848 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2849 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2850 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2851 | } |
| 2852 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2853 | if (unsigned ObjCIdRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2854 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2855 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2856 | if (unsigned ObjCClassRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2857 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2858 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2859 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2860 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2861 | if (unsigned String |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2862 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2863 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2864 | if (unsigned ObjCSelRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2865 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2866 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2867 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2868 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2869 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2870 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2871 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2872 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2873 | if (unsigned AutoDeduct = SpecialTypes[SPECIAL_TYPE_AUTO_DEDUCT]) |
| 2874 | Context->AutoDeductTy = GetType(AutoDeduct); |
| 2875 | if (unsigned AutoRRefDeduct = SpecialTypes[SPECIAL_TYPE_AUTO_RREF_DEDUCT]) |
| 2876 | Context->AutoRRefDeductTy = GetType(AutoRRefDeduct); |
| 2877 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2878 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2879 | |
| 2880 | // If there were any CUDA special declarations, deserialize them. |
| 2881 | if (!CUDASpecialDeclRefs.empty()) { |
| 2882 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 2883 | Context->setcudaConfigureCallDecl( |
| 2884 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2885 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2886 | } |
| 2887 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2888 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2889 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2890 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2891 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2892 | FileManager &FileMgr, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2893 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2894 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2895 | std::string ErrStr; |
| 2896 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2897 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2898 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2899 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2900 | return std::string(); |
| 2901 | } |
| 2902 | |
| 2903 | // Initialize the stream |
| 2904 | llvm::BitstreamReader StreamFile; |
| 2905 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2906 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2907 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2908 | Stream.init(StreamFile); |
| 2909 | |
| 2910 | // Sniff for the signature. |
| 2911 | if (Stream.Read(8) != 'C' || |
| 2912 | Stream.Read(8) != 'P' || |
| 2913 | Stream.Read(8) != 'C' || |
| 2914 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2915 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2916 | return std::string(); |
| 2917 | } |
| 2918 | |
| 2919 | RecordData Record; |
| 2920 | while (!Stream.AtEndOfStream()) { |
| 2921 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2922 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2923 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2924 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2925 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2926 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2927 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2928 | case AST_BLOCK_ID: |
| 2929 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2930 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2931 | return std::string(); |
| 2932 | } |
| 2933 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2934 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2935 | default: |
| 2936 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2937 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2938 | return std::string(); |
| 2939 | } |
| 2940 | break; |
| 2941 | } |
| 2942 | continue; |
| 2943 | } |
| 2944 | |
| 2945 | if (Code == llvm::bitc::END_BLOCK) { |
| 2946 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2947 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2948 | return std::string(); |
| 2949 | } |
| 2950 | continue; |
| 2951 | } |
| 2952 | |
| 2953 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2954 | Stream.ReadAbbrevRecord(); |
| 2955 | continue; |
| 2956 | } |
| 2957 | |
| 2958 | Record.clear(); |
| 2959 | const char *BlobStart = 0; |
| 2960 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2961 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2962 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2963 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2964 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2965 | |
| 2966 | return std::string(); |
| 2967 | } |
| 2968 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2969 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2970 | /// structure. |
| 2971 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2972 | /// This routine parses the language options from the AST file and then gives |
| 2973 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2974 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2975 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2976 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2977 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2978 | if (Listener) { |
| 2979 | LangOptions LangOpts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2980 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2981 | #define PARSE_LANGOPT(Option) \ |
| 2982 | LangOpts.Option = Record[Idx]; \ |
| 2983 | ++Idx |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2984 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2985 | unsigned Idx = 0; |
| 2986 | PARSE_LANGOPT(Trigraphs); |
| 2987 | PARSE_LANGOPT(BCPLComment); |
| 2988 | PARSE_LANGOPT(DollarIdents); |
| 2989 | PARSE_LANGOPT(AsmPreprocessor); |
| 2990 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2991 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2992 | PARSE_LANGOPT(ImplicitInt); |
| 2993 | PARSE_LANGOPT(Digraphs); |
| 2994 | PARSE_LANGOPT(HexFloats); |
| 2995 | PARSE_LANGOPT(C99); |
Peter Collingbourne | 7e7fbd0 | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 2996 | PARSE_LANGOPT(C1X); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2997 | PARSE_LANGOPT(Microsoft); |
| 2998 | PARSE_LANGOPT(CPlusPlus); |
| 2999 | PARSE_LANGOPT(CPlusPlus0x); |
| 3000 | PARSE_LANGOPT(CXXOperatorNames); |
| 3001 | PARSE_LANGOPT(ObjC1); |
| 3002 | PARSE_LANGOPT(ObjC2); |
| 3003 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 3004 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 3005 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 3006 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Douglas Gregor | 74da19f | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 3007 | PARSE_LANGOPT(ObjCInferRelatedResultType); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 3008 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3009 | PARSE_LANGOPT(PascalStrings); |
| 3010 | PARSE_LANGOPT(WritableStrings); |
| 3011 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 3012 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3013 | PARSE_LANGOPT(Exceptions); |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 3014 | PARSE_LANGOPT(ObjCExceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 3015 | PARSE_LANGOPT(CXXExceptions); |
| 3016 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 3017 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3018 | PARSE_LANGOPT(NeXTRuntime); |
| 3019 | PARSE_LANGOPT(Freestanding); |
| 3020 | PARSE_LANGOPT(NoBuiltin); |
| 3021 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 3022 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3023 | PARSE_LANGOPT(Blocks); |
| 3024 | PARSE_LANGOPT(EmitAllDecls); |
| 3025 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3026 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 3027 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3028 | PARSE_LANGOPT(HeinousExtensions); |
| 3029 | PARSE_LANGOPT(Optimize); |
| 3030 | PARSE_LANGOPT(OptimizeSize); |
| 3031 | PARSE_LANGOPT(Static); |
| 3032 | PARSE_LANGOPT(PICLevel); |
| 3033 | PARSE_LANGOPT(GNUInline); |
| 3034 | PARSE_LANGOPT(NoInline); |
Chandler Carruth | 0d2d1bc | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 3035 | PARSE_LANGOPT(Deprecated); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3036 | PARSE_LANGOPT(AccessControl); |
| 3037 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 3038 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | b1bdced | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 3039 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3040 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 3041 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 3042 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3043 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3044 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 3045 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 3046 | PARSE_LANGOPT(CUDA); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 3047 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3048 | PARSE_LANGOPT(DefaultFPContract); |
Roman Divacky | 1c51b1c | 2011-03-01 17:36:40 +0000 | [diff] [blame] | 3049 | PARSE_LANGOPT(ElideConstructors); |
| 3050 | PARSE_LANGOPT(SpellChecking); |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 3051 | PARSE_LANGOPT(MRTD); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3052 | PARSE_LANGOPT(ObjCAutoRefCount); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3053 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3054 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3055 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3056 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3057 | |
| 3058 | return false; |
| 3059 | } |
| 3060 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3061 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3062 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3063 | PerFileData &F = *Chain[I]; |
| 3064 | if (!F.PreprocessorDetailCursor.getBitStreamReader()) |
| 3065 | continue; |
| 3066 | |
| 3067 | SavedStreamPosition SavedPosition(F.PreprocessorDetailCursor); |
| 3068 | F.PreprocessorDetailCursor.JumpToBit(F.PreprocessorDetailStartOffset); |
| 3069 | while (LoadPreprocessedEntity(F)) { } |
| 3070 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3071 | } |
| 3072 | |
Douglas Gregor | 0a48029 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 3073 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3074 | PerFileData *F = 0; |
| 3075 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3076 | if (Offset < Chain[I]->SizeInBits) { |
| 3077 | F = Chain[I]; |
| 3078 | break; |
| 3079 | } |
| 3080 | |
| 3081 | Offset -= Chain[I]->SizeInBits; |
| 3082 | } |
| 3083 | |
| 3084 | if (!F) { |
| 3085 | Error("Malformed preprocessed entity offset"); |
| 3086 | return 0; |
| 3087 | } |
| 3088 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3089 | // Keep track of where we are in the stream, then jump back there |
| 3090 | // after reading this entity. |
| 3091 | SavedStreamPosition SavedPosition(F->PreprocessorDetailCursor); |
| 3092 | F->PreprocessorDetailCursor.JumpToBit(Offset); |
| 3093 | return LoadPreprocessedEntity(*F); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3094 | } |
| 3095 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3096 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
| 3097 | HeaderFileInfoTrait Trait(FE->getName()); |
| 3098 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3099 | PerFileData &F = *Chain[I]; |
| 3100 | HeaderFileInfoLookupTable *Table |
| 3101 | = static_cast<HeaderFileInfoLookupTable *>(F.HeaderFileInfoTable); |
| 3102 | if (!Table) |
| 3103 | continue; |
| 3104 | |
| 3105 | // Look in the on-disk hash table for an entry for this file name. |
| 3106 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE->getName(), |
| 3107 | &Trait); |
| 3108 | if (Pos == Table->end()) |
| 3109 | continue; |
| 3110 | |
| 3111 | HeaderFileInfo HFI = *Pos; |
| 3112 | if (Listener) |
| 3113 | Listener->ReadHeaderFileInfo(HFI, FE->getUID()); |
| 3114 | |
| 3115 | return HFI; |
| 3116 | } |
| 3117 | |
| 3118 | return HeaderFileInfo(); |
| 3119 | } |
| 3120 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3121 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3122 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3123 | PerFileData &F = *Chain[I]; |
| 3124 | unsigned Idx = 0; |
| 3125 | while (Idx < F.PragmaDiagMappings.size()) { |
| 3126 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 3127 | while (1) { |
| 3128 | assert(Idx < F.PragmaDiagMappings.size() && |
| 3129 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 3130 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 3131 | break; // Something is messed up but at least avoid infinite loop in |
| 3132 | // release build. |
| 3133 | } |
| 3134 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 3135 | if (DiagID == (unsigned)-1) { |
| 3136 | break; // no more diag/map pairs for this location. |
| 3137 | } |
| 3138 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
| 3139 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 3140 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3141 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3142 | } |
| 3143 | } |
| 3144 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3145 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3146 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3147 | PerFileData *F = 0; |
| 3148 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3149 | F = Chain[N - I - 1]; |
| 3150 | if (Index < F->LocalNumTypes) |
| 3151 | break; |
| 3152 | Index -= F->LocalNumTypes; |
| 3153 | } |
| 3154 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3155 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3159 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3160 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 3161 | /// routine actually reads the record corresponding to the type at the given |
| 3162 | /// location. It is a helper routine for GetType, which deals with reading type |
| 3163 | /// IDs. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3164 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3165 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3166 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3167 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3168 | // Keep track of where we are in the stream, then jump back there |
| 3169 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3170 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3171 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3172 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3173 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3174 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3175 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3176 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3177 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3178 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3179 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3180 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 3181 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3182 | if (Record.size() != 2) { |
| 3183 | Error("Incorrect encoding of extended qualifier type"); |
| 3184 | return QualType(); |
| 3185 | } |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3186 | QualType Base = GetType(Record[0]); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3187 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 3188 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3189 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3190 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3191 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3192 | if (Record.size() != 1) { |
| 3193 | Error("Incorrect encoding of complex type"); |
| 3194 | return QualType(); |
| 3195 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3196 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3197 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3198 | } |
| 3199 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3200 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3201 | if (Record.size() != 1) { |
| 3202 | Error("Incorrect encoding of pointer type"); |
| 3203 | return QualType(); |
| 3204 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3205 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3206 | return Context->getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3207 | } |
| 3208 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3209 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3210 | if (Record.size() != 1) { |
| 3211 | Error("Incorrect encoding of block pointer type"); |
| 3212 | return QualType(); |
| 3213 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3214 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3215 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3216 | } |
| 3217 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3218 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3219 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3220 | Error("Incorrect encoding of lvalue reference type"); |
| 3221 | return QualType(); |
| 3222 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3223 | QualType PointeeType = GetType(Record[0]); |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3224 | return Context->getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3225 | } |
| 3226 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3227 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3228 | if (Record.size() != 1) { |
| 3229 | Error("Incorrect encoding of rvalue reference type"); |
| 3230 | return QualType(); |
| 3231 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3232 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3233 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3234 | } |
| 3235 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3236 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3237 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3238 | Error("Incorrect encoding of member pointer type"); |
| 3239 | return QualType(); |
| 3240 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3241 | QualType PointeeType = GetType(Record[0]); |
| 3242 | QualType ClassType = GetType(Record[1]); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3243 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3244 | return QualType(); |
| 3245 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3246 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3247 | } |
| 3248 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3249 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3250 | QualType ElementType = GetType(Record[0]); |
| 3251 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3252 | unsigned IndexTypeQuals = Record[2]; |
| 3253 | unsigned Idx = 3; |
| 3254 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3255 | return Context->getConstantArrayType(ElementType, Size, |
| 3256 | ASM, IndexTypeQuals); |
| 3257 | } |
| 3258 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3259 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3260 | QualType ElementType = GetType(Record[0]); |
| 3261 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3262 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3263 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3264 | } |
| 3265 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3266 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3267 | QualType ElementType = GetType(Record[0]); |
| 3268 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3269 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3270 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3271 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 3272 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3273 | ASM, IndexTypeQuals, |
| 3274 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3275 | } |
| 3276 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3277 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3278 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3279 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3280 | return QualType(); |
| 3281 | } |
| 3282 | |
| 3283 | QualType ElementType = GetType(Record[0]); |
| 3284 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3285 | unsigned VecKind = Record[2]; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3286 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3287 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3288 | } |
| 3289 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3290 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3291 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3292 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3293 | return QualType(); |
| 3294 | } |
| 3295 | |
| 3296 | QualType ElementType = GetType(Record[0]); |
| 3297 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3298 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3299 | } |
| 3300 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3301 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3302 | if (Record.size() != 6) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3303 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3304 | return QualType(); |
| 3305 | } |
| 3306 | QualType ResultType = GetType(Record[0]); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3307 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 3308 | (CallingConv)Record[4], Record[5]); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 3309 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3310 | } |
| 3311 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3312 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3313 | QualType ResultType = GetType(Record[0]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3314 | |
| 3315 | FunctionProtoType::ExtProtoInfo EPI; |
| 3316 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3317 | /*hasregparm*/ Record[2], |
| 3318 | /*regparm*/ Record[3], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3319 | static_cast<CallingConv>(Record[4]), |
| 3320 | /*produces*/ Record[5]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3321 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3322 | unsigned Idx = 6; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3323 | unsigned NumParams = Record[Idx++]; |
| 3324 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 3325 | for (unsigned I = 0; I != NumParams; ++I) |
| 3326 | ParamTypes.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3327 | |
| 3328 | EPI.Variadic = Record[Idx++]; |
| 3329 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3330 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3331 | ExceptionSpecificationType EST = |
| 3332 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3333 | EPI.ExceptionSpecType = EST; |
| 3334 | if (EST == EST_Dynamic) { |
| 3335 | EPI.NumExceptions = Record[Idx++]; |
| 3336 | llvm::SmallVector<QualType, 2> Exceptions; |
| 3337 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
| 3338 | Exceptions.push_back(GetType(Record[Idx++])); |
| 3339 | EPI.Exceptions = Exceptions.data(); |
| 3340 | } else if (EST == EST_ComputedNoexcept) { |
| 3341 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
| 3342 | } |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 3343 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3344 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3345 | } |
| 3346 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3347 | case TYPE_UNRESOLVED_USING: |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3348 | return Context->getTypeDeclType( |
| 3349 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 3350 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3351 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3352 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3353 | Error("incorrect encoding of typedef type"); |
| 3354 | return QualType(); |
| 3355 | } |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3356 | TypedefNameDecl *Decl = cast<TypedefNameDecl>(GetDecl(Record[0])); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3357 | QualType Canonical = GetType(Record[1]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3358 | if (!Canonical.isNull()) |
| 3359 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3360 | return Context->getTypedefType(Decl, Canonical); |
| 3361 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3362 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3363 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3364 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3365 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3366 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3367 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3368 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3369 | return QualType(); |
| 3370 | } |
| 3371 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3372 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3373 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3374 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3375 | case TYPE_DECLTYPE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3376 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3377 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3378 | case TYPE_UNARY_TRANSFORM: { |
| 3379 | QualType BaseType = GetType(Record[0]); |
| 3380 | QualType UnderlyingType = GetType(Record[1]); |
| 3381 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
| 3382 | return Context->getUnaryTransformType(BaseType, UnderlyingType, UKind); |
| 3383 | } |
| 3384 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3385 | case TYPE_AUTO: |
| 3386 | return Context->getAutoType(GetType(Record[0])); |
| 3387 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3388 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3389 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3390 | Error("incorrect encoding of record type"); |
| 3391 | return QualType(); |
| 3392 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3393 | bool IsDependent = Record[0]; |
| 3394 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3395 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3396 | return T; |
| 3397 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3398 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3399 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3400 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3401 | Error("incorrect encoding of enum type"); |
| 3402 | return QualType(); |
| 3403 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3404 | bool IsDependent = Record[0]; |
| 3405 | QualType T = Context->getEnumType(cast<EnumDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3406 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3407 | return T; |
| 3408 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3409 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3410 | case TYPE_ATTRIBUTED: { |
| 3411 | if (Record.size() != 3) { |
| 3412 | Error("incorrect encoding of attributed type"); |
| 3413 | return QualType(); |
| 3414 | } |
| 3415 | QualType modifiedType = GetType(Record[0]); |
| 3416 | QualType equivalentType = GetType(Record[1]); |
| 3417 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 3418 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 3419 | } |
| 3420 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3421 | case TYPE_PAREN: { |
| 3422 | if (Record.size() != 1) { |
| 3423 | Error("incorrect encoding of paren type"); |
| 3424 | return QualType(); |
| 3425 | } |
| 3426 | QualType InnerType = GetType(Record[0]); |
| 3427 | return Context->getParenType(InnerType); |
| 3428 | } |
| 3429 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3430 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3431 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3432 | Error("incorrect encoding of pack expansion type"); |
| 3433 | return QualType(); |
| 3434 | } |
| 3435 | QualType Pattern = GetType(Record[0]); |
| 3436 | if (Pattern.isNull()) |
| 3437 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3438 | llvm::Optional<unsigned> NumExpansions; |
| 3439 | if (Record[1]) |
| 3440 | NumExpansions = Record[1] - 1; |
| 3441 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3442 | } |
| 3443 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3444 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3445 | unsigned Idx = 0; |
| 3446 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3447 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3448 | QualType NamedType = GetType(Record[Idx++]); |
| 3449 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3450 | } |
| 3451 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3452 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3453 | unsigned Idx = 0; |
| 3454 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3455 | return Context->getObjCInterfaceType(ItfD); |
| 3456 | } |
| 3457 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3458 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3459 | unsigned Idx = 0; |
| 3460 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3461 | unsigned NumProtos = Record[Idx++]; |
| 3462 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 3463 | for (unsigned I = 0; I != NumProtos; ++I) |
| 3464 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3465 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3466 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3467 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3468 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3469 | unsigned Idx = 0; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3470 | QualType Pointee = GetType(Record[Idx++]); |
| 3471 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3472 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3473 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3474 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3475 | unsigned Idx = 0; |
| 3476 | QualType Parm = GetType(Record[Idx++]); |
| 3477 | QualType Replacement = GetType(Record[Idx++]); |
| 3478 | return |
| 3479 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3480 | Replacement); |
| 3481 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3482 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3483 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3484 | unsigned Idx = 0; |
| 3485 | QualType Parm = GetType(Record[Idx++]); |
| 3486 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3487 | return Context->getSubstTemplateTypeParmPackType( |
| 3488 | cast<TemplateTypeParmType>(Parm), |
| 3489 | ArgPack); |
| 3490 | } |
| 3491 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3492 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3493 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 3494 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3495 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3496 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3497 | return |
| 3498 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3499 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3500 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3501 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3502 | unsigned Idx = 0; |
| 3503 | unsigned Depth = Record[Idx++]; |
| 3504 | unsigned Index = Record[Idx++]; |
| 3505 | bool Pack = Record[Idx++]; |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 3506 | TemplateTypeParmDecl *D = |
| 3507 | cast_or_null<TemplateTypeParmDecl>(GetDecl(Record[Idx++])); |
| 3508 | return Context->getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3509 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3510 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3511 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3512 | unsigned Idx = 0; |
| 3513 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3514 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3515 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3516 | QualType Canon = GetType(Record[Idx++]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3517 | if (!Canon.isNull()) |
| 3518 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3519 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3520 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3521 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3522 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3523 | unsigned Idx = 0; |
| 3524 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3525 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3526 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
| 3527 | unsigned NumArgs = Record[Idx++]; |
| 3528 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 3529 | Args.reserve(NumArgs); |
| 3530 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3531 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3532 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3533 | Args.size(), Args.data()); |
| 3534 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3535 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3536 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3537 | unsigned Idx = 0; |
| 3538 | |
| 3539 | // ArrayType |
| 3540 | QualType ElementType = GetType(Record[Idx++]); |
| 3541 | ArrayType::ArraySizeModifier ASM |
| 3542 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3543 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3544 | |
| 3545 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3546 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3547 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3548 | |
| 3549 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3550 | IndexTypeQuals, Brackets); |
| 3551 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3552 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3553 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3554 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3555 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3556 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3557 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3558 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3559 | QualType Underlying = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3560 | QualType T; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3561 | if (Underlying.isNull()) |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3562 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3563 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3564 | else |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3565 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3566 | Args.size(), Underlying); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3567 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3568 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3569 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3570 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3571 | // Suppress a GCC warning |
| 3572 | return QualType(); |
| 3573 | } |
| 3574 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3575 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3576 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3577 | ASTReader::PerFileData &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3578 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3579 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3580 | unsigned &Idx; |
| 3581 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3582 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3583 | unsigned &I) { |
| 3584 | return Reader.ReadSourceLocation(F, R, I); |
| 3585 | } |
| 3586 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3587 | public: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3588 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3589 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3590 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3591 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3592 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3593 | // We want compile-time assurance that we've enumerated all of |
| 3594 | // these, so unfortunately we have to declare them first, then |
| 3595 | // define them out-of-line. |
| 3596 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3597 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3598 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3599 | #include "clang/AST/TypeLocNodes.def" |
| 3600 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3601 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3602 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3603 | }; |
| 3604 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3605 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3606 | // nothing to do |
| 3607 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3608 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3609 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3610 | if (TL.needsExtraLocalData()) { |
| 3611 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3612 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3613 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3614 | TL.setModeAttr(Record[Idx++]); |
| 3615 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3616 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3617 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3618 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3619 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3620 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3621 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3622 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3623 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3624 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3625 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3626 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3627 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3628 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3629 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3630 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3631 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3632 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3633 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3634 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3635 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3636 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3637 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3638 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3639 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3640 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3641 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3642 | TL.setSizeExpr(0); |
| 3643 | } |
| 3644 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3645 | VisitArrayTypeLoc(TL); |
| 3646 | } |
| 3647 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3648 | VisitArrayTypeLoc(TL); |
| 3649 | } |
| 3650 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3651 | VisitArrayTypeLoc(TL); |
| 3652 | } |
| 3653 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3654 | DependentSizedArrayTypeLoc TL) { |
| 3655 | VisitArrayTypeLoc(TL); |
| 3656 | } |
| 3657 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3658 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3659 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3660 | } |
| 3661 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3662 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3663 | } |
| 3664 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3665 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3666 | } |
| 3667 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3668 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 3669 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3670 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3671 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | 86acc2a | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 3672 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3673 | } |
| 3674 | } |
| 3675 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3676 | VisitFunctionTypeLoc(TL); |
| 3677 | } |
| 3678 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3679 | VisitFunctionTypeLoc(TL); |
| 3680 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3681 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3682 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3683 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3684 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3685 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3686 | } |
| 3687 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3688 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3689 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3690 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3691 | } |
| 3692 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3693 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3694 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3695 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3696 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3697 | } |
| 3698 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3699 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3700 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3701 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 3702 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 3703 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3704 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3705 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 3706 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3707 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3708 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3709 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3710 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3711 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3712 | } |
| 3713 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3714 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3715 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3716 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3717 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3718 | if (TL.hasAttrOperand()) { |
| 3719 | SourceRange range; |
| 3720 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3721 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3722 | TL.setAttrOperandParensRange(range); |
| 3723 | } |
| 3724 | if (TL.hasAttrExprOperand()) { |
| 3725 | if (Record[Idx++]) |
| 3726 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3727 | else |
| 3728 | TL.setAttrExprOperand(0); |
| 3729 | } else if (TL.hasAttrEnumOperand()) |
| 3730 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3731 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3732 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3733 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3734 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3735 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3736 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3737 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3738 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3739 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3740 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3741 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3742 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3743 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3744 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3745 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3746 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3747 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3748 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3749 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3750 | Reader.GetTemplateArgumentLocInfo(F, |
| 3751 | TL.getTypePtr()->getArg(i).getKind(), |
| 3752 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3753 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3754 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3755 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3756 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3757 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3758 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3759 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3760 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3761 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3762 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3763 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3764 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3765 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3766 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3767 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3768 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3769 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3770 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3771 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3772 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3773 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3774 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3775 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3776 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3777 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3778 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3779 | Reader.GetTemplateArgumentLocInfo(F, |
| 3780 | TL.getTypePtr()->getArg(I).getKind(), |
| 3781 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3782 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3783 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3784 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3785 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3786 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3787 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3788 | } |
| 3789 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3790 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3791 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3792 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3793 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3794 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3795 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3796 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3797 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3798 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3799 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3800 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3801 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3802 | unsigned &Idx) { |
| 3803 | QualType InfoTy = GetType(Record[Idx++]); |
| 3804 | if (InfoTy.isNull()) |
| 3805 | return 0; |
| 3806 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3807 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3808 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3809 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3810 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3811 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3812 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3813 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3814 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3815 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3816 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3817 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3818 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3819 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3820 | switch ((PredefinedTypeIDs)Index) { |
| 3821 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3822 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3823 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3824 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3825 | case PREDEF_TYPE_CHAR_U_ID: |
| 3826 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3827 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3828 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3829 | break; |
| 3830 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3831 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3832 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3833 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3834 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3835 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3836 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3837 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3838 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3839 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3840 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3841 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3842 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3843 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3844 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3845 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3846 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3847 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 3848 | case PREDEF_TYPE_BOUND_MEMBER: T = Context->BoundMemberTy; break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3849 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
John McCall | 1de4d4e | 2011-04-07 08:22:57 +0000 | [diff] [blame] | 3850 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context->UnknownAnyTy; break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3851 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3852 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3853 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3854 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3855 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3856 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
| 3859 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3860 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3861 | } |
| 3862 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3863 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3864 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3865 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3866 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3867 | if (TypesLoaded[Index].isNull()) |
| 3868 | return QualType(); |
| 3869 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3870 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3871 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3872 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3873 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3874 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3875 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3876 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3877 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3878 | } |
| 3879 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3880 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3881 | return MakeTypeID(T, |
| 3882 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3883 | } |
| 3884 | |
| 3885 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3886 | if (T.isNull()) |
| 3887 | return TypeIdx(); |
| 3888 | assert(!T.getLocalFastQualifiers()); |
| 3889 | |
| 3890 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3891 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3892 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3893 | // If the type didn't come from the AST file use a specially marked index |
| 3894 | // so that any hash/key comparison fail since no such index is stored |
| 3895 | // in a AST file. |
| 3896 | if (I == TypeIdxs.end()) |
| 3897 | return TypeIdx(-1); |
| 3898 | return I->second; |
| 3899 | } |
| 3900 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3901 | unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const { |
| 3902 | unsigned Result = 0; |
| 3903 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 3904 | Result += Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3905 | |
| 3906 | return Result; |
| 3907 | } |
| 3908 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3909 | TemplateArgumentLocInfo |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3910 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3911 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3912 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3913 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3914 | switch (Kind) { |
| 3915 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3916 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3917 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3918 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3919 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3920 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3921 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3922 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3923 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3924 | SourceLocation()); |
| 3925 | } |
| 3926 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3927 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3928 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3929 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3930 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3931 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3932 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3933 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3934 | case TemplateArgument::Null: |
| 3935 | case TemplateArgument::Integral: |
| 3936 | case TemplateArgument::Declaration: |
| 3937 | case TemplateArgument::Pack: |
| 3938 | return TemplateArgumentLocInfo(); |
| 3939 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3940 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3941 | return TemplateArgumentLocInfo(); |
| 3942 | } |
| 3943 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3944 | TemplateArgumentLoc |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3945 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3946 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3947 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3948 | |
| 3949 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3950 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3951 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3952 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3953 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3954 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3955 | } |
| 3956 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3957 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3958 | return GetDecl(ID); |
| 3959 | } |
| 3960 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3961 | uint64_t |
| 3962 | ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) { |
| 3963 | if (ID == 0) |
| 3964 | return 0; |
| 3965 | |
| 3966 | --ID; |
| 3967 | uint64_t Offset = 0; |
| 3968 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3969 | PerFileData &F = *Chain[N - I - 1]; |
| 3970 | |
| 3971 | if (ID < F.LocalNumCXXBaseSpecifiers) |
| 3972 | return Offset + F.CXXBaseSpecifiersOffsets[ID]; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3973 | |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3974 | ID -= F.LocalNumCXXBaseSpecifiers; |
| 3975 | Offset += F.SizeInBits; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | assert(false && "CXXBaseSpecifiers not found"); |
| 3979 | return 0; |
| 3980 | } |
| 3981 | |
| 3982 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 3983 | // Figure out which AST file contains this offset. |
| 3984 | PerFileData *F = 0; |
| 3985 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3986 | if (Offset < Chain[N - I - 1]->SizeInBits) { |
| 3987 | F = Chain[N - I - 1]; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3988 | break; |
| 3989 | } |
| 3990 | |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3991 | Offset -= Chain[N - I - 1]->SizeInBits; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3992 | } |
Anders Carlsson | f25330b | 2011-03-09 05:09:32 +0000 | [diff] [blame] | 3993 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3994 | if (!F) { |
| 3995 | Error("Malformed AST file: C++ base specifiers at impossible offset"); |
| 3996 | return 0; |
| 3997 | } |
| 3998 | |
| 3999 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 4000 | SavedStreamPosition SavedPosition(Cursor); |
| 4001 | Cursor.JumpToBit(Offset); |
| 4002 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 4003 | RecordData Record; |
| 4004 | unsigned Code = Cursor.ReadCode(); |
| 4005 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 4006 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 4007 | Error("Malformed AST file: missing C++ base specifiers"); |
| 4008 | return 0; |
| 4009 | } |
| 4010 | |
| 4011 | unsigned Idx = 0; |
| 4012 | unsigned NumBases = Record[Idx++]; |
| 4013 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 4014 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 4015 | for (unsigned I = 0; I != NumBases; ++I) |
| 4016 | Bases[I] = ReadCXXBaseSpecifier(*F, Record, Idx); |
| 4017 | return Bases; |
| 4018 | } |
| 4019 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4020 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4021 | if (!DeclsLoaded[0]) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4022 | ReadDeclRecord(0, 1); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4023 | if (DeserializationListener) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 4024 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4025 | } |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 4026 | |
| 4027 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 4028 | } |
| 4029 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4030 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4031 | if (ID == 0) |
| 4032 | return 0; |
| 4033 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4034 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4035 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4036 | return 0; |
| 4037 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4038 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4039 | unsigned Index = ID - 1; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4040 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 4041 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4042 | if (DeserializationListener) |
| 4043 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 4044 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4045 | |
| 4046 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4047 | } |
| 4048 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 4049 | /// \brief Resolve the offset of a statement into a statement. |
| 4050 | /// |
| 4051 | /// This operation will read a new statement from the external |
| 4052 | /// source each time it is called, and is meant to be used via a |
| 4053 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4054 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4055 | // Switch case IDs are per Decl. |
| 4056 | ClearSwitchCaseIDs(); |
| 4057 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4058 | // Offset here is a global offset across the entire chain. |
| 4059 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4060 | PerFileData &F = *Chain[N - I - 1]; |
| 4061 | if (Offset < F.SizeInBits) { |
| 4062 | // Since we know that this statement is part of a decl, make sure to use |
| 4063 | // the decl cursor to read it. |
| 4064 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4065 | return ReadStmtFromStream(F); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4066 | } |
| 4067 | Offset -= F.SizeInBits; |
| 4068 | } |
| 4069 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 4070 | } |
| 4071 | |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4072 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4073 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4074 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4075 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 4076 | // at least. |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 4077 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 4078 | // so make a copy of the vector. |
| 4079 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4080 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 4081 | I != E; ++I) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4082 | // IDs can be 0 if this context doesn't contain declarations. |
| 4083 | if (!I->LexicalDecls) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4084 | continue; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4085 | |
| 4086 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4087 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 4088 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 4089 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 4090 | continue; |
| 4091 | |
| 4092 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 4093 | assert(D && "Null decl in lexical decls"); |
| 4094 | Decls.push_back(D); |
| 4095 | } |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4096 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4097 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4098 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4099 | return ELR_Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4100 | } |
| 4101 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4102 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4103 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4104 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4105 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4106 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4107 | if (!Name) |
| 4108 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 4109 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4110 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4111 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 8b12273 | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 4112 | // 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] | 4113 | // and namespaces. For any given name, the last available results replace |
| 4114 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4115 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 4116 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4117 | I != E; ++I) { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4118 | if (!I->NameLookupTableData) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4119 | continue; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4120 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4121 | ASTDeclContextNameLookupTable *LookupTable = |
| 4122 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 4123 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 4124 | if (Pos == LookupTable->end()) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4125 | continue; |
| 4126 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4127 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 4128 | for (; Data.first != Data.second; ++Data.first) |
| 4129 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 4130 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4131 | } |
| 4132 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4133 | ++NumVisibleDeclContextsRead; |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4134 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4135 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4136 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4137 | } |
| 4138 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 4139 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 4140 | assert(DC->hasExternalVisibleStorage() && |
| 4141 | "DeclContext has no visible decls in storage"); |
| 4142 | |
| 4143 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 4144 | // There might be visible decls in multiple parts of the chain, for the TU |
| 4145 | // and namespaces. |
| 4146 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 4147 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 4148 | I != E; ++I) { |
| 4149 | if (!I->NameLookupTableData) |
| 4150 | continue; |
| 4151 | |
| 4152 | ASTDeclContextNameLookupTable *LookupTable = |
| 4153 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 4154 | for (ASTDeclContextNameLookupTable::item_iterator |
| 4155 | ItemI = LookupTable->item_begin(), |
| 4156 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 4157 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 4158 | = *ItemI; |
| 4159 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 4160 | Decls.clear(); |
| 4161 | for (; Data.first != Data.second; ++Data.first) |
| 4162 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 4163 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 4164 | } |
| 4165 | } |
| 4166 | } |
| 4167 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4168 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4169 | assert(Consumer); |
| 4170 | while (!InterestingDecls.empty()) { |
| 4171 | DeclGroupRef DG(InterestingDecls.front()); |
| 4172 | InterestingDecls.pop_front(); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 4173 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4174 | } |
| 4175 | } |
| 4176 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4177 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 4178 | this->Consumer = Consumer; |
| 4179 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4180 | if (!Consumer) |
| 4181 | return; |
| 4182 | |
| 4183 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4184 | // Force deserialization of this decl, which will cause it to be queued for |
| 4185 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 4186 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4187 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 4188 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4189 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4190 | } |
| 4191 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4192 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4193 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4194 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4195 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4196 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4197 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4198 | unsigned NumDeclsLoaded |
| 4199 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 4200 | (Decl *)0); |
| 4201 | unsigned NumIdentifiersLoaded |
| 4202 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 4203 | IdentifiersLoaded.end(), |
| 4204 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4205 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4206 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 4207 | SelectorsLoaded.end(), |
| 4208 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 4209 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4210 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 4211 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4212 | if (TotalNumSLocEntries) |
| 4213 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 4214 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 4215 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4216 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4217 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4218 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 4219 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 4220 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4221 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4222 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 4223 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4224 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4225 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4226 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4227 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4228 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4229 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4230 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4231 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4232 | if (TotalNumStatements) |
| 4233 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4234 | NumStatementsRead, TotalNumStatements, |
| 4235 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4236 | if (TotalNumMacros) |
| 4237 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4238 | NumMacrosRead, TotalNumMacros, |
| 4239 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4240 | if (TotalLexicalDeclContexts) |
| 4241 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4242 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4243 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4244 | * 100)); |
| 4245 | if (TotalVisibleDeclContexts) |
| 4246 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4247 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4248 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4249 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4250 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4251 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4252 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4253 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4254 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4255 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4256 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4257 | std::fprintf(stderr, "\n"); |
| 4258 | } |
| 4259 | |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4260 | /// Return the amount of memory used by memory buffers, breaking down |
| 4261 | /// by heap-backed versus mmap'ed memory. |
| 4262 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
| 4263 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 4264 | if (llvm::MemoryBuffer *buf = Chain[i]->Buffer.get()) { |
| 4265 | size_t bytes = buf->getBufferSize(); |
| 4266 | switch (buf->getBufferKind()) { |
| 4267 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 4268 | sizes.malloc_bytes += bytes; |
| 4269 | break; |
| 4270 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 4271 | sizes.mmap_bytes += bytes; |
| 4272 | break; |
| 4273 | } |
| 4274 | } |
| 4275 | } |
| 4276 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4277 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4278 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4279 | S.ExternalSource = this; |
| 4280 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4281 | // Makes sure any declarations that were deserialized "too early" |
| 4282 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4283 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4284 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4285 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4286 | |
| 4287 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4288 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4289 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4290 | |
| 4291 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4292 | // them to Sema's list of tentative definitions. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4293 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4294 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4295 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4296 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 4297 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4298 | // If there were any unused file scoped decls, deserialize them and add to |
| 4299 | // Sema's list of unused file scoped decls. |
| 4300 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4301 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4302 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 4303 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4304 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4305 | // If there were any delegating constructors, add them to Sema's list |
| 4306 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 4307 | CXXConstructorDecl *D |
| 4308 | = cast<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 4309 | SemaObj->DelegatingCtorDecls.push_back(D); |
| 4310 | } |
| 4311 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4312 | // If there were any locally-scoped external declarations, |
| 4313 | // deserialize them and add them to Sema's table of locally-scoped |
| 4314 | // external declarations. |
| 4315 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4316 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4317 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 4318 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4319 | |
| 4320 | // If there were any ext_vector type declarations, deserialize them |
| 4321 | // and add them to Sema's vector of such declarations. |
| 4322 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 4323 | SemaObj->ExtVectorDecls.push_back( |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4324 | cast<TypedefNameDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4325 | |
| 4326 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 4327 | // Can we cut them down before writing them ? |
| 4328 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4329 | // If there were any dynamic classes declarations, deserialize them |
| 4330 | // and add them to Sema's vector of such declarations. |
| 4331 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 4332 | SemaObj->DynamicClasses.push_back( |
| 4333 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4334 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4335 | // Load the offsets of the declarations that Sema references. |
| 4336 | // They will be lazily deserialized when needed. |
| 4337 | if (!SemaDeclRefs.empty()) { |
| 4338 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 4339 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4340 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 4341 | } |
| 4342 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4343 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 4344 | |
| 4345 | // If there are @selector references added them to its pool. This is for |
| 4346 | // implementation of -Wselector. |
| 4347 | if (!F->ReferencedSelectorsData.empty()) { |
| 4348 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 4349 | unsigned I = 0; |
| 4350 | while (I < DataSize) { |
| 4351 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 4352 | SourceLocation SelLoc = ReadSourceLocation( |
| 4353 | *F, F->ReferencedSelectorsData, I); |
| 4354 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 4355 | } |
| 4356 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4357 | } |
| 4358 | |
Sebastian Redl | c1d3ffb | 2011-04-24 16:27:30 +0000 | [diff] [blame] | 4359 | // The special data sets below always come from the most recent PCH, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4360 | // which is at the front of the chain. |
| 4361 | PerFileData &F = *Chain.front(); |
| 4362 | |
Sebastian Redl | c1d3ffb | 2011-04-24 16:27:30 +0000 | [diff] [blame] | 4363 | // If there were any pending implicit instantiations, deserialize them |
| 4364 | // and add them to Sema's queue of such instantiations. |
| 4365 | assert(F.PendingInstantiations.size() % 2 == 0 && |
| 4366 | "Expected pairs of entries"); |
| 4367 | for (unsigned Idx = 0, N = F.PendingInstantiations.size(); Idx < N;) { |
| 4368 | ValueDecl *D=cast<ValueDecl>(GetDecl(F.PendingInstantiations[Idx++])); |
| 4369 | SourceLocation Loc = ReadSourceLocation(F, F.PendingInstantiations,Idx); |
| 4370 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 4371 | } |
| 4372 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4373 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 4374 | // Sema's list of weak undeclared identifiers. |
| 4375 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 4376 | unsigned Idx = 0; |
| 4377 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 4378 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4379 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 4380 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 4381 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 4382 | Sema::WeakInfo WI(AliasId, Loc); |
| 4383 | WI.setUsed(Used); |
| 4384 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 4385 | } |
| 4386 | } |
| 4387 | |
| 4388 | // If there were any VTable uses, deserialize the information and add it |
| 4389 | // to Sema's vector and map of VTable uses. |
| 4390 | if (!VTableUses.empty()) { |
| 4391 | unsigned Idx = 0; |
| 4392 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 4393 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4394 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 4395 | bool DefinitionRequired = VTableUses[Idx++]; |
| 4396 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 4397 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4398 | } |
| 4399 | } |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4400 | |
| 4401 | if (!FPPragmaOptions.empty()) { |
| 4402 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4403 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4404 | } |
| 4405 | |
| 4406 | if (!OpenCLExtensions.empty()) { |
| 4407 | unsigned I = 0; |
| 4408 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4409 | #include "clang/Basic/OpenCLExtensions.def" |
| 4410 | |
| 4411 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4412 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4413 | } |
| 4414 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4415 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4416 | // Try to find this name within our on-disk hash tables. We start with the |
| 4417 | // 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] | 4418 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4419 | ASTIdentifierLookupTable *IdTable |
| 4420 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4421 | if (!IdTable) |
| 4422 | continue; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4423 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4424 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4425 | if (Pos == IdTable->end()) |
| 4426 | continue; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4427 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4428 | // Dereferencing the iterator has the effect of building the |
| 4429 | // IdentifierInfo node and populating it with the various |
| 4430 | // declarations it needs. |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4431 | return *Pos; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 4432 | } |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 4433 | return 0; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4434 | } |
| 4435 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4436 | namespace clang { |
| 4437 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4438 | /// identifiers stored within a set of AST files. |
| 4439 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4440 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4441 | const ASTReader &Reader; |
| 4442 | |
| 4443 | /// \brief The current index into the chain of AST files stored in |
| 4444 | /// the AST reader. |
| 4445 | unsigned Index; |
| 4446 | |
| 4447 | /// \brief The current position within the identifier lookup table |
| 4448 | /// of the current AST file. |
| 4449 | ASTIdentifierLookupTable::key_iterator Current; |
| 4450 | |
| 4451 | /// \brief The end position within the identifier lookup table of |
| 4452 | /// the current AST file. |
| 4453 | ASTIdentifierLookupTable::key_iterator End; |
| 4454 | |
| 4455 | public: |
| 4456 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4457 | |
| 4458 | virtual llvm::StringRef Next(); |
| 4459 | }; |
| 4460 | } |
| 4461 | |
| 4462 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 4463 | : Reader(Reader), Index(Reader.Chain.size() - 1) { |
| 4464 | ASTIdentifierLookupTable *IdTable |
| 4465 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4466 | Current = IdTable->key_begin(); |
| 4467 | End = IdTable->key_end(); |
| 4468 | } |
| 4469 | |
| 4470 | llvm::StringRef ASTIdentifierIterator::Next() { |
| 4471 | while (Current == End) { |
| 4472 | // If we have exhausted all of our AST files, we're done. |
| 4473 | if (Index == 0) |
| 4474 | return llvm::StringRef(); |
| 4475 | |
| 4476 | --Index; |
| 4477 | ASTIdentifierLookupTable *IdTable |
| 4478 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 4479 | Current = IdTable->key_begin(); |
| 4480 | End = IdTable->key_end(); |
| 4481 | } |
| 4482 | |
| 4483 | // We have any identifiers remaining in the current AST file; return |
| 4484 | // the next one. |
| 4485 | std::pair<const char*, unsigned> Key = *Current; |
| 4486 | ++Current; |
| 4487 | return llvm::StringRef(Key.first, Key.second); |
| 4488 | } |
| 4489 | |
| 4490 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4491 | return new ASTIdentifierIterator(*this); |
| 4492 | } |
| 4493 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4494 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4495 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4496 | // Find this selector in a hash table. We want to find the most recent entry. |
| 4497 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4498 | PerFileData &F = *Chain[I]; |
| 4499 | if (!F.SelectorLookupTable) |
| 4500 | continue; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4501 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4502 | ASTSelectorLookupTable *PoolTable |
| 4503 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 4504 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4505 | if (Pos != PoolTable->end()) { |
| 4506 | ++NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4507 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4508 | // disable this tracking when called via LoadSelector. |
| 4509 | // Also, should entries without methods count as misses? |
| 4510 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4511 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4512 | if (DeserializationListener) |
| 4513 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 4514 | return std::make_pair(Data.Instance, Data.Factory); |
| 4515 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4516 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4517 | |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4518 | ++NumMethodPoolMisses; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4519 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4520 | } |
| 4521 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4522 | void ASTReader::ReadKnownNamespaces( |
| 4523 | llvm::SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
| 4524 | Namespaces.clear(); |
| 4525 | |
| 4526 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 4527 | if (NamespaceDecl *Namespace |
| 4528 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 4529 | Namespaces.push_back(Namespace); |
| 4530 | } |
| 4531 | } |
| 4532 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4533 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4534 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4535 | ReadMethodPool(Sel); |
| 4536 | } |
| 4537 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4538 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4539 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4540 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4541 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4542 | if (DeserializationListener) |
| 4543 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4544 | } |
| 4545 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4546 | /// \brief Set the globally-visible declarations associated with the given |
| 4547 | /// identifier. |
| 4548 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4549 | /// 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] | 4550 | /// 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] | 4551 | /// them. |
| 4552 | /// |
| 4553 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4554 | /// declarations. |
| 4555 | /// |
| 4556 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4557 | /// visible at global scope. |
| 4558 | /// |
| 4559 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4560 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4561 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4562 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4563 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4564 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 4565 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4566 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4567 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4568 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4569 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4570 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4571 | return; |
| 4572 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4573 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4574 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4575 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4576 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4577 | if (SemaObj->TUScope) { |
| 4578 | // Introduce this declaration into the translation-unit scope |
| 4579 | // and add it to the declaration chain for this identifier, so |
| 4580 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4581 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4582 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4583 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4584 | } else { |
| 4585 | // Queue this declaration so that it will be added to the |
| 4586 | // translation unit scope and identifier's declaration chain |
| 4587 | // once a Sema object is known. |
| 4588 | PreloadedDecls.push_back(D); |
| 4589 | } |
| 4590 | } |
| 4591 | } |
| 4592 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4593 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4594 | if (ID == 0) |
| 4595 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4596 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4597 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4598 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4599 | return 0; |
| 4600 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4601 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4602 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4603 | ID -= 1; |
| 4604 | if (!IdentifiersLoaded[ID]) { |
| 4605 | unsigned Index = ID; |
| 4606 | const char *Str = 0; |
| 4607 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4608 | PerFileData *F = Chain[N - I - 1]; |
| 4609 | if (Index < F->LocalNumIdentifiers) { |
| 4610 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 4611 | Str = F->IdentifierTableData + Offset; |
| 4612 | break; |
| 4613 | } |
| 4614 | Index -= F->LocalNumIdentifiers; |
| 4615 | } |
| 4616 | assert(Str && "Broken Chain"); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4617 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4618 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4619 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4620 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4621 | // unsigned integers. This is important to avoid integer overflow when |
| 4622 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4623 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4624 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4625 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4626 | IdentifiersLoaded[ID] |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 4627 | = &PP->getIdentifierTable().get(llvm::StringRef(Str, StrLen)); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4628 | if (DeserializationListener) |
| 4629 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4630 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4631 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4632 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4633 | } |
| 4634 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4635 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | e23ac65 | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 4636 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4637 | } |
| 4638 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4639 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4640 | if (ID == 0) |
| 4641 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4642 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4643 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4644 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4645 | return Selector(); |
| 4646 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4647 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4648 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4649 | // Load this selector from the selector table. |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4650 | unsigned Idx = ID - 1; |
| 4651 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4652 | PerFileData &F = *Chain[N - I - 1]; |
| 4653 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4654 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4655 | SelectorsLoaded[ID - 1] = |
| 4656 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 4657 | if (DeserializationListener) |
| 4658 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 4659 | break; |
| 4660 | } |
| 4661 | Idx -= F.LocalNumSelectors; |
| 4662 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4663 | } |
| 4664 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4665 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4666 | } |
| 4667 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4668 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4669 | return DecodeSelector(ID); |
| 4670 | } |
| 4671 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4672 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4673 | // ID 0 (the null selector) is considered an external selector. |
| 4674 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4675 | } |
| 4676 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4677 | DeclarationName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4678 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4679 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4680 | switch (Kind) { |
| 4681 | case DeclarationName::Identifier: |
| 4682 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 4683 | |
| 4684 | case DeclarationName::ObjCZeroArgSelector: |
| 4685 | case DeclarationName::ObjCOneArgSelector: |
| 4686 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 4687 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4688 | |
| 4689 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4690 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4691 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4692 | |
| 4693 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4694 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4695 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4696 | |
| 4697 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4698 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4699 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4700 | |
| 4701 | case DeclarationName::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4702 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4703 | (OverloadedOperatorKind)Record[Idx++]); |
| 4704 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4705 | case DeclarationName::CXXLiteralOperatorName: |
| 4706 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 4707 | GetIdentifierInfo(Record, Idx)); |
| 4708 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4709 | case DeclarationName::CXXUsingDirective: |
| 4710 | return DeclarationName::getUsingDirectiveName(); |
| 4711 | } |
| 4712 | |
| 4713 | // Required to silence GCC warning |
| 4714 | return DeclarationName(); |
| 4715 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4716 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4717 | void ASTReader::ReadDeclarationNameLoc(PerFileData &F, |
| 4718 | DeclarationNameLoc &DNLoc, |
| 4719 | DeclarationName Name, |
| 4720 | const RecordData &Record, unsigned &Idx) { |
| 4721 | switch (Name.getNameKind()) { |
| 4722 | case DeclarationName::CXXConstructorName: |
| 4723 | case DeclarationName::CXXDestructorName: |
| 4724 | case DeclarationName::CXXConversionFunctionName: |
| 4725 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4726 | break; |
| 4727 | |
| 4728 | case DeclarationName::CXXOperatorName: |
| 4729 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4730 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4731 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4732 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4733 | break; |
| 4734 | |
| 4735 | case DeclarationName::CXXLiteralOperatorName: |
| 4736 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4737 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4738 | break; |
| 4739 | |
| 4740 | case DeclarationName::Identifier: |
| 4741 | case DeclarationName::ObjCZeroArgSelector: |
| 4742 | case DeclarationName::ObjCOneArgSelector: |
| 4743 | case DeclarationName::ObjCMultiArgSelector: |
| 4744 | case DeclarationName::CXXUsingDirective: |
| 4745 | break; |
| 4746 | } |
| 4747 | } |
| 4748 | |
| 4749 | void ASTReader::ReadDeclarationNameInfo(PerFileData &F, |
| 4750 | DeclarationNameInfo &NameInfo, |
| 4751 | const RecordData &Record, unsigned &Idx) { |
| 4752 | NameInfo.setName(ReadDeclarationName(Record, Idx)); |
| 4753 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4754 | DeclarationNameLoc DNLoc; |
| 4755 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4756 | NameInfo.setInfo(DNLoc); |
| 4757 | } |
| 4758 | |
| 4759 | void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info, |
| 4760 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4761 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4762 | unsigned NumTPLists = Record[Idx++]; |
| 4763 | Info.NumTemplParamLists = NumTPLists; |
| 4764 | if (NumTPLists) { |
| 4765 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 4766 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4767 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4768 | } |
| 4769 | } |
| 4770 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4771 | TemplateName |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4772 | ASTReader::ReadTemplateName(PerFileData &F, const RecordData &Record, |
| 4773 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4774 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4775 | switch (Kind) { |
| 4776 | case TemplateName::Template: |
| 4777 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 4778 | |
| 4779 | case TemplateName::OverloadedTemplate: { |
| 4780 | unsigned size = Record[Idx++]; |
| 4781 | UnresolvedSet<8> Decls; |
| 4782 | while (size--) |
| 4783 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 4784 | |
| 4785 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 4786 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4787 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4788 | case TemplateName::QualifiedTemplate: { |
| 4789 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4790 | bool hasTemplKeyword = Record[Idx++]; |
| 4791 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 4792 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 4793 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4794 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4795 | case TemplateName::DependentTemplate: { |
| 4796 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4797 | if (Record[Idx++]) // isIdentifier |
| 4798 | return Context->getDependentTemplateName(NNS, |
| 4799 | GetIdentifierInfo(Record, Idx)); |
| 4800 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4801 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4802 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 4803 | |
| 4804 | case TemplateName::SubstTemplateTemplateParm: { |
| 4805 | TemplateTemplateParmDecl *param |
| 4806 | = cast_or_null<TemplateTemplateParmDecl>(GetDecl(Record[Idx++])); |
| 4807 | if (!param) return TemplateName(); |
| 4808 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
| 4809 | return Context->getSubstTemplateTemplateParm(param, replacement); |
| 4810 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4811 | |
| 4812 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4813 | TemplateTemplateParmDecl *Param |
| 4814 | = cast_or_null<TemplateTemplateParmDecl>(GetDecl(Record[Idx++])); |
| 4815 | if (!Param) |
| 4816 | return TemplateName(); |
| 4817 | |
| 4818 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 4819 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 4820 | return TemplateName(); |
| 4821 | |
| 4822 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 4823 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4824 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4825 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4826 | assert(0 && "Unhandled template name kind!"); |
| 4827 | return TemplateName(); |
| 4828 | } |
| 4829 | |
| 4830 | TemplateArgument |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4831 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4832 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4833 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 4834 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4835 | case TemplateArgument::Null: |
| 4836 | return TemplateArgument(); |
| 4837 | case TemplateArgument::Type: |
| 4838 | return TemplateArgument(GetType(Record[Idx++])); |
| 4839 | case TemplateArgument::Declaration: |
| 4840 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4841 | case TemplateArgument::Integral: { |
| 4842 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 4843 | QualType T = GetType(Record[Idx++]); |
| 4844 | return TemplateArgument(Value, T); |
| 4845 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4846 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4847 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4848 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4849 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4850 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 4851 | if (unsigned NumExpansions = Record[Idx++]) |
| 4852 | NumTemplateExpansions = NumExpansions - 1; |
| 4853 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4854 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4855 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4856 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4857 | case TemplateArgument::Pack: { |
| 4858 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4859 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 4860 | for (unsigned I = 0; I != NumArgs; ++I) |
| 4861 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 4862 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4863 | } |
| 4864 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4865 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4866 | assert(0 && "Unhandled template argument kind!"); |
| 4867 | return TemplateArgument(); |
| 4868 | } |
| 4869 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4870 | TemplateParameterList * |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4871 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 4872 | const RecordData &Record, unsigned &Idx) { |
| 4873 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 4874 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 4875 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4876 | |
| 4877 | unsigned NumParams = Record[Idx++]; |
| 4878 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 4879 | Params.reserve(NumParams); |
| 4880 | while (NumParams--) |
| 4881 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4882 | |
| 4883 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4884 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 4885 | Params.data(), Params.size(), RAngleLoc); |
| 4886 | return TemplateParams; |
| 4887 | } |
| 4888 | |
| 4889 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4890 | ASTReader:: |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4891 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4892 | PerFileData &F, const RecordData &Record, |
| 4893 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4894 | unsigned NumTemplateArgs = Record[Idx++]; |
| 4895 | TemplArgs.reserve(NumTemplateArgs); |
| 4896 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4897 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4898 | } |
| 4899 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4900 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4901 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4902 | const RecordData &Record, unsigned &Idx) { |
| 4903 | unsigned NumDecls = Record[Idx++]; |
| 4904 | while (NumDecls--) { |
| 4905 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 4906 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 4907 | Set.addDecl(D, AS); |
| 4908 | } |
| 4909 | } |
| 4910 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4911 | CXXBaseSpecifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4912 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4913 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4914 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 4915 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 4916 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4917 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4918 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4919 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4920 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4921 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4922 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4923 | Result.setInheritConstructors(inheritConstructors); |
| 4924 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4925 | } |
| 4926 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4927 | std::pair<CXXCtorInitializer **, unsigned> |
| 4928 | ASTReader::ReadCXXCtorInitializers(PerFileData &F, const RecordData &Record, |
| 4929 | unsigned &Idx) { |
| 4930 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4931 | unsigned NumInitializers = Record[Idx++]; |
| 4932 | if (NumInitializers) { |
| 4933 | ASTContext &C = *getContext(); |
| 4934 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4935 | CtorInitializers |
| 4936 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4937 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 4938 | TypeSourceInfo *BaseClassInfo = 0; |
| 4939 | bool IsBaseVirtual = false; |
| 4940 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4941 | IndirectFieldDecl *IndirectMember = 0; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4942 | CXXConstructorDecl *Target = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4943 | |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4944 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 4945 | switch (Type) { |
| 4946 | case CTOR_INITIALIZER_BASE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4947 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4948 | IsBaseVirtual = Record[Idx++]; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4949 | break; |
| 4950 | |
| 4951 | case CTOR_INITIALIZER_DELEGATING: |
| 4952 | Target = cast<CXXConstructorDecl>(GetDecl(Record[Idx++])); |
| 4953 | break; |
| 4954 | |
| 4955 | case CTOR_INITIALIZER_MEMBER: |
| 4956 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
| 4957 | break; |
| 4958 | |
| 4959 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
| 4960 | IndirectMember = cast<IndirectFieldDecl>(GetDecl(Record[Idx++])); |
| 4961 | break; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4962 | } |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4963 | |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 4964 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4965 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4966 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 4967 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4968 | bool IsWritten = Record[Idx++]; |
| 4969 | unsigned SourceOrderOrNumArrayIndices; |
| 4970 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 4971 | if (IsWritten) { |
| 4972 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4973 | } else { |
| 4974 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4975 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 4976 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 4977 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 4978 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4979 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4980 | CXXCtorInitializer *BOMInit; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4981 | if (Type == CTOR_INITIALIZER_BASE) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4982 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 4983 | LParenLoc, Init, RParenLoc, |
| 4984 | MemberOrEllipsisLoc); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4985 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
| 4986 | BOMInit = new (C) CXXCtorInitializer(C, MemberOrEllipsisLoc, LParenLoc, |
| 4987 | Target, Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4988 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4989 | if (Member) |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4990 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 4991 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4992 | else |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4993 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 4994 | MemberOrEllipsisLoc, LParenLoc, |
| 4995 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4996 | } else { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4997 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 4998 | LParenLoc, Init, RParenLoc, |
| 4999 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5000 | } |
| 5001 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 5002 | if (IsWritten) |
| 5003 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5004 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5005 | } |
| 5006 | } |
| 5007 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5008 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5009 | } |
| 5010 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5011 | NestedNameSpecifier * |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5012 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5013 | unsigned N = Record[Idx++]; |
| 5014 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 5015 | for (unsigned I = 0; I != N; ++I) { |
| 5016 | NestedNameSpecifier::SpecifierKind Kind |
| 5017 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5018 | switch (Kind) { |
| 5019 | case NestedNameSpecifier::Identifier: { |
| 5020 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 5021 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 5022 | break; |
| 5023 | } |
| 5024 | |
| 5025 | case NestedNameSpecifier::Namespace: { |
| 5026 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 5027 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 5028 | break; |
| 5029 | } |
| 5030 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5031 | case NestedNameSpecifier::NamespaceAlias: { |
| 5032 | NamespaceAliasDecl *Alias |
| 5033 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
| 5034 | NNS = NestedNameSpecifier::Create(*Context, Prev, Alias); |
| 5035 | break; |
| 5036 | } |
| 5037 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5038 | case NestedNameSpecifier::TypeSpec: |
| 5039 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5040 | const Type *T = GetType(Record[Idx++]).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 5041 | if (!T) |
| 5042 | return 0; |
| 5043 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5044 | bool Template = Record[Idx++]; |
| 5045 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 5046 | break; |
| 5047 | } |
| 5048 | |
| 5049 | case NestedNameSpecifier::Global: { |
| 5050 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 5051 | // No associated value, and there can't be a prefix. |
| 5052 | break; |
| 5053 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5054 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 5055 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5056 | } |
| 5057 | return NNS; |
| 5058 | } |
| 5059 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5060 | NestedNameSpecifierLoc |
| 5061 | ASTReader::ReadNestedNameSpecifierLoc(PerFileData &F, const RecordData &Record, |
| 5062 | unsigned &Idx) { |
| 5063 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5064 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5065 | for (unsigned I = 0; I != N; ++I) { |
| 5066 | NestedNameSpecifier::SpecifierKind Kind |
| 5067 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5068 | switch (Kind) { |
| 5069 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5070 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5071 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5072 | Builder.Extend(*Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5073 | break; |
| 5074 | } |
| 5075 | |
| 5076 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5077 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5078 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5079 | Builder.Extend(*Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5080 | break; |
| 5081 | } |
| 5082 | |
| 5083 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5084 | NamespaceAliasDecl *Alias |
| 5085 | = cast<NamespaceAliasDecl>(GetDecl(Record[Idx++])); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5086 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5087 | Builder.Extend(*Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5088 | break; |
| 5089 | } |
| 5090 | |
| 5091 | case NestedNameSpecifier::TypeSpec: |
| 5092 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5093 | bool Template = Record[Idx++]; |
| 5094 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 5095 | if (!T) |
| 5096 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5097 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5098 | |
| 5099 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
| 5100 | Builder.Extend(*Context, |
| 5101 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 5102 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5103 | break; |
| 5104 | } |
| 5105 | |
| 5106 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5107 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5108 | Builder.MakeGlobal(*Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5109 | break; |
| 5110 | } |
| 5111 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5112 | } |
| 5113 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5114 | return Builder.getWithLocInContext(*Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5115 | } |
| 5116 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5117 | SourceRange |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5118 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 5119 | unsigned &Idx) { |
| 5120 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 5121 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 5122 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5123 | } |
| 5124 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5125 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5126 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5127 | unsigned BitWidth = Record[Idx++]; |
| 5128 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 5129 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 5130 | Idx += NumWords; |
| 5131 | return Result; |
| 5132 | } |
| 5133 | |
| 5134 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5135 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5136 | bool isUnsigned = Record[Idx++]; |
| 5137 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 5138 | } |
| 5139 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5140 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5141 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5142 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 5143 | } |
| 5144 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5145 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5146 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5147 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 5148 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5149 | Idx += Len; |
| 5150 | return Result; |
| 5151 | } |
| 5152 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 5153 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 5154 | unsigned &Idx) { |
| 5155 | unsigned Major = Record[Idx++]; |
| 5156 | unsigned Minor = Record[Idx++]; |
| 5157 | unsigned Subminor = Record[Idx++]; |
| 5158 | if (Minor == 0) |
| 5159 | return VersionTuple(Major); |
| 5160 | if (Subminor == 0) |
| 5161 | return VersionTuple(Major, Minor - 1); |
| 5162 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 5163 | } |
| 5164 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5165 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5166 | unsigned &Idx) { |
| 5167 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 5168 | return CXXTemporary::Create(*Context, Decl); |
| 5169 | } |
| 5170 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5171 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 5172 | return Diag(SourceLocation(), DiagID); |
| 5173 | } |
| 5174 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5175 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5176 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5177 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5178 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5179 | /// \brief Retrieve the identifier table associated with the |
| 5180 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5181 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 5182 | assert(PP && "Forgot to set Preprocessor ?"); |
| 5183 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5184 | } |
| 5185 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5186 | /// \brief Record that the given ID maps to the given switch-case |
| 5187 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5188 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5189 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 5190 | SwitchCaseStmts[ID] = SC; |
| 5191 | } |
| 5192 | |
| 5193 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5194 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5195 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 5196 | return SwitchCaseStmts[ID]; |
| 5197 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 5198 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 5199 | void ASTReader::ClearSwitchCaseIDs() { |
| 5200 | SwitchCaseStmts.clear(); |
| 5201 | } |
| 5202 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5203 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5204 | assert(NumCurrentElementsDeserializing && |
| 5205 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 5206 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5207 | // If any identifiers with corresponding top-level declarations have |
| 5208 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5209 | while (!PendingIdentifierInfos.empty()) { |
| 5210 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 5211 | PendingIdentifierInfos.front().DeclIDs, true); |
| 5212 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5213 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5214 | |
Argyrios Kyrtzidis | 0895d15 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 5215 | // Ready to load previous declarations of Decls that were delayed. |
| 5216 | while (!PendingPreviousDecls.empty()) { |
| 5217 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 5218 | PendingPreviousDecls.front().second); |
| 5219 | PendingPreviousDecls.pop_front(); |
| 5220 | } |
| 5221 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5222 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 5223 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5224 | if (Consumer) |
| 5225 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 5226 | |
| 5227 | assert(PendingForwardRefs.size() == 0 && |
| 5228 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5229 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5230 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5231 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5232 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5233 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5234 | const char *isysroot, bool DisableValidation, |
| 5235 | bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5236 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 5237 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 5238 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5239 | Consumer(0), FirstInSource(0), RelocatablePCH(false), isysroot(isysroot), |
| 5240 | DisableValidation(DisableValidation), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5241 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5242 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5243 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 5244 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 5245 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 5246 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
| 5247 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 5248 | NumCurrentElementsDeserializing(0) |
| 5249 | { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5250 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5251 | } |
| 5252 | |
| 5253 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 5254 | Diagnostic &Diags, const char *isysroot, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5255 | bool DisableValidation, bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5256 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5257 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), FirstInSource(0), |
| 5258 | RelocatablePCH(false), isysroot(isysroot), |
| 5259 | DisableValidation(DisableValidation), DisableStatCache(DisableStatCache), |
| 5260 | NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), |
| 5261 | TotalNumSLocEntries(0), NumStatementsRead(0), |
| 5262 | TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), |
| 5263 | NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 5264 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 5265 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5266 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) |
| 5267 | { |
| 5268 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5269 | } |
| 5270 | |
| 5271 | ASTReader::~ASTReader() { |
| 5272 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 5273 | delete Chain[e - i - 1]; |
| 5274 | // Delete all visible decl lookup tables |
| 5275 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 5276 | E = DeclContextOffsets.end(); |
| 5277 | I != E; ++I) { |
| 5278 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 5279 | J != F; ++J) { |
| 5280 | if (J->NameLookupTableData) |
| 5281 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 5282 | J->NameLookupTableData); |
| 5283 | } |
| 5284 | } |
| 5285 | for (DeclContextVisibleUpdatesPending::iterator |
| 5286 | I = PendingVisibleUpdates.begin(), |
| 5287 | E = PendingVisibleUpdates.end(); |
| 5288 | I != E; ++I) { |
| 5289 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5290 | F = I->second.end(); |
| 5291 | J != F; ++J) |
| 5292 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 5293 | } |
| 5294 | } |
| 5295 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 5296 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5297 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocEntryBaseID(0), |
| 5298 | SLocEntryBaseOffset(0), SLocEntryOffsets(0), |
| 5299 | SLocFileOffsets(0), LocalNumIdentifiers(0), |
| 5300 | IdentifierOffsets(0), IdentifierTableData(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5301 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5302 | MacroDefinitionOffsets(0), LocalNumHeaderFileInfos(0), |
| 5303 | HeaderFileInfoTableData(0), HeaderFileInfoTable(0), |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5304 | LocalNumSelectors(0), SelectorOffsets(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5305 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5306 | DeclOffsets(0), LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
| 5307 | LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 5308 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5309 | {} |
| 5310 | |
| 5311 | ASTReader::PerFileData::~PerFileData() { |
| 5312 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5313 | delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5314 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 5315 | } |