Sebastian Redl | 904c9c8 | 2010-08-18 23:57:11 +0000 | [diff] [blame] | 1 | //===--- ASTReader.cpp - AST File Reader ------------------------*- C++ -*-===// |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 10 | // This file defines the ASTReader class, which reads AST files. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 13 | |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTReader.h" |
| 15 | #include "clang/Serialization/ASTDeserializationListener.h" |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 16 | #include "ASTCommon.h" |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 17 | #include "clang/Frontend/FrontendDiagnostic.h" |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/Utils.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 19 | #include "clang/Sema/Sema.h" |
John McCall | 5f1e094 | 2010-08-24 08:50:51 +0000 | [diff] [blame] | 20 | #include "clang/Sema/Scope.h" |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 21 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 22 | #include "clang/AST/ASTContext.h" |
John McCall | 2a7fb27 | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 24 | #include "clang/AST/Expr.h" |
John McCall | 7a1fad3 | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 26 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 27 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 28 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 29 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 30 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 31 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 32 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 33 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 34 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 35 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 36 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 37 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 38 | #include "clang/Basic/Version.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 39 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 40 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 41 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 42 | #include "llvm/Support/ErrorHandling.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame^] | 43 | #include "llvm/Support/Path.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 44 | #include <algorithm> |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 45 | #include <iterator> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 46 | #include <cstdio> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 47 | #include <sys/stat.h> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 48 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 49 | using namespace clang::serialization; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 50 | |
| 51 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 52 | // PCH validator implementation |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 53 | //===----------------------------------------------------------------------===// |
| 54 | |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 55 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 56 | |
| 57 | bool |
| 58 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 59 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 60 | #define PARSE_LANGOPT_BENIGN(Option) |
| 61 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 62 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 63 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 64 | return true; \ |
| 65 | } |
| 66 | |
| 67 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 68 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 69 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 70 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 71 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 72 | PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 73 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 74 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 75 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 76 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
| 77 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 78 | PARSE_LANGOPT_BENIGN(MSCVersion); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 79 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 80 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 81 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 82 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 83 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 84 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 85 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 86 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 87 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 88 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 89 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 91 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 92 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 93 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 94 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 95 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 96 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 97 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 98 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 99 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 100 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 101 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 102 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 103 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 104 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 105 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 106 | diag::warn_pch_heinous_extensions); |
| 107 | // FIXME: Most of the options below are benign if the macro wasn't |
| 108 | // used. Unfortunately, this means that a PCH compiled without |
| 109 | // optimization can't be used with optimization turned on, even |
| 110 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 111 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 112 | // doesn't matter. We could consider making this some special kind |
| 113 | // of check. |
| 114 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 115 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 116 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 117 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 118 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 119 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
| 120 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 121 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 122 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 123 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 124 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 126 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 127 | return true; |
| 128 | } |
| 129 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 130 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 131 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 132 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 133 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 134 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 135 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 136 | PARSE_LANGOPT_BENIGN(SpellChecking); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 137 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 138 | #undef PARSE_LANGOPT_BENIGN |
| 139 | |
| 140 | return false; |
| 141 | } |
| 142 | |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 143 | bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) { |
| 144 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 145 | return false; |
| 146 | |
| 147 | Reader.Diag(diag::warn_pch_target_triple) |
| 148 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 149 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 152 | namespace { |
| 153 | struct EmptyStringRef { |
| 154 | bool operator ()(llvm::StringRef r) const { return r.empty(); } |
| 155 | }; |
| 156 | struct EmptyBlock { |
| 157 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 158 | }; |
| 159 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 160 | |
| 161 | static bool EqualConcatenations(llvm::SmallVector<llvm::StringRef, 2> L, |
| 162 | PCHPredefinesBlocks R) { |
| 163 | // First, sum up the lengths. |
| 164 | unsigned LL = 0, RL = 0; |
| 165 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 166 | LL += L[I].size(); |
| 167 | } |
| 168 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 169 | RL += R[I].Data.size(); |
| 170 | } |
| 171 | if (LL != RL) |
| 172 | return false; |
| 173 | if (LL == 0 && RL == 0) |
| 174 | return true; |
| 175 | |
| 176 | // Kick out empty parts, they confuse the algorithm below. |
| 177 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 178 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 179 | |
| 180 | // Do it the hard way. At this point, both vectors must be non-empty. |
| 181 | llvm::StringRef LR = L[0], RR = R[0].Data; |
| 182 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 183 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 184 | for (;;) { |
| 185 | // Compare the current pieces. |
| 186 | if (LR.size() == RR.size()) { |
| 187 | // If they're the same length, it's pretty easy. |
| 188 | if (LR != RR) |
| 189 | return false; |
| 190 | // Both pieces are done, advance. |
| 191 | ++LI; |
| 192 | ++RI; |
| 193 | // If either string is done, they're both done, since they're the same |
| 194 | // length. |
| 195 | if (LI == LN) { |
| 196 | assert(RI == RN && "Strings not the same length after all?"); |
| 197 | return true; |
| 198 | } |
| 199 | LR = L[LI]; |
| 200 | RR = R[RI].Data; |
| 201 | } else if (LR.size() < RR.size()) { |
| 202 | // Right piece is longer. |
| 203 | if (!RR.startswith(LR)) |
| 204 | return false; |
| 205 | ++LI; |
| 206 | assert(LI != LN && "Strings not the same length after all?"); |
| 207 | RR = RR.substr(LR.size()); |
| 208 | LR = L[LI]; |
| 209 | } else { |
| 210 | // Left piece is longer. |
| 211 | if (!LR.startswith(RR)) |
| 212 | return false; |
| 213 | ++RI; |
| 214 | assert(RI != RN && "Strings not the same length after all?"); |
| 215 | LR = LR.substr(RR.size()); |
| 216 | RR = R[RI].Data; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | static std::pair<FileID, llvm::StringRef::size_type> |
| 222 | FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) { |
| 223 | std::pair<FileID, llvm::StringRef::size_type> Res; |
| 224 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 225 | Res.second = Buffers[I].Data.find(MacroDef); |
| 226 | if (Res.second != llvm::StringRef::npos) { |
| 227 | Res.first = Buffers[I].BufferID; |
| 228 | break; |
| 229 | } |
| 230 | } |
| 231 | return Res; |
| 232 | } |
| 233 | |
| 234 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 235 | llvm::StringRef OriginalFileName, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 236 | std::string &SuggestedPredefines) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 237 | // We are in the context of an implicit include, so the predefines buffer will |
| 238 | // have a #include entry for the PCH file itself (as normalized by the |
| 239 | // preprocessor initialization). Find it and skip over it in the checking |
| 240 | // below. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 241 | llvm::SmallString<256> PCHInclude; |
| 242 | PCHInclude += "#include \""; |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 243 | PCHInclude += NormalizeDashIncludePath(OriginalFileName); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 244 | PCHInclude += "\"\n"; |
| 245 | std::pair<llvm::StringRef,llvm::StringRef> Split = |
| 246 | llvm::StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 247 | llvm::StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 248 | if (Left == PP.getPredefines()) { |
| 249 | Error("Missing PCH include entry!"); |
| 250 | return true; |
| 251 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 252 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 253 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 254 | // command line, we're done. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 255 | llvm::SmallVector<llvm::StringRef, 2> CommandLine; |
| 256 | CommandLine.push_back(Left); |
| 257 | CommandLine.push_back(Right); |
| 258 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 259 | return false; |
| 260 | |
| 261 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 262 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 263 | // The predefines buffers are different. Determine what the differences are, |
| 264 | // and whether they require us to reject the PCH file. |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 265 | llvm::SmallVector<llvm::StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 266 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 267 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 268 | |
| 269 | llvm::SmallVector<llvm::StringRef, 8> CmdLineLines; |
| 270 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 271 | |
| 272 | // Pick out implicit #includes after the PCH and don't consider them for |
| 273 | // validation; we will insert them into SuggestedPredefines so that the |
| 274 | // preprocessor includes them. |
| 275 | std::string IncludesAfterPCH; |
| 276 | llvm::SmallVector<llvm::StringRef, 8> AfterPCHLines; |
| 277 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 278 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 279 | if (AfterPCHLines[i].startswith("#include ")) { |
| 280 | IncludesAfterPCH += AfterPCHLines[i]; |
| 281 | IncludesAfterPCH += '\n'; |
| 282 | } else { |
| 283 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | // Make sure we add the includes last into SuggestedPredefines before we |
| 288 | // exit this function. |
| 289 | struct AddIncludesRAII { |
| 290 | std::string &SuggestedPredefines; |
| 291 | std::string &IncludesAfterPCH; |
| 292 | |
| 293 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 294 | std::string &IncludesAfterPCH) |
| 295 | : SuggestedPredefines(SuggestedPredefines), |
| 296 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 297 | ~AddIncludesRAII() { |
| 298 | SuggestedPredefines += IncludesAfterPCH; |
| 299 | } |
| 300 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 301 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 302 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 303 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 304 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 305 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 306 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 307 | // Determine which predefines that were used to build the PCH file are missing |
| 308 | // from the command line. |
| 309 | std::vector<llvm::StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 310 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 311 | CmdLineLines.begin(), CmdLineLines.end(), |
| 312 | std::back_inserter(MissingPredefines)); |
| 313 | |
| 314 | bool MissingDefines = false; |
| 315 | bool ConflictingDefines = false; |
| 316 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 317 | llvm::StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 318 | if (Missing.startswith("#include ")) { |
| 319 | // An -include was specified when generating the PCH; it is included in |
| 320 | // the PCH, just ignore it. |
| 321 | continue; |
| 322 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 323 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 324 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 325 | return true; |
| 326 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 327 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 328 | // This is a macro definition. Determine the name of the macro we're |
| 329 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 330 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 331 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 332 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 333 | assert(EndOfMacroName != std::string::npos && |
| 334 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 335 | llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 336 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 337 | // Determine whether this macro was given a different definition on the |
| 338 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 339 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 340 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 341 | llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 342 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 343 | MacroDefStart); |
| 344 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 345 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 346 | // Different macro; we're done. |
| 347 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 348 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 349 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 350 | |
| 351 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 352 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 353 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 354 | (*ConflictPos)[MacroDefLen] != '(') |
| 355 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 357 | // We found a conflicting macro definition. |
| 358 | break; |
| 359 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 360 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 361 | if (ConflictPos != CmdLineLines.end()) { |
| 362 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 363 | << MacroName; |
| 364 | |
| 365 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 366 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 367 | FindMacro(Buffers, Missing); |
| 368 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 369 | SourceLocation PCHMissingLoc = |
| 370 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 371 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 372 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 373 | |
| 374 | ConflictingDefines = true; |
| 375 | continue; |
| 376 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 377 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 378 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 379 | // 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] | 380 | if (ConflictingDefines) |
| 381 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 382 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 383 | if (!MissingDefines) { |
| 384 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 385 | MissingDefines = true; |
| 386 | } |
| 387 | |
| 388 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 389 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 390 | FindMacro(Buffers, Missing); |
| 391 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 392 | SourceLocation PCHMissingLoc = |
| 393 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 394 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 395 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 396 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 397 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 398 | if (ConflictingDefines) |
| 399 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 400 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 401 | // Determine what predefines were introduced based on command-line |
| 402 | // parameters that were not present when building the PCH |
| 403 | // file. Extra #defines are okay, so long as the identifiers being |
| 404 | // defined were not used within the precompiled header. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 405 | std::vector<llvm::StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 406 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 407 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 408 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 409 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 410 | llvm::StringRef &Extra = ExtraPredefines[I]; |
| 411 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 412 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 413 | return true; |
| 414 | } |
| 415 | |
| 416 | // This is an extra macro definition. Determine the name of the |
| 417 | // macro we're defining. |
| 418 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 419 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 420 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 421 | assert(EndOfMacroName != std::string::npos && |
| 422 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 423 | llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 424 | |
| 425 | // Check whether this name was used somewhere in the PCH file. If |
| 426 | // so, defining it as a macro could change behavior, so we reject |
| 427 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 428 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 429 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 430 | return true; |
| 431 | } |
| 432 | |
| 433 | // Add this definition to the suggested predefines buffer. |
| 434 | SuggestedPredefines += Extra; |
| 435 | SuggestedPredefines += '\n'; |
| 436 | } |
| 437 | |
| 438 | // If we get here, it's because the predefines buffer had compatible |
| 439 | // contents. Accept the PCH file. |
| 440 | return false; |
| 441 | } |
| 442 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 443 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 444 | unsigned ID) { |
| 445 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 446 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | void PCHValidator::ReadCounter(unsigned Value) { |
| 450 | PP.setCounterValue(Value); |
| 451 | } |
| 452 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 453 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 454 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 455 | //===----------------------------------------------------------------------===// |
| 456 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 457 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 458 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 459 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 462 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 463 | namespace { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 464 | class ASTSelectorLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 465 | ASTReader &Reader; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 466 | |
| 467 | public: |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 468 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 469 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 470 | ObjCMethodList Instance, Factory; |
| 471 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 472 | |
| 473 | typedef Selector external_key_type; |
| 474 | typedef external_key_type internal_key_type; |
| 475 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 476 | explicit ASTSelectorLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 477 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 478 | static bool EqualKey(const internal_key_type& a, |
| 479 | const internal_key_type& b) { |
| 480 | return a == b; |
| 481 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 482 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 483 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 484 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 485 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 486 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 487 | // This hopefully will just get inlined and removed by the optimizer. |
| 488 | static const internal_key_type& |
| 489 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 490 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 491 | static std::pair<unsigned, unsigned> |
| 492 | ReadKeyDataLength(const unsigned char*& d) { |
| 493 | using namespace clang::io; |
| 494 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 495 | unsigned DataLen = ReadUnalignedLE16(d); |
| 496 | return std::make_pair(KeyLen, DataLen); |
| 497 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 498 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 499 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 500 | using namespace clang::io; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 501 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 502 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 503 | IdentifierInfo *FirstII |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 504 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 505 | if (N == 0) |
| 506 | return SelTable.getNullarySelector(FirstII); |
| 507 | else if (N == 1) |
| 508 | return SelTable.getUnarySelector(FirstII); |
| 509 | |
| 510 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 511 | Args.push_back(FirstII); |
| 512 | for (unsigned I = 1; I != N; ++I) |
| 513 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 514 | |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 515 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 516 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 517 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 518 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 519 | using namespace clang::io; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 520 | |
| 521 | data_type Result; |
| 522 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 523 | Result.ID = ReadUnalignedLE32(d); |
| 524 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 525 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 526 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 527 | // Load instance methods |
| 528 | ObjCMethodList *Prev = 0; |
| 529 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 531 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 532 | if (!Result.Instance.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 533 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 534 | Result.Instance.Method = Method; |
| 535 | Prev = &Result.Instance; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 536 | continue; |
| 537 | } |
| 538 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 539 | ObjCMethodList *Mem = |
| 540 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 541 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 542 | Prev = Prev->Next; |
| 543 | } |
| 544 | |
| 545 | // Load factory methods |
| 546 | Prev = 0; |
| 547 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 548 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 549 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 550 | if (!Result.Factory.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 551 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 552 | Result.Factory.Method = Method; |
| 553 | Prev = &Result.Factory; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 554 | continue; |
| 555 | } |
| 556 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 557 | ObjCMethodList *Mem = |
| 558 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 559 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 560 | Prev = Prev->Next; |
| 561 | } |
| 562 | |
| 563 | return Result; |
| 564 | } |
| 565 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 566 | |
| 567 | } // end anonymous namespace |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 568 | |
| 569 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 570 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 571 | ASTSelectorLookupTable; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 572 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 573 | namespace clang { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 574 | class ASTIdentifierLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 575 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 576 | ASTReader::PerFileData &F; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 577 | |
| 578 | // If we know the IdentifierInfo in advance, it is here and we will |
| 579 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 580 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 581 | IdentifierInfo *KnownII; |
| 582 | |
| 583 | public: |
| 584 | typedef IdentifierInfo * data_type; |
| 585 | |
| 586 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 587 | |
| 588 | typedef external_key_type internal_key_type; |
| 589 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 590 | ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 591 | IdentifierInfo *II = 0) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 592 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 593 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 594 | static bool EqualKey(const internal_key_type& a, |
| 595 | const internal_key_type& b) { |
| 596 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 597 | : false; |
| 598 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 599 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 600 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 601 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 602 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 603 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 604 | // This hopefully will just get inlined and removed by the optimizer. |
| 605 | static const internal_key_type& |
| 606 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 607 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 608 | // This hopefully will just get inlined and removed by the optimizer. |
| 609 | static const external_key_type& |
| 610 | GetExternalKey(const internal_key_type& x) { return x; } |
| 611 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 612 | static std::pair<unsigned, unsigned> |
| 613 | ReadKeyDataLength(const unsigned char*& d) { |
| 614 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 615 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 616 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 617 | return std::make_pair(KeyLen, DataLen); |
| 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 std::pair<const char*, unsigned> |
| 621 | ReadKey(const unsigned char* d, unsigned n) { |
| 622 | assert(n >= 2 && d[n-1] == '\0'); |
| 623 | return std::make_pair((const char*) d, n-1); |
| 624 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 625 | |
| 626 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 627 | const unsigned char* d, |
| 628 | unsigned DataLen) { |
| 629 | using namespace clang::io; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 630 | IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 631 | bool IsInteresting = ID & 0x01; |
| 632 | |
| 633 | // Wipe out the "is interesting" bit. |
| 634 | ID = ID >> 1; |
| 635 | |
| 636 | if (!IsInteresting) { |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 637 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 638 | // and associate it with the persistent ID. |
| 639 | IdentifierInfo *II = KnownII; |
| 640 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 641 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 642 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 643 | II->setIsFromAST(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 644 | return II; |
| 645 | } |
| 646 | |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 647 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 648 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 649 | Bits >>= 1; |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 650 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 651 | Bits >>= 1; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 652 | bool Poisoned = Bits & 0x01; |
| 653 | Bits >>= 1; |
| 654 | bool ExtensionToken = Bits & 0x01; |
| 655 | Bits >>= 1; |
| 656 | bool hasMacroDefinition = Bits & 0x01; |
| 657 | Bits >>= 1; |
| 658 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 659 | Bits >>= 10; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 660 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 661 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 662 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 663 | |
| 664 | // Build the IdentifierInfo itself and link the identifier ID with |
| 665 | // the new IdentifierInfo. |
| 666 | IdentifierInfo *II = KnownII; |
| 667 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 668 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 669 | Reader.SetIdentifierInfo(ID, II); |
| 670 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 671 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 672 | // Token IDs are read-only. |
| 673 | if (HasRevertedTokenIDToIdentifier) |
| 674 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 675 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 677 | "Incorrect extension token flag"); |
| 678 | (void)ExtensionToken; |
| 679 | II->setIsPoisoned(Poisoned); |
| 680 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 681 | "Incorrect C++ operator keyword flag"); |
| 682 | (void)CPlusPlusOperatorKeyword; |
| 683 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 684 | // If this identifier is a macro, deserialize the macro |
| 685 | // definition. |
| 686 | if (hasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 687 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 688 | Reader.SetIdentifierIsMacro(II, F, Offset); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 689 | DataLen -= 4; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 690 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 691 | |
| 692 | // Read all of the declarations visible at global scope with this |
| 693 | // name. |
Chris Lattner | 6bf690f | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 694 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 695 | if (DataLen > 0) { |
| 696 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 697 | for (; DataLen > 0; DataLen -= 4) |
| 698 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 699 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 700 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 702 | II->setIsFromAST(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 703 | return II; |
| 704 | } |
| 705 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 706 | |
| 707 | } // end anonymous namespace |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 708 | |
| 709 | /// \brief The on-disk hash table used to contain information about |
| 710 | /// all of the identifiers in the program. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 711 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 712 | ASTIdentifierLookupTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 713 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 714 | namespace { |
| 715 | class ASTDeclContextNameLookupTrait { |
| 716 | ASTReader &Reader; |
| 717 | |
| 718 | public: |
| 719 | /// \brief Pair of begin/end iterators for DeclIDs. |
| 720 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 721 | |
| 722 | /// \brief Special internal key for declaration names. |
| 723 | /// The hash table creates keys for comparison; we do not create |
| 724 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 725 | struct DeclNameKey { |
| 726 | DeclarationName::NameKind Kind; |
| 727 | uint64_t Data; |
| 728 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 729 | }; |
| 730 | |
| 731 | typedef DeclarationName external_key_type; |
| 732 | typedef DeclNameKey internal_key_type; |
| 733 | |
| 734 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
| 735 | |
| 736 | static bool EqualKey(const internal_key_type& a, |
| 737 | const internal_key_type& b) { |
| 738 | return a.Kind == b.Kind && a.Data == b.Data; |
| 739 | } |
| 740 | |
| 741 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 742 | llvm::FoldingSetNodeID ID; |
| 743 | ID.AddInteger(Key.Kind); |
| 744 | |
| 745 | switch (Key.Kind) { |
| 746 | case DeclarationName::Identifier: |
| 747 | case DeclarationName::CXXLiteralOperatorName: |
| 748 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 749 | break; |
| 750 | case DeclarationName::ObjCZeroArgSelector: |
| 751 | case DeclarationName::ObjCOneArgSelector: |
| 752 | case DeclarationName::ObjCMultiArgSelector: |
| 753 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 754 | break; |
| 755 | case DeclarationName::CXXConstructorName: |
| 756 | case DeclarationName::CXXDestructorName: |
| 757 | case DeclarationName::CXXConversionFunctionName: |
| 758 | ID.AddInteger((TypeID)Key.Data); |
| 759 | break; |
| 760 | case DeclarationName::CXXOperatorName: |
| 761 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 762 | break; |
| 763 | case DeclarationName::CXXUsingDirective: |
| 764 | break; |
| 765 | } |
| 766 | |
| 767 | return ID.ComputeHash(); |
| 768 | } |
| 769 | |
| 770 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 771 | DeclNameKey Key; |
| 772 | Key.Kind = Name.getNameKind(); |
| 773 | switch (Name.getNameKind()) { |
| 774 | case DeclarationName::Identifier: |
| 775 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 776 | break; |
| 777 | case DeclarationName::ObjCZeroArgSelector: |
| 778 | case DeclarationName::ObjCOneArgSelector: |
| 779 | case DeclarationName::ObjCMultiArgSelector: |
| 780 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 781 | break; |
| 782 | case DeclarationName::CXXConstructorName: |
| 783 | case DeclarationName::CXXDestructorName: |
| 784 | case DeclarationName::CXXConversionFunctionName: |
| 785 | Key.Data = Reader.GetTypeID(Name.getCXXNameType()); |
| 786 | break; |
| 787 | case DeclarationName::CXXOperatorName: |
| 788 | Key.Data = Name.getCXXOverloadedOperator(); |
| 789 | break; |
| 790 | case DeclarationName::CXXLiteralOperatorName: |
| 791 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 792 | break; |
| 793 | case DeclarationName::CXXUsingDirective: |
| 794 | break; |
| 795 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 796 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 797 | return Key; |
| 798 | } |
| 799 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 800 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 801 | ASTContext *Context = Reader.getContext(); |
| 802 | switch (Key.Kind) { |
| 803 | case DeclarationName::Identifier: |
| 804 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 805 | |
| 806 | case DeclarationName::ObjCZeroArgSelector: |
| 807 | case DeclarationName::ObjCOneArgSelector: |
| 808 | case DeclarationName::ObjCMultiArgSelector: |
| 809 | return DeclarationName(Selector(Key.Data)); |
| 810 | |
| 811 | case DeclarationName::CXXConstructorName: |
| 812 | return Context->DeclarationNames.getCXXConstructorName( |
| 813 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 814 | |
| 815 | case DeclarationName::CXXDestructorName: |
| 816 | return Context->DeclarationNames.getCXXDestructorName( |
| 817 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 818 | |
| 819 | case DeclarationName::CXXConversionFunctionName: |
| 820 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 821 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 822 | |
| 823 | case DeclarationName::CXXOperatorName: |
| 824 | return Context->DeclarationNames.getCXXOperatorName( |
| 825 | (OverloadedOperatorKind)Key.Data); |
| 826 | |
| 827 | case DeclarationName::CXXLiteralOperatorName: |
| 828 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 829 | (IdentifierInfo*)Key.Data); |
| 830 | |
| 831 | case DeclarationName::CXXUsingDirective: |
| 832 | return DeclarationName::getUsingDirectiveName(); |
| 833 | } |
| 834 | |
| 835 | llvm_unreachable("Invalid Name Kind ?"); |
| 836 | } |
| 837 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 838 | static std::pair<unsigned, unsigned> |
| 839 | ReadKeyDataLength(const unsigned char*& d) { |
| 840 | using namespace clang::io; |
| 841 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 842 | unsigned DataLen = ReadUnalignedLE16(d); |
| 843 | return std::make_pair(KeyLen, DataLen); |
| 844 | } |
| 845 | |
| 846 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 847 | using namespace clang::io; |
| 848 | |
| 849 | DeclNameKey Key; |
| 850 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 851 | switch (Key.Kind) { |
| 852 | case DeclarationName::Identifier: |
| 853 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 854 | break; |
| 855 | case DeclarationName::ObjCZeroArgSelector: |
| 856 | case DeclarationName::ObjCOneArgSelector: |
| 857 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 858 | Key.Data = |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 859 | (uint64_t)Reader.DecodeSelector(ReadUnalignedLE32(d)).getAsOpaquePtr(); |
| 860 | break; |
| 861 | case DeclarationName::CXXConstructorName: |
| 862 | case DeclarationName::CXXDestructorName: |
| 863 | case DeclarationName::CXXConversionFunctionName: |
| 864 | Key.Data = ReadUnalignedLE32(d); // TypeID |
| 865 | break; |
| 866 | case DeclarationName::CXXOperatorName: |
| 867 | Key.Data = *d++; // OverloadedOperatorKind |
| 868 | break; |
| 869 | case DeclarationName::CXXLiteralOperatorName: |
| 870 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 871 | break; |
| 872 | case DeclarationName::CXXUsingDirective: |
| 873 | break; |
| 874 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 875 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 876 | return Key; |
| 877 | } |
| 878 | |
| 879 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 880 | unsigned DataLen) { |
| 881 | using namespace clang::io; |
| 882 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 883 | DeclID *Start = (DeclID *)d; |
| 884 | return std::make_pair(Start, Start + NumDecls); |
| 885 | } |
| 886 | }; |
| 887 | |
| 888 | } // end anonymous namespace |
| 889 | |
| 890 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 891 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 892 | ASTDeclContextNameLookupTable; |
| 893 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 894 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 895 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 896 | DeclContextInfo &Info) { |
| 897 | SavedStreamPosition SavedPosition(Cursor); |
| 898 | // First the lexical decls. |
| 899 | if (Offsets.first != 0) { |
| 900 | Cursor.JumpToBit(Offsets.first); |
| 901 | |
| 902 | RecordData Record; |
| 903 | const char *Blob; |
| 904 | unsigned BlobLen; |
| 905 | unsigned Code = Cursor.ReadCode(); |
| 906 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 907 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 908 | Error("Expected lexical block"); |
| 909 | return true; |
| 910 | } |
| 911 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 912 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 913 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 914 | } else { |
| 915 | Info.LexicalDecls = 0; |
| 916 | Info.NumLexicalDecls = 0; |
| 917 | } |
| 918 | |
| 919 | // Now the lookup table. |
| 920 | if (Offsets.second != 0) { |
| 921 | Cursor.JumpToBit(Offsets.second); |
| 922 | |
| 923 | RecordData Record; |
| 924 | const char *Blob; |
| 925 | unsigned BlobLen; |
| 926 | unsigned Code = Cursor.ReadCode(); |
| 927 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 928 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 929 | Error("Expected visible lookup table block"); |
| 930 | return true; |
| 931 | } |
| 932 | Info.NameLookupTableData |
| 933 | = ASTDeclContextNameLookupTable::Create( |
| 934 | (const unsigned char *)Blob + Record[0], |
| 935 | (const unsigned char *)Blob, |
| 936 | ASTDeclContextNameLookupTrait(*this)); |
Sebastian Redl | 0ea8f7f | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 937 | } else { |
| 938 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | return false; |
| 942 | } |
| 943 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 944 | void ASTReader::Error(const char *Msg) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 945 | Diag(diag::err_fe_pch_malformed) << Msg; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 946 | } |
| 947 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 948 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 949 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 950 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 951 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 952 | ActualOriginalFileName, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 953 | SuggestedPredefines); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 954 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 957 | //===----------------------------------------------------------------------===// |
| 958 | // Source Manager Deserialization |
| 959 | //===----------------------------------------------------------------------===// |
| 960 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 961 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 962 | /// \returns true if there was an error. |
| 963 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 964 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 965 | unsigned Idx = 0; |
| 966 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 967 | |
| 968 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 969 | std::map<int, int> FileIDs; |
| 970 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 971 | // Extract the file name |
| 972 | unsigned FilenameLen = Record[Idx++]; |
| 973 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 974 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 975 | MaybeAddSystemRootToFilename(Filename); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 976 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 977 | Filename.size()); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | // Parse the line entries |
| 981 | std::vector<LineEntry> Entries; |
| 982 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 983 | int FID = Record[Idx++]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 984 | |
| 985 | // Extract the line entries |
| 986 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 987 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 988 | Entries.clear(); |
| 989 | Entries.reserve(NumEntries); |
| 990 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 991 | unsigned FileOffset = Record[Idx++]; |
| 992 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 993 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 994 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 995 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 996 | unsigned IncludeOffset = Record[Idx++]; |
| 997 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 998 | FileKind, IncludeOffset)); |
| 999 | } |
| 1000 | LineTable.AddEntry(FID, Entries); |
| 1001 | } |
| 1002 | |
| 1003 | return false; |
| 1004 | } |
| 1005 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1006 | namespace { |
| 1007 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1008 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1009 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1010 | const ino_t ino; |
| 1011 | const dev_t dev; |
| 1012 | const mode_t mode; |
| 1013 | const time_t mtime; |
| 1014 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1015 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1016 | 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] | 1017 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1018 | }; |
| 1019 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1020 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1021 | public: |
| 1022 | typedef const char *external_key_type; |
| 1023 | typedef const char *internal_key_type; |
| 1024 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1025 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1026 | |
| 1027 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1028 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1032 | |
| 1033 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1034 | return strcmp(a, b) == 0; |
| 1035 | } |
| 1036 | |
| 1037 | static std::pair<unsigned, unsigned> |
| 1038 | ReadKeyDataLength(const unsigned char*& d) { |
| 1039 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1040 | unsigned DataLen = (unsigned) *d++; |
| 1041 | return std::make_pair(KeyLen + 1, DataLen); |
| 1042 | } |
| 1043 | |
| 1044 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1045 | return (const char *)d; |
| 1046 | } |
| 1047 | |
| 1048 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1049 | unsigned /*DataLen*/) { |
| 1050 | using namespace clang::io; |
| 1051 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1052 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1053 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1054 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1055 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1056 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1057 | return data_type(ino, dev, mode, mtime, size); |
| 1058 | } |
| 1059 | }; |
| 1060 | |
| 1061 | /// \brief stat() cache for precompiled headers. |
| 1062 | /// |
| 1063 | /// This cache is very similar to the stat cache used by pretokenized |
| 1064 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1065 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1066 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1067 | CacheTy *Cache; |
| 1068 | |
| 1069 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1070 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1071 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1072 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1073 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1074 | Cache = CacheTy::Create(Buckets, Base); |
| 1075 | } |
| 1076 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1077 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1078 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1079 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1080 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1081 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1082 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1083 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1084 | // 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] | 1085 | if (I == Cache->end()) { |
| 1086 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1087 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1088 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1089 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1090 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1091 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1092 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1093 | StatBuf.st_ino = Data.ino; |
| 1094 | StatBuf.st_dev = Data.dev; |
| 1095 | StatBuf.st_mtime = Data.mtime; |
| 1096 | StatBuf.st_mode = Data.mode; |
| 1097 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1098 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1099 | } |
| 1100 | }; |
| 1101 | } // end anonymous namespace |
| 1102 | |
| 1103 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1104 | /// \brief Read a source manager block |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1105 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1106 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1107 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1108 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1109 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1110 | // Set the source-location entry cursor to the current position in |
| 1111 | // the stream. This cursor will be used to read the contents of the |
| 1112 | // source manager block initially, and then lazily read |
| 1113 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1114 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1115 | |
| 1116 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1117 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1118 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1119 | return Failure; |
| 1120 | } |
| 1121 | |
| 1122 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1123 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1124 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1125 | return Failure; |
| 1126 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1127 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1128 | RecordData Record; |
| 1129 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1130 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1131 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1132 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1133 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1134 | return Failure; |
| 1135 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1136 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1137 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1138 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1139 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1140 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1141 | SLocEntryCursor.ReadSubBlockID(); |
| 1142 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1143 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1144 | return Failure; |
| 1145 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1146 | continue; |
| 1147 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1148 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1149 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1150 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1151 | continue; |
| 1152 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1153 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1154 | // Read a record. |
| 1155 | const char *BlobStart; |
| 1156 | unsigned BlobLen; |
| 1157 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1158 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1159 | default: // Default behavior: ignore. |
| 1160 | break; |
| 1161 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1162 | case SM_LINE_TABLE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1163 | if (ParseLineTable(F, Record)) |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1164 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1165 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1166 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1167 | case SM_SLOC_FILE_ENTRY: |
| 1168 | case SM_SLOC_BUFFER_ENTRY: |
| 1169 | case SM_SLOC_INSTANTIATION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1170 | // Once we hit one of the source location entries, we're done. |
| 1171 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1172 | } |
| 1173 | } |
| 1174 | } |
| 1175 | |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1176 | /// \brief Get a cursor that's correctly positioned for reading the source |
| 1177 | /// location entry with the given ID. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1178 | ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1179 | assert(ID != 0 && ID <= TotalNumSLocEntries && |
| 1180 | "SLocCursorForID should only be called for real IDs."); |
| 1181 | |
| 1182 | ID -= 1; |
| 1183 | PerFileData *F = 0; |
| 1184 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1185 | F = Chain[N - I - 1]; |
| 1186 | if (ID < F->LocalNumSLocEntries) |
| 1187 | break; |
| 1188 | ID -= F->LocalNumSLocEntries; |
| 1189 | } |
| 1190 | assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); |
| 1191 | |
| 1192 | F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1193 | return F; |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1196 | /// \brief Read in the source location entry with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1197 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1198 | if (ID == 0) |
| 1199 | return Success; |
| 1200 | |
| 1201 | if (ID > TotalNumSLocEntries) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1202 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1203 | return Failure; |
| 1204 | } |
| 1205 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1206 | PerFileData *F = SLocCursorForID(ID); |
| 1207 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1208 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1209 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1210 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1211 | if (Code == llvm::bitc::END_BLOCK || |
| 1212 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1213 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1214 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1215 | return Failure; |
| 1216 | } |
| 1217 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1218 | RecordData Record; |
| 1219 | const char *BlobStart; |
| 1220 | unsigned BlobLen; |
| 1221 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1222 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1223 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1224 | return Failure; |
| 1225 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1226 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1227 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1228 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1229 | const FileEntry *File = FileMgr.getFile(Filename); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1230 | if (File == 0) { |
| 1231 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1232 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1233 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1234 | Error(ErrorStr.c_str()); |
| 1235 | return Failure; |
| 1236 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1237 | |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1238 | if (Record.size() < 10) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1239 | Error("source location entry is incorrect"); |
| 1240 | return Failure; |
| 1241 | } |
| 1242 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1243 | if (!DisableValidation && |
| 1244 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1245 | #if !defined(LLVM_ON_WIN32) |
| 1246 | // In our regression testing, the Windows file system seems to |
| 1247 | // have inconsistent modification times that sometimes |
| 1248 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1249 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1250 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1251 | )) { |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1252 | Diag(diag::err_fe_pch_file_modified) |
| 1253 | << Filename; |
| 1254 | return Failure; |
| 1255 | } |
| 1256 | |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1257 | FileID FID = SourceMgr.createFileID(File, ReadSourceLocation(*F, Record[1]), |
| 1258 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1259 | ID, Record[0]); |
| 1260 | if (Record[3]) |
| 1261 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1262 | .setHasLineDirectives(); |
| 1263 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 1264 | // Reconstruct header-search information for this file. |
| 1265 | HeaderFileInfo HFI; |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1266 | HFI.isImport = Record[6]; |
| 1267 | HFI.DirInfo = Record[7]; |
| 1268 | HFI.NumIncludes = Record[8]; |
| 1269 | HFI.ControllingMacroID = Record[9]; |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 1270 | if (Listener) |
| 1271 | Listener->ReadHeaderFileInfo(HFI, File->getUID()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1272 | break; |
| 1273 | } |
| 1274 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1275 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1276 | const char *Name = BlobStart; |
| 1277 | unsigned Offset = Record[0]; |
| 1278 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1279 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1280 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1281 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1282 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1283 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1284 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1285 | return Failure; |
| 1286 | } |
| 1287 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1288 | llvm::MemoryBuffer *Buffer |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1289 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1290 | Name); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1291 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1292 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1293 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1294 | PCHPredefinesBlock Block = { |
| 1295 | BufferID, |
| 1296 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1297 | }; |
| 1298 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1299 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1300 | |
| 1301 | break; |
| 1302 | } |
| 1303 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1304 | case SM_SLOC_INSTANTIATION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1305 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1306 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1307 | ReadSourceLocation(*F, Record[2]), |
| 1308 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1309 | Record[4], |
| 1310 | ID, |
| 1311 | Record[0]); |
| 1312 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1313 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | return Success; |
| 1317 | } |
| 1318 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1319 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1320 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1321 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1322 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1323 | unsigned BlockID) { |
| 1324 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1325 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1326 | return Failure; |
| 1327 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1328 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1329 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1330 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1331 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1332 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1333 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1334 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1335 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1336 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1337 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1338 | Cursor.ReadAbbrevRecord(); |
| 1339 | } |
| 1340 | } |
| 1341 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1342 | void ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1343 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1344 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1345 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1346 | // Keep track of where we are in the stream, then jump back there |
| 1347 | // after reading this macro. |
| 1348 | SavedStreamPosition SavedPosition(Stream); |
| 1349 | |
| 1350 | Stream.JumpToBit(Offset); |
| 1351 | RecordData Record; |
| 1352 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1353 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1354 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1355 | while (true) { |
| 1356 | unsigned Code = Stream.ReadCode(); |
| 1357 | switch (Code) { |
| 1358 | case llvm::bitc::END_BLOCK: |
| 1359 | return; |
| 1360 | |
| 1361 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1362 | // No known subblocks, always skip them. |
| 1363 | Stream.ReadSubBlockID(); |
| 1364 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1365 | Error("malformed block record in AST file"); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1366 | return; |
| 1367 | } |
| 1368 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1369 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1370 | case llvm::bitc::DEFINE_ABBREV: |
| 1371 | Stream.ReadAbbrevRecord(); |
| 1372 | continue; |
| 1373 | default: break; |
| 1374 | } |
| 1375 | |
| 1376 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1377 | const char *BlobStart = 0; |
| 1378 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1379 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1380 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1381 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1382 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1383 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1384 | case PP_MACRO_OBJECT_LIKE: |
| 1385 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1386 | // If we already have a macro, that means that we've hit the end |
| 1387 | // of the definition of the macro we were looking for. We're |
| 1388 | // done. |
| 1389 | if (Macro) |
| 1390 | return; |
| 1391 | |
| 1392 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1393 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1394 | Error("macro must have a name in AST file"); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1395 | return; |
| 1396 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1397 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1398 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1399 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1400 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1401 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1402 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1403 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1404 | unsigned NextIndex = 3; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1405 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1406 | // Decode function-like macro info. |
| 1407 | bool isC99VarArgs = Record[3]; |
| 1408 | bool isGNUVarArgs = Record[4]; |
| 1409 | MacroArgs.clear(); |
| 1410 | unsigned NumArgs = Record[5]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1411 | NextIndex = 6 + NumArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1412 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1413 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1414 | |
| 1415 | // Install function-like macro info. |
| 1416 | MI->setIsFunctionLike(); |
| 1417 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1418 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1419 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1420 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1424 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1425 | |
| 1426 | // Remember that we saw this macro last so that we add the tokens that |
| 1427 | // form its body to it. |
| 1428 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1429 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1430 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1431 | // We have a macro definition. Load it now. |
| 1432 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1433 | getMacroDefinition(Record[NextIndex])); |
| 1434 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1435 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1436 | ++NumMacrosRead; |
| 1437 | break; |
| 1438 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1439 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1440 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1441 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1442 | // erroneous, just pretend we didn't see this. |
| 1443 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1444 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1445 | Token Tok; |
| 1446 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1447 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1448 | Tok.setLength(Record[1]); |
| 1449 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1450 | Tok.setIdentifierInfo(II); |
| 1451 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1452 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1453 | Macro->AddTokenToBody(Tok); |
| 1454 | break; |
| 1455 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1456 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1457 | case PP_MACRO_INSTANTIATION: { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1458 | // If we already have a macro, that means that we've hit the end |
| 1459 | // of the definition of the macro we were looking for. We're |
| 1460 | // done. |
| 1461 | if (Macro) |
| 1462 | return; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1463 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1464 | if (!PP->getPreprocessingRecord()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1465 | Error("missing preprocessing record in AST file"); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1466 | return; |
| 1467 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1468 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1469 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1470 | if (PPRec.getPreprocessedEntity(Record[0])) |
| 1471 | return; |
| 1472 | |
| 1473 | MacroInstantiation *MI |
| 1474 | = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1475 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1476 | ReadSourceLocation(F, Record[2])), |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1477 | getMacroDefinition(Record[4])); |
| 1478 | PPRec.SetPreallocatedEntity(Record[0], MI); |
| 1479 | return; |
| 1480 | } |
| 1481 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1482 | case PP_MACRO_DEFINITION: { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1483 | // If we already have a macro, that means that we've hit the end |
| 1484 | // of the definition of the macro we were looking for. We're |
| 1485 | // done. |
| 1486 | if (Macro) |
| 1487 | return; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1488 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1489 | if (!PP->getPreprocessingRecord()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1490 | Error("missing preprocessing record in AST file"); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1491 | return; |
| 1492 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1493 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1494 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1495 | if (PPRec.getPreprocessedEntity(Record[0])) |
| 1496 | return; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1497 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1498 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1499 | Error("out-of-bounds macro definition record"); |
| 1500 | return; |
| 1501 | } |
| 1502 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1503 | // Decode the identifier info and then check again; if the macro is |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1504 | // still defined and associated with the identifier, |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1505 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1506 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1507 | MacroDefinition *MD |
| 1508 | = new (PPRec) MacroDefinition(II, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1509 | ReadSourceLocation(F, Record[5]), |
Douglas Gregor | b1a7d9a | 2010-10-01 20:33:34 +0000 | [diff] [blame] | 1510 | SourceRange( |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1511 | ReadSourceLocation(F, Record[2]), |
| 1512 | ReadSourceLocation(F, Record[3]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1513 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1514 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1515 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1516 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1517 | if (DeserializationListener) |
| 1518 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1519 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1520 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1521 | return; |
| 1522 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1523 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1524 | case PP_INCLUSION_DIRECTIVE: { |
| 1525 | // If we already have a macro, that means that we've hit the end |
| 1526 | // of the definition of the macro we were looking for. We're |
| 1527 | // done. |
| 1528 | if (Macro) |
| 1529 | return; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1530 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1531 | if (!PP->getPreprocessingRecord()) { |
| 1532 | Error("missing preprocessing record in AST file"); |
| 1533 | return; |
| 1534 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1535 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1536 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1537 | if (PPRec.getPreprocessedEntity(Record[0])) |
| 1538 | return; |
| 1539 | |
| 1540 | const char *FullFileNameStart = BlobStart + Record[3]; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1541 | const FileEntry *File |
Chris Lattner | 6538227 | 2010-11-21 09:55:08 +0000 | [diff] [blame] | 1542 | = PP->getFileManager().getFile(llvm::StringRef(FullFileNameStart, |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1543 | BlobLen - Record[3])); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1544 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1545 | // FIXME: Stable encoding |
| 1546 | InclusionDirective::InclusionKind Kind |
| 1547 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1548 | InclusionDirective *ID |
Douglas Gregor | 4ab829c | 2010-11-01 15:03:47 +0000 | [diff] [blame] | 1549 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1550 | llvm::StringRef(BlobStart, Record[3]), |
| 1551 | Record[4], |
| 1552 | File, |
| 1553 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1554 | ReadSourceLocation(F, Record[2]))); |
| 1555 | PPRec.SetPreallocatedEntity(Record[0], ID); |
| 1556 | return; |
| 1557 | } |
Sebastian Redl | b57a624 | 2010-09-27 22:18:47 +0000 | [diff] [blame] | 1558 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1562 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F, |
| 1563 | uint64_t Offset) { |
| 1564 | // Note that this identifier has a macro definition. |
| 1565 | II->setHasMacroDefinition(true); |
| 1566 | |
| 1567 | // Adjust the offset based on our position in the chain. |
| 1568 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1569 | if (Chain[I] == &F) |
| 1570 | break; |
| 1571 | |
| 1572 | Offset += Chain[I]->SizeInBits; |
| 1573 | } |
| 1574 | |
| 1575 | UnreadMacroRecordOffsets[II] = Offset; |
| 1576 | } |
| 1577 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1578 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1579 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1580 | PerFileData &F = *Chain[N - I - 1]; |
| 1581 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1582 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1583 | // If there was no preprocessor block, skip this file. |
| 1584 | if (!MacroCursor.getBitStreamReader()) |
| 1585 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1586 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1587 | llvm::BitstreamCursor Cursor = MacroCursor; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1588 | Cursor.JumpToBit(F.MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1589 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1590 | RecordData Record; |
| 1591 | while (true) { |
Sebastian Redl | edadecc | 2010-09-28 02:55:49 +0000 | [diff] [blame] | 1592 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1593 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1594 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1595 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1596 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1597 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1598 | // No known subblocks, always skip them. |
| 1599 | Cursor.ReadSubBlockID(); |
| 1600 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1601 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1602 | return; |
| 1603 | } |
| 1604 | continue; |
| 1605 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1606 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1607 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1608 | Cursor.ReadAbbrevRecord(); |
| 1609 | continue; |
| 1610 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1611 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1612 | // Read a record. |
| 1613 | const char *BlobStart; |
| 1614 | unsigned BlobLen; |
| 1615 | Record.clear(); |
| 1616 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1617 | default: // Default behavior: ignore. |
| 1618 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1619 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1620 | case PP_MACRO_OBJECT_LIKE: |
| 1621 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1622 | DecodeIdentifierInfo(Record[0]); |
| 1623 | break; |
| 1624 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1625 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1626 | // Ignore tokens. |
| 1627 | break; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1628 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1629 | case PP_MACRO_INSTANTIATION: |
| 1630 | case PP_MACRO_DEFINITION: |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1631 | case PP_INCLUSION_DIRECTIVE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1632 | // Read the macro record. |
Sebastian Redl | edadecc | 2010-09-28 02:55:49 +0000 | [diff] [blame] | 1633 | // FIXME: That's a stupid way to do this. We should reuse this cursor. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1634 | ReadMacroRecord(F, Offset); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1635 | break; |
| 1636 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1637 | } |
| 1638 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1639 | |
| 1640 | // Drain the unread macro-record offsets map. |
| 1641 | while (!UnreadMacroRecordOffsets.empty()) |
| 1642 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1643 | } |
| 1644 | |
| 1645 | void ASTReader::LoadMacroDefinition( |
| 1646 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1647 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
| 1648 | PerFileData *F = 0; |
| 1649 | uint64_t Offset = Pos->second; |
| 1650 | UnreadMacroRecordOffsets.erase(Pos); |
| 1651 | |
| 1652 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1653 | if (Offset < Chain[I]->SizeInBits) { |
| 1654 | F = Chain[I]; |
| 1655 | break; |
| 1656 | } |
| 1657 | |
| 1658 | Offset -= Chain[I]->SizeInBits; |
| 1659 | } |
| 1660 | if (!F) { |
| 1661 | Error("Malformed macro record offset"); |
| 1662 | return; |
| 1663 | } |
| 1664 | |
| 1665 | ReadMacroRecord(*F, Offset); |
| 1666 | } |
| 1667 | |
| 1668 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1669 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1670 | = UnreadMacroRecordOffsets.find(II); |
| 1671 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1674 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1675 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1676 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1677 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1678 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1679 | unsigned Index = ID - 1; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1680 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1681 | PerFileData &F = *Chain[N - I - 1]; |
| 1682 | if (Index < F.LocalNumMacroDefinitions) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1683 | ReadMacroRecord(F, F.MacroDefinitionOffsets[Index]); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1684 | break; |
| 1685 | } |
| 1686 | Index -= F.LocalNumMacroDefinitions; |
| 1687 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1688 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1691 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1694 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1695 | /// not an absolute path, add the system root to the beginning of the file |
| 1696 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1697 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1698 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1699 | if (!RelocatablePCH) |
| 1700 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1701 | |
Daniel Dunbar | d5b2197 | 2009-11-18 19:50:41 +0000 | [diff] [blame] | 1702 | if (Filename.empty() || llvm::sys::Path(Filename).isAbsolute()) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1703 | return; |
| 1704 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1705 | if (isysroot == 0) { |
| 1706 | // If no system root was given, default to '/' |
| 1707 | Filename.insert(Filename.begin(), '/'); |
| 1708 | return; |
| 1709 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1710 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1711 | unsigned Length = strlen(isysroot); |
| 1712 | if (isysroot[Length - 1] != '/') |
| 1713 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1714 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1715 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1716 | } |
| 1717 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1718 | ASTReader::ASTReadResult |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1719 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1720 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1721 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1722 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1723 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1724 | return Failure; |
| 1725 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1726 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1727 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1728 | RecordData Record; |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1729 | bool First = true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1730 | while (!Stream.AtEndOfStream()) { |
| 1731 | unsigned Code = Stream.ReadCode(); |
| 1732 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1733 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1734 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1735 | return Failure; |
| 1736 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1737 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1738 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1742 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1743 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1744 | // We lazily load the decls block, but we want to set up the |
| 1745 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1746 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1747 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1748 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1749 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1750 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1751 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1752 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1753 | return Failure; |
| 1754 | } |
| 1755 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1756 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1757 | case DECL_UPDATES_BLOCK_ID: |
| 1758 | if (Stream.SkipBlock()) { |
| 1759 | Error("malformed block record in AST file"); |
| 1760 | return Failure; |
| 1761 | } |
| 1762 | break; |
| 1763 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1764 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1765 | F.MacroCursor = Stream; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1766 | if (PP) |
| 1767 | PP->setExternalSource(this); |
| 1768 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1769 | if (Stream.SkipBlock() || |
| 1770 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1771 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1772 | return Failure; |
| 1773 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1774 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1775 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1776 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1777 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1778 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1779 | case Success: |
| 1780 | break; |
| 1781 | |
| 1782 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1783 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1784 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1785 | |
| 1786 | case IgnorePCH: |
| 1787 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1788 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1789 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1790 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1791 | First = false; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1792 | continue; |
| 1793 | } |
| 1794 | |
| 1795 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1796 | Stream.ReadAbbrevRecord(); |
| 1797 | continue; |
| 1798 | } |
| 1799 | |
| 1800 | // Read and process a record. |
| 1801 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1802 | const char *BlobStart = 0; |
| 1803 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1804 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1805 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1806 | default: // Default behavior: ignore. |
| 1807 | break; |
| 1808 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1809 | case METADATA: { |
| 1810 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1811 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1812 | : diag::warn_pch_version_too_new); |
| 1813 | return IgnorePCH; |
| 1814 | } |
| 1815 | |
| 1816 | RelocatablePCH = Record[4]; |
| 1817 | if (Listener) { |
| 1818 | std::string TargetTriple(BlobStart, BlobLen); |
| 1819 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1820 | return IgnorePCH; |
| 1821 | } |
| 1822 | break; |
| 1823 | } |
| 1824 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1825 | case CHAINED_METADATA: { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1826 | if (!First) { |
| 1827 | Error("CHAINED_METADATA is not first record in block"); |
| 1828 | return Failure; |
| 1829 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1830 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1831 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1832 | : diag::warn_pch_version_too_new); |
| 1833 | return IgnorePCH; |
| 1834 | } |
| 1835 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 1836 | // Load the chained file, which is always a PCH file. |
| 1837 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1838 | case Failure: return Failure; |
| 1839 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1840 | case IgnorePCH: return IgnorePCH; |
| 1841 | case Success: break; |
| 1842 | } |
| 1843 | break; |
| 1844 | } |
| 1845 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1846 | case TYPE_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1847 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1848 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1849 | return Failure; |
| 1850 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1851 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1852 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1853 | break; |
| 1854 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1855 | case DECL_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1856 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1857 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1858 | return Failure; |
| 1859 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1860 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 1861 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1862 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1863 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1864 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1865 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 1866 | /* No visible information */ 0, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 1867 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 1868 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1869 | }; |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 1870 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 1871 | .push_back(Info); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1872 | break; |
| 1873 | } |
| 1874 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1875 | case UPDATE_VISIBLE: { |
| 1876 | serialization::DeclID ID = Record[0]; |
| 1877 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 1878 | (const unsigned char *)BlobStart + Record[1], |
| 1879 | (const unsigned char *)BlobStart, |
| 1880 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 1881 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1882 | DeclContextInfo Info = { |
| 1883 | Table, /* No lexical inforamtion */ 0, 0 |
| 1884 | }; |
| 1885 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 1886 | } else |
| 1887 | PendingVisibleUpdates[ID].push_back(Table); |
| 1888 | break; |
| 1889 | } |
| 1890 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1891 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1892 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 1893 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1894 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1895 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 1896 | Latest > FirstLatestDeclIDs[First]) && |
| 1897 | "The new latest is supposed to come after the previous latest"); |
| 1898 | FirstLatestDeclIDs[First] = Latest; |
| 1899 | } |
| 1900 | break; |
| 1901 | } |
| 1902 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1903 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1904 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1905 | return IgnorePCH; |
| 1906 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1907 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1908 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1909 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1910 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1911 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1912 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1913 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 1914 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1915 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1916 | if (PP) |
| 1917 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1918 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1919 | break; |
| 1920 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1921 | case IDENTIFIER_OFFSET: |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1922 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1923 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1924 | return Failure; |
| 1925 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1926 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1927 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1928 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1929 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1930 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1931 | // Optimization for the first block. |
| 1932 | if (ExternalDefinitions.empty()) |
| 1933 | ExternalDefinitions.swap(Record); |
| 1934 | else |
| 1935 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 1936 | Record.begin(), Record.end()); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1937 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1938 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1939 | case SPECIAL_TYPES: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1940 | // Optimization for the first block |
| 1941 | if (SpecialTypes.empty()) |
| 1942 | SpecialTypes.swap(Record); |
| 1943 | else |
| 1944 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1945 | break; |
| 1946 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1947 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1948 | TotalNumStatements += Record[0]; |
| 1949 | TotalNumMacros += Record[1]; |
| 1950 | TotalLexicalDeclContexts += Record[2]; |
| 1951 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1952 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1953 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1954 | case TENTATIVE_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1955 | // Optimization for the first block. |
| 1956 | if (TentativeDefinitions.empty()) |
| 1957 | TentativeDefinitions.swap(Record); |
| 1958 | else |
| 1959 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 1960 | Record.begin(), Record.end()); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 1961 | break; |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1962 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1963 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1964 | // Optimization for the first block. |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 1965 | if (UnusedFileScopedDecls.empty()) |
| 1966 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1967 | else |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 1968 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 1969 | Record.begin(), Record.end()); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 1970 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1971 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1972 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 1973 | // Later blocks overwrite earlier ones. |
| 1974 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 1975 | break; |
| 1976 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1977 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1978 | // Optimization for the first block. |
| 1979 | if (LocallyScopedExternalDecls.empty()) |
| 1980 | LocallyScopedExternalDecls.swap(Record); |
| 1981 | else |
| 1982 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 1983 | Record.begin(), Record.end()); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1984 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1985 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1986 | case SELECTOR_OFFSETS: |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 1987 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1988 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1989 | break; |
| 1990 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1991 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1992 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1993 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1994 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1995 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1996 | F.SelectorLookupTableData + Record[0], |
| 1997 | F.SelectorLookupTableData, |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1998 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 1999 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2000 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2001 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2002 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2003 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2004 | break; |
| 2005 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2006 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2007 | if (!Record.empty() && Listener) |
| 2008 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2009 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2010 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2011 | case SOURCE_LOCATION_OFFSETS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2012 | F.SLocOffsets = (const uint32_t *)BlobStart; |
| 2013 | F.LocalNumSLocEntries = Record[0]; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2014 | F.LocalSLocSize = Record[1]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2015 | break; |
| 2016 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2017 | case SOURCE_LOCATION_PRELOADS: |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2018 | if (PreloadSLocEntries.empty()) |
| 2019 | PreloadSLocEntries.swap(Record); |
| 2020 | else |
| 2021 | PreloadSLocEntries.insert(PreloadSLocEntries.end(), |
| 2022 | Record.begin(), Record.end()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2023 | break; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2024 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2025 | case STAT_CACHE: { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2026 | ASTStatCache *MyStatCache = |
| 2027 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2028 | (const unsigned char *)BlobStart, |
| 2029 | NumStatHits, NumStatMisses); |
| 2030 | FileMgr.addStatCache(MyStatCache); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2031 | F.StatCache = MyStatCache; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2032 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2033 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2034 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2035 | case EXT_VECTOR_DECLS: |
Sebastian Redl | a9f2368 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 2036 | // Optimization for the first block. |
| 2037 | if (ExtVectorDecls.empty()) |
| 2038 | ExtVectorDecls.swap(Record); |
| 2039 | else |
| 2040 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 2041 | Record.begin(), Record.end()); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2042 | break; |
| 2043 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2044 | case VTABLE_USES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2045 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2046 | VTableUses.swap(Record); |
| 2047 | break; |
| 2048 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2049 | case DYNAMIC_CLASSES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2050 | // Optimization for the first block. |
| 2051 | if (DynamicClasses.empty()) |
| 2052 | DynamicClasses.swap(Record); |
| 2053 | else |
| 2054 | DynamicClasses.insert(DynamicClasses.end(), |
| 2055 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2056 | break; |
| 2057 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2058 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2059 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2060 | break; |
| 2061 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2062 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2063 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2064 | SemaDeclRefs.swap(Record); |
| 2065 | break; |
| 2066 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2067 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2068 | // 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] | 2069 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2070 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2071 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2072 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2073 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2074 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2075 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2076 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2077 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 2078 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2079 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2080 | return IgnorePCH; |
| 2081 | } |
| 2082 | break; |
| 2083 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2084 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2085 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2086 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2087 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2088 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2089 | break; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2090 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2091 | case DECL_UPDATE_OFFSETS: { |
| 2092 | if (Record.size() % 2 != 0) { |
| 2093 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2094 | return Failure; |
| 2095 | } |
| 2096 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
| 2097 | DeclUpdateOffsets[static_cast<DeclID>(Record[I])] |
| 2098 | .push_back(std::make_pair(&F, Record[I+1])); |
| 2099 | break; |
| 2100 | } |
| 2101 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2102 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2103 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2104 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2105 | return Failure; |
| 2106 | } |
| 2107 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2108 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2109 | std::make_pair(&F, Record[I+1]); |
| 2110 | break; |
| 2111 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2112 | |
| 2113 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2114 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2115 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2116 | return Failure; |
| 2117 | } |
| 2118 | |
| 2119 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2120 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
| 2121 | break; |
| 2122 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2123 | |
| 2124 | case DIAG_USER_MAPPINGS: |
| 2125 | if (Record.size() % 2 != 0) { |
| 2126 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2127 | return Failure; |
| 2128 | } |
| 2129 | if (UserDiagMappings.empty()) |
| 2130 | UserDiagMappings.swap(Record); |
| 2131 | else |
| 2132 | UserDiagMappings.insert(UserDiagMappings.end(), |
| 2133 | Record.begin(), Record.end()); |
| 2134 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2135 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2136 | First = false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2137 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2138 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2139 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2142 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2143 | ASTFileType Type) { |
| 2144 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2145 | case Failure: return Failure; |
| 2146 | case IgnorePCH: return IgnorePCH; |
| 2147 | case Success: break; |
| 2148 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2149 | |
| 2150 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2151 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2152 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2153 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2154 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2155 | TotalNumSelectors = 0; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2156 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2157 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2158 | NextSLocOffset += Chain[I]->LocalSLocSize; |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2159 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2160 | TotalNumTypes += Chain[I]->LocalNumTypes; |
| 2161 | TotalNumDecls += Chain[I]->LocalNumDecls; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2162 | TotalNumPreallocatedPreprocessingEntities += |
| 2163 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2164 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2165 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2166 | } |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2167 | SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset); |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2168 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2169 | TypesLoaded.resize(TotalNumTypes); |
| 2170 | DeclsLoaded.resize(TotalNumDecls); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2171 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2172 | if (PP) { |
| 2173 | if (TotalNumIdentifiers > 0) |
| 2174 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2175 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2176 | if (!PP->getPreprocessingRecord()) |
| 2177 | PP->createPreprocessingRecord(); |
| 2178 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2179 | TotalNumPreallocatedPreprocessingEntities); |
| 2180 | } |
| 2181 | } |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2182 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2183 | // Preload SLocEntries. |
| 2184 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2185 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2186 | if (Result != Success) |
| 2187 | return Result; |
| 2188 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2189 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2190 | // Check the predefines buffers. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2191 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2192 | return IgnorePCH; |
| 2193 | |
| 2194 | if (PP) { |
| 2195 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2196 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2197 | // loaded into the IdentifierTable before we intercepted the |
| 2198 | // creation of identifiers. Iterate through the list of known |
| 2199 | // identifiers and determine whether we have to establish |
| 2200 | // preprocessor definitions or top-level identifier declaration |
| 2201 | // chains for those identifiers. |
| 2202 | // |
| 2203 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2204 | // since de-serializing declarations or macro definitions can add |
| 2205 | // new entries into the identifier table, invalidating the |
| 2206 | // iterators. |
| 2207 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2208 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2209 | IdEnd = PP->getIdentifierTable().end(); |
| 2210 | Id != IdEnd; ++Id) |
| 2211 | Identifiers.push_back(Id->second); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2212 | // We need to search the tables in all files. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2213 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2214 | ASTIdentifierLookupTable *IdTable |
| 2215 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2216 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2217 | // ones. |
| 2218 | if (!IdTable) |
| 2219 | continue; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2220 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2221 | IdentifierInfo *II = Identifiers[I]; |
| 2222 | // 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] | 2223 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2224 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2225 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2226 | if (Pos == IdTable->end()) |
| 2227 | continue; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2228 | |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2229 | // Dereferencing the iterator has the effect of populating the |
| 2230 | // IdentifierInfo node with the various declarations it needs. |
| 2231 | (void)*Pos; |
| 2232 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2233 | } |
| 2234 | } |
| 2235 | |
| 2236 | if (Context) |
| 2237 | InitializeContext(*Context); |
| 2238 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2239 | if (DeserializationListener) |
| 2240 | DeserializationListener->ReaderInitialized(this); |
| 2241 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2242 | return Success; |
| 2243 | } |
| 2244 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2245 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2246 | ASTFileType Type) { |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2247 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2248 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2249 | PerFileData &F = *Chain.back(); |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2250 | if (Prev) |
| 2251 | Prev->NextInSource = &F; |
| 2252 | else |
| 2253 | FirstInSource = &F; |
| 2254 | F.Loaders.push_back(Prev); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2255 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2256 | // Set the AST file name. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2257 | F.FileName = FileName; |
| 2258 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2259 | // Open the AST file. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2260 | // |
| 2261 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2262 | std::string ErrStr; |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2263 | if (FileName == "-") |
| 2264 | F.Buffer.reset(llvm::MemoryBuffer::getSTDIN(&ErrStr)); |
| 2265 | else |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2266 | F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr)); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2267 | if (!F.Buffer) { |
| 2268 | Error(ErrStr.c_str()); |
| 2269 | return IgnorePCH; |
| 2270 | } |
| 2271 | |
| 2272 | // Initialize the stream |
| 2273 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2274 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2275 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2276 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2277 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2278 | |
| 2279 | // Sniff for the signature. |
| 2280 | if (Stream.Read(8) != 'C' || |
| 2281 | Stream.Read(8) != 'P' || |
| 2282 | Stream.Read(8) != 'C' || |
| 2283 | Stream.Read(8) != 'H') { |
| 2284 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2285 | return Failure; |
| 2286 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2287 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2288 | while (!Stream.AtEndOfStream()) { |
| 2289 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2290 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2291 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2292 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2293 | return Failure; |
| 2294 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2295 | |
| 2296 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2297 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2298 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2299 | switch (BlockID) { |
| 2300 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2301 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2302 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2303 | return Failure; |
| 2304 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2305 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2306 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2307 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2308 | case Success: |
| 2309 | break; |
| 2310 | |
| 2311 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2312 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2313 | |
| 2314 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2315 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2316 | // AST block, skipping subblocks, to see if there are other |
| 2317 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2318 | |
| 2319 | // Clear out any preallocated source location entries, so that |
| 2320 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2321 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2322 | |
| 2323 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2324 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2325 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2326 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2327 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2328 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2329 | break; |
| 2330 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2331 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2332 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2333 | return Failure; |
| 2334 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2335 | break; |
| 2336 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2337 | } |
| 2338 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2339 | return Success; |
| 2340 | } |
| 2341 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2342 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2343 | PP = &pp; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2344 | |
| 2345 | unsigned TotalNum = 0; |
| 2346 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2347 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2348 | if (TotalNum) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2349 | if (!PP->getPreprocessingRecord()) |
| 2350 | PP->createPreprocessingRecord(); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2351 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2352 | } |
| 2353 | } |
| 2354 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2355 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2356 | Context = &Ctx; |
| 2357 | assert(Context && "Passed null context!"); |
| 2358 | |
| 2359 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2360 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2361 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2362 | PP->setExternalSource(this); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2363 | |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2364 | // If we have an update block for the TU waiting, we have to add it before |
| 2365 | // deserializing the decl. |
| 2366 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2367 | if (DCU != DeclContextOffsets.end()) { |
| 2368 | // Insertion could invalidate map, so grab vector. |
| 2369 | DeclContextInfos T; |
| 2370 | T.swap(DCU->second); |
| 2371 | DeclContextOffsets.erase(DCU); |
| 2372 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2373 | } |
| 2374 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2375 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2376 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2377 | |
| 2378 | // Load the special types. |
| 2379 | Context->setBuiltinVaListType( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2380 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2381 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2382 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2383 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2384 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2385 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2386 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2387 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2388 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2389 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2390 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2391 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2392 | if (unsigned FastEnum |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2393 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2394 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2395 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2396 | QualType FileType = GetType(File); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2397 | if (FileType.isNull()) { |
| 2398 | Error("FILE type is NULL"); |
| 2399 | return; |
| 2400 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2401 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2402 | Context->setFILEDecl(Typedef->getDecl()); |
| 2403 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2404 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2405 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2406 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2407 | return; |
| 2408 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2409 | Context->setFILEDecl(Tag->getDecl()); |
| 2410 | } |
| 2411 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2412 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2413 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2414 | if (Jmp_bufType.isNull()) { |
| 2415 | Error("jmp_bug type is NULL"); |
| 2416 | return; |
| 2417 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2418 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2419 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2420 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2421 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2422 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2423 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2424 | return; |
| 2425 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2426 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2427 | } |
| 2428 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2429 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2430 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2431 | if (Sigjmp_bufType.isNull()) { |
| 2432 | Error("sigjmp_buf type is NULL"); |
| 2433 | return; |
| 2434 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2435 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2436 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2437 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2438 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2439 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2440 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2441 | } |
| 2442 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2443 | if (unsigned ObjCIdRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2444 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2445 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2446 | if (unsigned ObjCClassRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2447 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2448 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2449 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2450 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2451 | if (unsigned String |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2452 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2453 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2454 | if (unsigned ObjCSelRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2455 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2456 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2457 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2458 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2459 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2460 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2461 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2462 | |
| 2463 | ReadUserDiagnosticMappings(Context->getDiagnostics()); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2466 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2467 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2468 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2469 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2470 | FileManager &FileMgr, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2471 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2472 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2473 | std::string ErrStr; |
| 2474 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2475 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2476 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2477 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2478 | return std::string(); |
| 2479 | } |
| 2480 | |
| 2481 | // Initialize the stream |
| 2482 | llvm::BitstreamReader StreamFile; |
| 2483 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2484 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2485 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2486 | Stream.init(StreamFile); |
| 2487 | |
| 2488 | // Sniff for the signature. |
| 2489 | if (Stream.Read(8) != 'C' || |
| 2490 | Stream.Read(8) != 'P' || |
| 2491 | Stream.Read(8) != 'C' || |
| 2492 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2493 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2494 | return std::string(); |
| 2495 | } |
| 2496 | |
| 2497 | RecordData Record; |
| 2498 | while (!Stream.AtEndOfStream()) { |
| 2499 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2500 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2501 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2502 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2503 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2504 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2505 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2506 | case AST_BLOCK_ID: |
| 2507 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2508 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2509 | return std::string(); |
| 2510 | } |
| 2511 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2512 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2513 | default: |
| 2514 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2515 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2516 | return std::string(); |
| 2517 | } |
| 2518 | break; |
| 2519 | } |
| 2520 | continue; |
| 2521 | } |
| 2522 | |
| 2523 | if (Code == llvm::bitc::END_BLOCK) { |
| 2524 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2525 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2526 | return std::string(); |
| 2527 | } |
| 2528 | continue; |
| 2529 | } |
| 2530 | |
| 2531 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2532 | Stream.ReadAbbrevRecord(); |
| 2533 | continue; |
| 2534 | } |
| 2535 | |
| 2536 | Record.clear(); |
| 2537 | const char *BlobStart = 0; |
| 2538 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2539 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2540 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2541 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2542 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2543 | |
| 2544 | return std::string(); |
| 2545 | } |
| 2546 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2547 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2548 | /// structure. |
| 2549 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2550 | /// This routine parses the language options from the AST file and then gives |
| 2551 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2552 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2553 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2554 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2555 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2556 | if (Listener) { |
| 2557 | LangOptions LangOpts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2558 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2559 | #define PARSE_LANGOPT(Option) \ |
| 2560 | LangOpts.Option = Record[Idx]; \ |
| 2561 | ++Idx |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2562 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2563 | unsigned Idx = 0; |
| 2564 | PARSE_LANGOPT(Trigraphs); |
| 2565 | PARSE_LANGOPT(BCPLComment); |
| 2566 | PARSE_LANGOPT(DollarIdents); |
| 2567 | PARSE_LANGOPT(AsmPreprocessor); |
| 2568 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2569 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2570 | PARSE_LANGOPT(ImplicitInt); |
| 2571 | PARSE_LANGOPT(Digraphs); |
| 2572 | PARSE_LANGOPT(HexFloats); |
| 2573 | PARSE_LANGOPT(C99); |
| 2574 | PARSE_LANGOPT(Microsoft); |
| 2575 | PARSE_LANGOPT(CPlusPlus); |
| 2576 | PARSE_LANGOPT(CPlusPlus0x); |
| 2577 | PARSE_LANGOPT(CXXOperatorNames); |
| 2578 | PARSE_LANGOPT(ObjC1); |
| 2579 | PARSE_LANGOPT(ObjC2); |
| 2580 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 2581 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 2582 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2583 | PARSE_LANGOPT(PascalStrings); |
| 2584 | PARSE_LANGOPT(WritableStrings); |
| 2585 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2586 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2587 | PARSE_LANGOPT(Exceptions); |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 2588 | PARSE_LANGOPT(SjLjExceptions); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2589 | PARSE_LANGOPT(NeXTRuntime); |
| 2590 | PARSE_LANGOPT(Freestanding); |
| 2591 | PARSE_LANGOPT(NoBuiltin); |
| 2592 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 2593 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2594 | PARSE_LANGOPT(Blocks); |
| 2595 | PARSE_LANGOPT(EmitAllDecls); |
| 2596 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2597 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 2598 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2599 | PARSE_LANGOPT(HeinousExtensions); |
| 2600 | PARSE_LANGOPT(Optimize); |
| 2601 | PARSE_LANGOPT(OptimizeSize); |
| 2602 | PARSE_LANGOPT(Static); |
| 2603 | PARSE_LANGOPT(PICLevel); |
| 2604 | PARSE_LANGOPT(GNUInline); |
| 2605 | PARSE_LANGOPT(NoInline); |
| 2606 | PARSE_LANGOPT(AccessControl); |
| 2607 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2608 | PARSE_LANGOPT(ShortWChar); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2609 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2610 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 2611 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2612 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2613 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2614 | PARSE_LANGOPT(OpenCL); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2615 | PARSE_LANGOPT(CatchUndefined); |
| 2616 | // FIXME: Missing ElideConstructors?! |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2617 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2618 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2619 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2620 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2621 | |
| 2622 | return false; |
| 2623 | } |
| 2624 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2625 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2626 | ReadDefinedMacros(); |
| 2627 | } |
| 2628 | |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2629 | void ASTReader::ReadUserDiagnosticMappings(Diagnostic &Diag) { |
| 2630 | unsigned Idx = 0; |
| 2631 | while (Idx < UserDiagMappings.size()) { |
| 2632 | unsigned DiagID = UserDiagMappings[Idx++]; |
| 2633 | unsigned Map = UserDiagMappings[Idx++]; |
| 2634 | Diag.setDiagnosticMappingInternal(DiagID, Map, /*isUser=*/true); |
| 2635 | } |
| 2636 | } |
| 2637 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2638 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2639 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2640 | PerFileData *F = 0; |
| 2641 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2642 | F = Chain[N - I - 1]; |
| 2643 | if (Index < F->LocalNumTypes) |
| 2644 | break; |
| 2645 | Index -= F->LocalNumTypes; |
| 2646 | } |
| 2647 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2648 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2649 | } |
| 2650 | |
| 2651 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2652 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2653 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 2654 | /// routine actually reads the record corresponding to the type at the given |
| 2655 | /// location. It is a helper routine for GetType, which deals with reading type |
| 2656 | /// IDs. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2657 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2658 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2659 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2660 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2661 | // Keep track of where we are in the stream, then jump back there |
| 2662 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2663 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2664 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 2665 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 2666 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2667 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 2668 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2669 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2670 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2671 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2672 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2673 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 2674 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2675 | if (Record.size() != 2) { |
| 2676 | Error("Incorrect encoding of extended qualifier type"); |
| 2677 | return QualType(); |
| 2678 | } |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2679 | QualType Base = GetType(Record[0]); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2680 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 2681 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2682 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2683 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2684 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2685 | if (Record.size() != 1) { |
| 2686 | Error("Incorrect encoding of complex type"); |
| 2687 | return QualType(); |
| 2688 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2689 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2690 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2691 | } |
| 2692 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2693 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2694 | if (Record.size() != 1) { |
| 2695 | Error("Incorrect encoding of pointer type"); |
| 2696 | return QualType(); |
| 2697 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2698 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2699 | return Context->getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2700 | } |
| 2701 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2702 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2703 | if (Record.size() != 1) { |
| 2704 | Error("Incorrect encoding of block pointer type"); |
| 2705 | return QualType(); |
| 2706 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2707 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2708 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2709 | } |
| 2710 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2711 | case TYPE_LVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2712 | if (Record.size() != 1) { |
| 2713 | Error("Incorrect encoding of lvalue reference type"); |
| 2714 | return QualType(); |
| 2715 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2716 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2717 | return Context->getLValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2718 | } |
| 2719 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2720 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2721 | if (Record.size() != 1) { |
| 2722 | Error("Incorrect encoding of rvalue reference type"); |
| 2723 | return QualType(); |
| 2724 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2725 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2726 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2727 | } |
| 2728 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2729 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 2730 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2731 | Error("Incorrect encoding of member pointer type"); |
| 2732 | return QualType(); |
| 2733 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2734 | QualType PointeeType = GetType(Record[0]); |
| 2735 | QualType ClassType = GetType(Record[1]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2736 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2737 | } |
| 2738 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2739 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2740 | QualType ElementType = GetType(Record[0]); |
| 2741 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2742 | unsigned IndexTypeQuals = Record[2]; |
| 2743 | unsigned Idx = 3; |
| 2744 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 2745 | return Context->getConstantArrayType(ElementType, Size, |
| 2746 | ASM, IndexTypeQuals); |
| 2747 | } |
| 2748 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2749 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2750 | QualType ElementType = GetType(Record[0]); |
| 2751 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2752 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2753 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2754 | } |
| 2755 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2756 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2757 | QualType ElementType = GetType(Record[0]); |
| 2758 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2759 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2760 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 2761 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 2762 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 2763 | ASM, IndexTypeQuals, |
| 2764 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2765 | } |
| 2766 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2767 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2768 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2769 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2770 | return QualType(); |
| 2771 | } |
| 2772 | |
| 2773 | QualType ElementType = GetType(Record[0]); |
| 2774 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 2775 | unsigned VecKind = Record[2]; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2776 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 2777 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2778 | } |
| 2779 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2780 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2781 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2782 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2783 | return QualType(); |
| 2784 | } |
| 2785 | |
| 2786 | QualType ElementType = GetType(Record[0]); |
| 2787 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2788 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2789 | } |
| 2790 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2791 | case TYPE_FUNCTION_NO_PROTO: { |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2792 | if (Record.size() != 4) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 2793 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2794 | return QualType(); |
| 2795 | } |
| 2796 | QualType ResultType = GetType(Record[0]); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2797 | FunctionType::ExtInfo Info(Record[1], Record[2], (CallingConv)Record[3]); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 2798 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2799 | } |
| 2800 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2801 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2802 | QualType ResultType = GetType(Record[0]); |
Douglas Gregor | 9123666 | 2009-12-22 18:11:50 +0000 | [diff] [blame] | 2803 | bool NoReturn = Record[1]; |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2804 | unsigned RegParm = Record[2]; |
| 2805 | CallingConv CallConv = (CallingConv)Record[3]; |
| 2806 | unsigned Idx = 4; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2807 | unsigned NumParams = Record[Idx++]; |
| 2808 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 2809 | for (unsigned I = 0; I != NumParams; ++I) |
| 2810 | ParamTypes.push_back(GetType(Record[Idx++])); |
| 2811 | bool isVariadic = Record[Idx++]; |
| 2812 | unsigned Quals = Record[Idx++]; |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 2813 | bool hasExceptionSpec = Record[Idx++]; |
| 2814 | bool hasAnyExceptionSpec = Record[Idx++]; |
| 2815 | unsigned NumExceptions = Record[Idx++]; |
| 2816 | llvm::SmallVector<QualType, 2> Exceptions; |
| 2817 | for (unsigned I = 0; I != NumExceptions; ++I) |
| 2818 | Exceptions.push_back(GetType(Record[Idx++])); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 2819 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 2820 | isVariadic, Quals, hasExceptionSpec, |
| 2821 | hasAnyExceptionSpec, NumExceptions, |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 2822 | Exceptions.data(), |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2823 | FunctionType::ExtInfo(NoReturn, RegParm, |
| 2824 | CallConv)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2827 | case TYPE_UNRESOLVED_USING: |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2828 | return Context->getTypeDeclType( |
| 2829 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 2830 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2831 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2832 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2833 | Error("incorrect encoding of typedef type"); |
| 2834 | return QualType(); |
| 2835 | } |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2836 | TypedefDecl *Decl = cast<TypedefDecl>(GetDecl(Record[0])); |
| 2837 | QualType Canonical = GetType(Record[1]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 2838 | if (!Canonical.isNull()) |
| 2839 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2840 | return Context->getTypedefType(Decl, Canonical); |
| 2841 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2842 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2843 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2844 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2845 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2846 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2847 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2848 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2849 | return QualType(); |
| 2850 | } |
| 2851 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2852 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2853 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2854 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2855 | case TYPE_DECLTYPE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2856 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 2857 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2858 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2859 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2860 | Error("incorrect encoding of record type"); |
| 2861 | return QualType(); |
| 2862 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2863 | bool IsDependent = Record[0]; |
| 2864 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
John McCall | b870b88 | 2010-10-14 21:48:26 +0000 | [diff] [blame] | 2865 | T->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2866 | return T; |
| 2867 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2868 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2869 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2870 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2871 | Error("incorrect encoding of enum type"); |
| 2872 | return QualType(); |
| 2873 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2874 | bool IsDependent = Record[0]; |
| 2875 | QualType T = Context->getEnumType(cast<EnumDecl>(GetDecl(Record[1]))); |
John McCall | b870b88 | 2010-10-14 21:48:26 +0000 | [diff] [blame] | 2876 | T->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2877 | return T; |
| 2878 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2879 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2880 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 2881 | unsigned Idx = 0; |
| 2882 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 2883 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 2884 | QualType NamedType = GetType(Record[Idx++]); |
| 2885 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2886 | } |
| 2887 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2888 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2889 | unsigned Idx = 0; |
| 2890 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2891 | return Context->getObjCInterfaceType(ItfD); |
| 2892 | } |
| 2893 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2894 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2895 | unsigned Idx = 0; |
| 2896 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2897 | unsigned NumProtos = Record[Idx++]; |
| 2898 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 2899 | for (unsigned I = 0; I != NumProtos; ++I) |
| 2900 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2901 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2902 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2903 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2904 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 2905 | unsigned Idx = 0; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2906 | QualType Pointee = GetType(Record[Idx++]); |
| 2907 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 2908 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2909 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2910 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2911 | unsigned Idx = 0; |
| 2912 | QualType Parm = GetType(Record[Idx++]); |
| 2913 | QualType Replacement = GetType(Record[Idx++]); |
| 2914 | return |
| 2915 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 2916 | Replacement); |
| 2917 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2918 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2919 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2920 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 2921 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 2922 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2923 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 2924 | return |
| 2925 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2926 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2927 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2928 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2929 | unsigned Idx = 0; |
| 2930 | unsigned Depth = Record[Idx++]; |
| 2931 | unsigned Index = Record[Idx++]; |
| 2932 | bool Pack = Record[Idx++]; |
| 2933 | IdentifierInfo *Name = GetIdentifierInfo(Record, Idx); |
| 2934 | return Context->getTemplateTypeParmType(Depth, Index, Pack, Name); |
| 2935 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2936 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2937 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 2938 | unsigned Idx = 0; |
| 2939 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 2940 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 2941 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 2942 | QualType Canon = GetType(Record[Idx++]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 2943 | if (!Canon.isNull()) |
| 2944 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 2945 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 2946 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2947 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2948 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 2949 | unsigned Idx = 0; |
| 2950 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 2951 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 2952 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
| 2953 | unsigned NumArgs = Record[Idx++]; |
| 2954 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 2955 | Args.reserve(NumArgs); |
| 2956 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2957 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 2958 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 2959 | Args.size(), Args.data()); |
| 2960 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2961 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2962 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 2963 | unsigned Idx = 0; |
| 2964 | |
| 2965 | // ArrayType |
| 2966 | QualType ElementType = GetType(Record[Idx++]); |
| 2967 | ArrayType::ArraySizeModifier ASM |
| 2968 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 2969 | unsigned IndexTypeQuals = Record[Idx++]; |
| 2970 | |
| 2971 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2972 | Expr *NumElts = ReadExpr(*Loc.F); |
| 2973 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 2974 | |
| 2975 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 2976 | IndexTypeQuals, Brackets); |
| 2977 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 2978 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2979 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2980 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2981 | bool IsDependent = Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2982 | TemplateName Name = ReadTemplateName(Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2983 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2984 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2985 | QualType Canon = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2986 | QualType T; |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2987 | if (Canon.isNull()) |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2988 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 2989 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2990 | else |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2991 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
| 2992 | Args.size(), Canon); |
John McCall | b870b88 | 2010-10-14 21:48:26 +0000 | [diff] [blame] | 2993 | T->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2994 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2995 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2996 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2997 | // Suppress a GCC warning |
| 2998 | return QualType(); |
| 2999 | } |
| 3000 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3001 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3002 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3003 | ASTReader::PerFileData &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3004 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3005 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3006 | unsigned &Idx; |
| 3007 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3008 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3009 | unsigned &I) { |
| 3010 | return Reader.ReadSourceLocation(F, R, I); |
| 3011 | } |
| 3012 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3013 | public: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3014 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3015 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3016 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3017 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3018 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3019 | // We want compile-time assurance that we've enumerated all of |
| 3020 | // these, so unfortunately we have to declare them first, then |
| 3021 | // define them out-of-line. |
| 3022 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3023 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3024 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3025 | #include "clang/AST/TypeLocNodes.def" |
| 3026 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3027 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3028 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3029 | }; |
| 3030 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3031 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3032 | // nothing to do |
| 3033 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3034 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3035 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3036 | if (TL.needsExtraLocalData()) { |
| 3037 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3038 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3039 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3040 | TL.setModeAttr(Record[Idx++]); |
| 3041 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3042 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3043 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3044 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3045 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3046 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3047 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3048 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3049 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3050 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3051 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3052 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3053 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3054 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3055 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3056 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3057 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3058 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3059 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3060 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3061 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3062 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3063 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3064 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3065 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3066 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3067 | TL.setSizeExpr(0); |
| 3068 | } |
| 3069 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3070 | VisitArrayTypeLoc(TL); |
| 3071 | } |
| 3072 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3073 | VisitArrayTypeLoc(TL); |
| 3074 | } |
| 3075 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3076 | VisitArrayTypeLoc(TL); |
| 3077 | } |
| 3078 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3079 | DependentSizedArrayTypeLoc TL) { |
| 3080 | VisitArrayTypeLoc(TL); |
| 3081 | } |
| 3082 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3083 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3084 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3085 | } |
| 3086 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3087 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3088 | } |
| 3089 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3090 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3091 | } |
| 3092 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3093 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3094 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3095 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3096 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | 86acc2a | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 3097 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3098 | } |
| 3099 | } |
| 3100 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3101 | VisitFunctionTypeLoc(TL); |
| 3102 | } |
| 3103 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3104 | VisitFunctionTypeLoc(TL); |
| 3105 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3106 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3107 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3108 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3109 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3110 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3111 | } |
| 3112 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3113 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3114 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3115 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3116 | } |
| 3117 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3118 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3119 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3120 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3121 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3122 | } |
| 3123 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3124 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3125 | } |
| 3126 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3127 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3128 | } |
| 3129 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3130 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3131 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3132 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3133 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3134 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3135 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3136 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3137 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3138 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3139 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3140 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3141 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3142 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3143 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3144 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3145 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3146 | Reader.GetTemplateArgumentLocInfo(F, |
| 3147 | TL.getTypePtr()->getArg(i).getKind(), |
| 3148 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3149 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3150 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3151 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3152 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3153 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3154 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3155 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3156 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3157 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3158 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3159 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3160 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3161 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3162 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3163 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3164 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3165 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3166 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3167 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3168 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3169 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3170 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3171 | Reader.GetTemplateArgumentLocInfo(F, |
| 3172 | TL.getTypePtr()->getArg(I).getKind(), |
| 3173 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3174 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3175 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3176 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3177 | } |
| 3178 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3179 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3180 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3181 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3182 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3183 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3184 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3185 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3186 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3187 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3188 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3189 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3190 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3191 | unsigned &Idx) { |
| 3192 | QualType InfoTy = GetType(Record[Idx++]); |
| 3193 | if (InfoTy.isNull()) |
| 3194 | return 0; |
| 3195 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3196 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3197 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3198 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3199 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3200 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3201 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3202 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3203 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3204 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3205 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3206 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3207 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3208 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3209 | switch ((PredefinedTypeIDs)Index) { |
| 3210 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3211 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3212 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3213 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3214 | case PREDEF_TYPE_CHAR_U_ID: |
| 3215 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3216 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3217 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3218 | break; |
| 3219 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3220 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3221 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3222 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3223 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3224 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3225 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3226 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3227 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3228 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3229 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3230 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3231 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3232 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3233 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3234 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3235 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3236 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
| 3237 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
| 3238 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3239 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3240 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3241 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3242 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3243 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3247 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3248 | } |
| 3249 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3250 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3251 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3252 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3253 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3254 | if (TypesLoaded[Index].isNull()) |
| 3255 | return QualType(); |
| 3256 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3257 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3258 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3259 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3260 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3261 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3262 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3263 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3264 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3265 | } |
| 3266 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3267 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3268 | return MakeTypeID(T, |
| 3269 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3270 | } |
| 3271 | |
| 3272 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3273 | if (T.isNull()) |
| 3274 | return TypeIdx(); |
| 3275 | assert(!T.getLocalFastQualifiers()); |
| 3276 | |
| 3277 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3278 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3279 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3280 | // If the type didn't come from the AST file use a specially marked index |
| 3281 | // so that any hash/key comparison fail since no such index is stored |
| 3282 | // in a AST file. |
| 3283 | if (I == TypeIdxs.end()) |
| 3284 | return TypeIdx(-1); |
| 3285 | return I->second; |
| 3286 | } |
| 3287 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3288 | unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const { |
| 3289 | unsigned Result = 0; |
| 3290 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 3291 | Result += Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3292 | |
| 3293 | return Result; |
| 3294 | } |
| 3295 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3296 | TemplateArgumentLocInfo |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3297 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3298 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3299 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3300 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3301 | switch (Kind) { |
| 3302 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3303 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3304 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3305 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3306 | case TemplateArgument::Template: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3307 | SourceRange QualifierRange = ReadSourceRange(F, Record, Index); |
| 3308 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3309 | return TemplateArgumentLocInfo(QualifierRange, TemplateNameLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3310 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3311 | case TemplateArgument::Null: |
| 3312 | case TemplateArgument::Integral: |
| 3313 | case TemplateArgument::Declaration: |
| 3314 | case TemplateArgument::Pack: |
| 3315 | return TemplateArgumentLocInfo(); |
| 3316 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3317 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3318 | return TemplateArgumentLocInfo(); |
| 3319 | } |
| 3320 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3321 | TemplateArgumentLoc |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3322 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3323 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3324 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3325 | |
| 3326 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3327 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3328 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3329 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3330 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3331 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3332 | } |
| 3333 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3334 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3335 | return GetDecl(ID); |
| 3336 | } |
| 3337 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3338 | uint64_t |
| 3339 | ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) { |
| 3340 | if (ID == 0) |
| 3341 | return 0; |
| 3342 | |
| 3343 | --ID; |
| 3344 | uint64_t Offset = 0; |
| 3345 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3346 | if (ID < Chain[I]->LocalNumCXXBaseSpecifiers) |
| 3347 | return Offset + Chain[I]->CXXBaseSpecifiersOffsets[ID]; |
| 3348 | |
| 3349 | ID -= Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3350 | Offset += Chain[I]->SizeInBits; |
| 3351 | } |
| 3352 | |
| 3353 | assert(false && "CXXBaseSpecifiers not found"); |
| 3354 | return 0; |
| 3355 | } |
| 3356 | |
| 3357 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 3358 | // Figure out which AST file contains this offset. |
| 3359 | PerFileData *F = 0; |
| 3360 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3361 | if (Offset < Chain[I]->SizeInBits) { |
| 3362 | F = Chain[I]; |
| 3363 | break; |
| 3364 | } |
| 3365 | |
| 3366 | Offset -= Chain[I]->SizeInBits; |
| 3367 | } |
| 3368 | |
| 3369 | if (!F) { |
| 3370 | Error("Malformed AST file: C++ base specifiers at impossible offset"); |
| 3371 | return 0; |
| 3372 | } |
| 3373 | |
| 3374 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3375 | SavedStreamPosition SavedPosition(Cursor); |
| 3376 | Cursor.JumpToBit(Offset); |
| 3377 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3378 | RecordData Record; |
| 3379 | unsigned Code = Cursor.ReadCode(); |
| 3380 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 3381 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 3382 | Error("Malformed AST file: missing C++ base specifiers"); |
| 3383 | return 0; |
| 3384 | } |
| 3385 | |
| 3386 | unsigned Idx = 0; |
| 3387 | unsigned NumBases = Record[Idx++]; |
| 3388 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 3389 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 3390 | for (unsigned I = 0; I != NumBases; ++I) |
| 3391 | Bases[I] = ReadCXXBaseSpecifier(*F, Record, Idx); |
| 3392 | return Bases; |
| 3393 | } |
| 3394 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3395 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3396 | if (!DeclsLoaded[0]) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 3397 | ReadDeclRecord(0, 1); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3398 | if (DeserializationListener) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3399 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3400 | } |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 3401 | |
| 3402 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 3403 | } |
| 3404 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3405 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3406 | if (ID == 0) |
| 3407 | return 0; |
| 3408 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3409 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3410 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3411 | return 0; |
| 3412 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3413 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3414 | unsigned Index = ID - 1; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3415 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3416 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3417 | if (DeserializationListener) |
| 3418 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3419 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3420 | |
| 3421 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3422 | } |
| 3423 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3424 | /// \brief Resolve the offset of a statement into a statement. |
| 3425 | /// |
| 3426 | /// This operation will read a new statement from the external |
| 3427 | /// source each time it is called, and is meant to be used via a |
| 3428 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3429 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 3430 | // Switch case IDs are per Decl. |
| 3431 | ClearSwitchCaseIDs(); |
| 3432 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3433 | // Offset here is a global offset across the entire chain. |
| 3434 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3435 | PerFileData &F = *Chain[N - I - 1]; |
| 3436 | if (Offset < F.SizeInBits) { |
| 3437 | // Since we know that this statement is part of a decl, make sure to use |
| 3438 | // the decl cursor to read it. |
| 3439 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3440 | return ReadStmtFromStream(F); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3441 | } |
| 3442 | Offset -= F.SizeInBits; |
| 3443 | } |
| 3444 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 3445 | } |
| 3446 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3447 | bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3448 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3449 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3450 | assert(DC->hasExternalLexicalStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3451 | "DeclContext has no lexical decls in storage"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3452 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3453 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 3454 | // at least. |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3455 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 3456 | // so make a copy of the vector. |
| 3457 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3458 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3459 | I != E; ++I) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3460 | // IDs can be 0 if this context doesn't contain declarations. |
| 3461 | if (!I->LexicalDecls) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3462 | continue; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3463 | |
| 3464 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3465 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 3466 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 3467 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 3468 | continue; |
| 3469 | |
| 3470 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3471 | assert(D && "Null decl in lexical decls"); |
| 3472 | Decls.push_back(D); |
| 3473 | } |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3474 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3475 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3476 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3477 | return false; |
| 3478 | } |
| 3479 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3480 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3481 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3482 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3483 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3484 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3485 | if (!Name) |
| 3486 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 3487 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3488 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3489 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 8b12273 | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 3490 | // 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] | 3491 | // and namespaces. For any given name, the last available results replace |
| 3492 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3493 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3494 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3495 | I != E; ++I) { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3496 | if (!I->NameLookupTableData) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3497 | continue; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3498 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3499 | ASTDeclContextNameLookupTable *LookupTable = |
| 3500 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3501 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 3502 | if (Pos == LookupTable->end()) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3503 | continue; |
| 3504 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3505 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 3506 | for (; Data.first != Data.second; ++Data.first) |
| 3507 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3508 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3509 | } |
| 3510 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3511 | ++NumVisibleDeclContextsRead; |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3512 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3513 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3514 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3515 | } |
| 3516 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 3517 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 3518 | assert(DC->hasExternalVisibleStorage() && |
| 3519 | "DeclContext has no visible decls in storage"); |
| 3520 | |
| 3521 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 3522 | // There might be visible decls in multiple parts of the chain, for the TU |
| 3523 | // and namespaces. |
| 3524 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 3525 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3526 | I != E; ++I) { |
| 3527 | if (!I->NameLookupTableData) |
| 3528 | continue; |
| 3529 | |
| 3530 | ASTDeclContextNameLookupTable *LookupTable = |
| 3531 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3532 | for (ASTDeclContextNameLookupTable::item_iterator |
| 3533 | ItemI = LookupTable->item_begin(), |
| 3534 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 3535 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 3536 | = *ItemI; |
| 3537 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 3538 | Decls.clear(); |
| 3539 | for (; Data.first != Data.second; ++Data.first) |
| 3540 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 3541 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 3542 | } |
| 3543 | } |
| 3544 | } |
| 3545 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3546 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3547 | assert(Consumer); |
| 3548 | while (!InterestingDecls.empty()) { |
| 3549 | DeclGroupRef DG(InterestingDecls.front()); |
| 3550 | InterestingDecls.pop_front(); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3551 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3552 | } |
| 3553 | } |
| 3554 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3555 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 3556 | this->Consumer = Consumer; |
| 3557 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3558 | if (!Consumer) |
| 3559 | return; |
| 3560 | |
| 3561 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3562 | // Force deserialization of this decl, which will cause it to be queued for |
| 3563 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 3564 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3565 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 3566 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3567 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3568 | } |
| 3569 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3570 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3571 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3572 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3573 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3574 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3575 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3576 | unsigned NumDeclsLoaded |
| 3577 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 3578 | (Decl *)0); |
| 3579 | unsigned NumIdentifiersLoaded |
| 3580 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 3581 | IdentifiersLoaded.end(), |
| 3582 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3583 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3584 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 3585 | SelectorsLoaded.end(), |
| 3586 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 3587 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3588 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 3589 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 3590 | if (TotalNumSLocEntries) |
| 3591 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 3592 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 3593 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3594 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3595 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3596 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 3597 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 3598 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3599 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3600 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 3601 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3602 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3603 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3604 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 3605 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3606 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3607 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3608 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 3609 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3610 | if (TotalNumStatements) |
| 3611 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 3612 | NumStatementsRead, TotalNumStatements, |
| 3613 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 3614 | if (TotalNumMacros) |
| 3615 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 3616 | NumMacrosRead, TotalNumMacros, |
| 3617 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 3618 | if (TotalLexicalDeclContexts) |
| 3619 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 3620 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 3621 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 3622 | * 100)); |
| 3623 | if (TotalVisibleDeclContexts) |
| 3624 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 3625 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 3626 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 3627 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3628 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3629 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3630 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 3631 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3632 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3633 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3634 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3635 | std::fprintf(stderr, "\n"); |
| 3636 | } |
| 3637 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3638 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3639 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3640 | S.ExternalSource = this; |
| 3641 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 3642 | // Makes sure any declarations that were deserialized "too early" |
| 3643 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3644 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 3645 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 3646 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3647 | |
| 3648 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3649 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 3650 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3651 | |
| 3652 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 3653 | // them to Sema's list of tentative definitions. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3654 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 3655 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 3656 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3657 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 3658 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3659 | // If there were any unused file scoped decls, deserialize them and add to |
| 3660 | // Sema's list of unused file scoped decls. |
| 3661 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 3662 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 3663 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 3664 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3665 | |
| 3666 | // If there were any locally-scoped external declarations, |
| 3667 | // deserialize them and add them to Sema's table of locally-scoped |
| 3668 | // external declarations. |
| 3669 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 3670 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 3671 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 3672 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3673 | |
| 3674 | // If there were any ext_vector type declarations, deserialize them |
| 3675 | // and add them to Sema's vector of such declarations. |
| 3676 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 3677 | SemaObj->ExtVectorDecls.push_back( |
| 3678 | cast<TypedefDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3679 | |
| 3680 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 3681 | // Can we cut them down before writing them ? |
| 3682 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3683 | // If there were any dynamic classes declarations, deserialize them |
| 3684 | // and add them to Sema's vector of such declarations. |
| 3685 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 3686 | SemaObj->DynamicClasses.push_back( |
| 3687 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3688 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3689 | // Load the offsets of the declarations that Sema references. |
| 3690 | // They will be lazily deserialized when needed. |
| 3691 | if (!SemaDeclRefs.empty()) { |
| 3692 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 3693 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 3694 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 3695 | } |
| 3696 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3697 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 3698 | |
| 3699 | // If there are @selector references added them to its pool. This is for |
| 3700 | // implementation of -Wselector. |
| 3701 | if (!F->ReferencedSelectorsData.empty()) { |
| 3702 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 3703 | unsigned I = 0; |
| 3704 | while (I < DataSize) { |
| 3705 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 3706 | SourceLocation SelLoc = ReadSourceLocation( |
| 3707 | *F, F->ReferencedSelectorsData, I); |
| 3708 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 3709 | } |
| 3710 | } |
| 3711 | |
| 3712 | // If there were any pending implicit instantiations, deserialize them |
| 3713 | // and add them to Sema's queue of such instantiations. |
| 3714 | assert(F->PendingInstantiations.size() % 2 == 0 && |
| 3715 | "Expected pairs of entries"); |
| 3716 | for (unsigned Idx = 0, N = F->PendingInstantiations.size(); Idx < N;) { |
| 3717 | ValueDecl *D=cast<ValueDecl>(GetDecl(F->PendingInstantiations[Idx++])); |
| 3718 | SourceLocation Loc = ReadSourceLocation(*F, F->PendingInstantiations,Idx); |
| 3719 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 3720 | } |
| 3721 | } |
| 3722 | |
| 3723 | // The two special data sets below always come from the most recent PCH, |
| 3724 | // which is at the front of the chain. |
| 3725 | PerFileData &F = *Chain.front(); |
| 3726 | |
| 3727 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 3728 | // Sema's list of weak undeclared identifiers. |
| 3729 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 3730 | unsigned Idx = 0; |
| 3731 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 3732 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 3733 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 3734 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 3735 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 3736 | Sema::WeakInfo WI(AliasId, Loc); |
| 3737 | WI.setUsed(Used); |
| 3738 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 3739 | } |
| 3740 | } |
| 3741 | |
| 3742 | // If there were any VTable uses, deserialize the information and add it |
| 3743 | // to Sema's vector and map of VTable uses. |
| 3744 | if (!VTableUses.empty()) { |
| 3745 | unsigned Idx = 0; |
| 3746 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 3747 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 3748 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 3749 | bool DefinitionRequired = VTableUses[Idx++]; |
| 3750 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 3751 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3752 | } |
| 3753 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3754 | } |
| 3755 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3756 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3757 | // Try to find this name within our on-disk hash tables. We start with the |
| 3758 | // 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] | 3759 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3760 | ASTIdentifierLookupTable *IdTable |
| 3761 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3762 | if (!IdTable) |
| 3763 | continue; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3764 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3765 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3766 | if (Pos == IdTable->end()) |
| 3767 | continue; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3768 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3769 | // Dereferencing the iterator has the effect of building the |
| 3770 | // IdentifierInfo node and populating it with the various |
| 3771 | // declarations it needs. |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3772 | return *Pos; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3773 | } |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3774 | return 0; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3775 | } |
| 3776 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 3777 | namespace clang { |
| 3778 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 3779 | /// identifiers stored within a set of AST files. |
| 3780 | class ASTIdentifierIterator : public IdentifierIterator { |
| 3781 | /// \brief The AST reader whose identifiers are being enumerated. |
| 3782 | const ASTReader &Reader; |
| 3783 | |
| 3784 | /// \brief The current index into the chain of AST files stored in |
| 3785 | /// the AST reader. |
| 3786 | unsigned Index; |
| 3787 | |
| 3788 | /// \brief The current position within the identifier lookup table |
| 3789 | /// of the current AST file. |
| 3790 | ASTIdentifierLookupTable::key_iterator Current; |
| 3791 | |
| 3792 | /// \brief The end position within the identifier lookup table of |
| 3793 | /// the current AST file. |
| 3794 | ASTIdentifierLookupTable::key_iterator End; |
| 3795 | |
| 3796 | public: |
| 3797 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 3798 | |
| 3799 | virtual llvm::StringRef Next(); |
| 3800 | }; |
| 3801 | } |
| 3802 | |
| 3803 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 3804 | : Reader(Reader), Index(Reader.Chain.size() - 1) { |
| 3805 | ASTIdentifierLookupTable *IdTable |
| 3806 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 3807 | Current = IdTable->key_begin(); |
| 3808 | End = IdTable->key_end(); |
| 3809 | } |
| 3810 | |
| 3811 | llvm::StringRef ASTIdentifierIterator::Next() { |
| 3812 | while (Current == End) { |
| 3813 | // If we have exhausted all of our AST files, we're done. |
| 3814 | if (Index == 0) |
| 3815 | return llvm::StringRef(); |
| 3816 | |
| 3817 | --Index; |
| 3818 | ASTIdentifierLookupTable *IdTable |
| 3819 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 3820 | Current = IdTable->key_begin(); |
| 3821 | End = IdTable->key_end(); |
| 3822 | } |
| 3823 | |
| 3824 | // We have any identifiers remaining in the current AST file; return |
| 3825 | // the next one. |
| 3826 | std::pair<const char*, unsigned> Key = *Current; |
| 3827 | ++Current; |
| 3828 | return llvm::StringRef(Key.first, Key.second); |
| 3829 | } |
| 3830 | |
| 3831 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 3832 | return new ASTIdentifierIterator(*this); |
| 3833 | } |
| 3834 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3835 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3836 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3837 | // Find this selector in a hash table. We want to find the most recent entry. |
| 3838 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3839 | PerFileData &F = *Chain[I]; |
| 3840 | if (!F.SelectorLookupTable) |
| 3841 | continue; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3842 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3843 | ASTSelectorLookupTable *PoolTable |
| 3844 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 3845 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3846 | if (Pos != PoolTable->end()) { |
| 3847 | ++NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3848 | // FIXME: Not quite happy with the statistics here. We probably should |
| 3849 | // disable this tracking when called via LoadSelector. |
| 3850 | // Also, should entries without methods count as misses? |
| 3851 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3852 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3853 | if (DeserializationListener) |
| 3854 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 3855 | return std::make_pair(Data.Instance, Data.Factory); |
| 3856 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3857 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3858 | |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3859 | ++NumMethodPoolMisses; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3860 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3861 | } |
| 3862 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3863 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3864 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 3865 | ReadMethodPool(Sel); |
| 3866 | } |
| 3867 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3868 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3869 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3870 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3871 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3872 | if (DeserializationListener) |
| 3873 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3874 | } |
| 3875 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3876 | /// \brief Set the globally-visible declarations associated with the given |
| 3877 | /// identifier. |
| 3878 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3879 | /// 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] | 3880 | /// 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] | 3881 | /// them. |
| 3882 | /// |
| 3883 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 3884 | /// declarations. |
| 3885 | /// |
| 3886 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 3887 | /// visible at global scope. |
| 3888 | /// |
| 3889 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 3890 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 3891 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3892 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3893 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3894 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 3895 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3896 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3897 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 3898 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 3899 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 3900 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3901 | return; |
| 3902 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3903 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3904 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 3905 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 3906 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 3907 | if (SemaObj->TUScope) { |
| 3908 | // Introduce this declaration into the translation-unit scope |
| 3909 | // and add it to the declaration chain for this identifier, so |
| 3910 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 3911 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 3912 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3913 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3914 | } else { |
| 3915 | // Queue this declaration so that it will be added to the |
| 3916 | // translation unit scope and identifier's declaration chain |
| 3917 | // once a Sema object is known. |
| 3918 | PreloadedDecls.push_back(D); |
| 3919 | } |
| 3920 | } |
| 3921 | } |
| 3922 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3923 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3924 | if (ID == 0) |
| 3925 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3926 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3927 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3928 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3929 | return 0; |
| 3930 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3931 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3932 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3933 | ID -= 1; |
| 3934 | if (!IdentifiersLoaded[ID]) { |
| 3935 | unsigned Index = ID; |
| 3936 | const char *Str = 0; |
| 3937 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3938 | PerFileData *F = Chain[N - I - 1]; |
| 3939 | if (Index < F->LocalNumIdentifiers) { |
| 3940 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 3941 | Str = F->IdentifierTableData + Offset; |
| 3942 | break; |
| 3943 | } |
| 3944 | Index -= F->LocalNumIdentifiers; |
| 3945 | } |
| 3946 | assert(Str && "Broken Chain"); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 3947 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3948 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 3949 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 3950 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 3951 | // unsigned integers. This is important to avoid integer overflow when |
| 3952 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 3953 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3954 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 3955 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3956 | IdentifiersLoaded[ID] |
Kovarththanan Rajaratnam | 811f426 | 2010-03-12 10:32:27 +0000 | [diff] [blame] | 3957 | = &PP->getIdentifierTable().get(Str, StrLen); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3958 | if (DeserializationListener) |
| 3959 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3960 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3961 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3962 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3963 | } |
| 3964 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3965 | void ASTReader::ReadSLocEntry(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 3966 | ReadSLocEntryRecord(ID); |
| 3967 | } |
| 3968 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3969 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3970 | if (ID == 0) |
| 3971 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3973 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3974 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3975 | return Selector(); |
| 3976 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3977 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3978 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3979 | // Load this selector from the selector table. |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3980 | unsigned Idx = ID - 1; |
| 3981 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3982 | PerFileData &F = *Chain[N - I - 1]; |
| 3983 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3984 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3985 | SelectorsLoaded[ID - 1] = |
| 3986 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 3987 | if (DeserializationListener) |
| 3988 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 3989 | break; |
| 3990 | } |
| 3991 | Idx -= F.LocalNumSelectors; |
| 3992 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3993 | } |
| 3994 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3995 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3996 | } |
| 3997 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3998 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 3999 | return DecodeSelector(ID); |
| 4000 | } |
| 4001 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4002 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4003 | // ID 0 (the null selector) is considered an external selector. |
| 4004 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4005 | } |
| 4006 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4007 | DeclarationName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4008 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4009 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4010 | switch (Kind) { |
| 4011 | case DeclarationName::Identifier: |
| 4012 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 4013 | |
| 4014 | case DeclarationName::ObjCZeroArgSelector: |
| 4015 | case DeclarationName::ObjCOneArgSelector: |
| 4016 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 4017 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4018 | |
| 4019 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4020 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4021 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4022 | |
| 4023 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4024 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4025 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4026 | |
| 4027 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4028 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4029 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4030 | |
| 4031 | case DeclarationName::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4032 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4033 | (OverloadedOperatorKind)Record[Idx++]); |
| 4034 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4035 | case DeclarationName::CXXLiteralOperatorName: |
| 4036 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 4037 | GetIdentifierInfo(Record, Idx)); |
| 4038 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4039 | case DeclarationName::CXXUsingDirective: |
| 4040 | return DeclarationName::getUsingDirectiveName(); |
| 4041 | } |
| 4042 | |
| 4043 | // Required to silence GCC warning |
| 4044 | return DeclarationName(); |
| 4045 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4046 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4047 | void ASTReader::ReadDeclarationNameLoc(PerFileData &F, |
| 4048 | DeclarationNameLoc &DNLoc, |
| 4049 | DeclarationName Name, |
| 4050 | const RecordData &Record, unsigned &Idx) { |
| 4051 | switch (Name.getNameKind()) { |
| 4052 | case DeclarationName::CXXConstructorName: |
| 4053 | case DeclarationName::CXXDestructorName: |
| 4054 | case DeclarationName::CXXConversionFunctionName: |
| 4055 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4056 | break; |
| 4057 | |
| 4058 | case DeclarationName::CXXOperatorName: |
| 4059 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4060 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4061 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4062 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4063 | break; |
| 4064 | |
| 4065 | case DeclarationName::CXXLiteralOperatorName: |
| 4066 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4067 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4068 | break; |
| 4069 | |
| 4070 | case DeclarationName::Identifier: |
| 4071 | case DeclarationName::ObjCZeroArgSelector: |
| 4072 | case DeclarationName::ObjCOneArgSelector: |
| 4073 | case DeclarationName::ObjCMultiArgSelector: |
| 4074 | case DeclarationName::CXXUsingDirective: |
| 4075 | break; |
| 4076 | } |
| 4077 | } |
| 4078 | |
| 4079 | void ASTReader::ReadDeclarationNameInfo(PerFileData &F, |
| 4080 | DeclarationNameInfo &NameInfo, |
| 4081 | const RecordData &Record, unsigned &Idx) { |
| 4082 | NameInfo.setName(ReadDeclarationName(Record, Idx)); |
| 4083 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4084 | DeclarationNameLoc DNLoc; |
| 4085 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4086 | NameInfo.setInfo(DNLoc); |
| 4087 | } |
| 4088 | |
| 4089 | void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info, |
| 4090 | const RecordData &Record, unsigned &Idx) { |
| 4091 | Info.NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4092 | Info.NNSRange = ReadSourceRange(F, Record, Idx); |
| 4093 | unsigned NumTPLists = Record[Idx++]; |
| 4094 | Info.NumTemplParamLists = NumTPLists; |
| 4095 | if (NumTPLists) { |
| 4096 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 4097 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4098 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4099 | } |
| 4100 | } |
| 4101 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4102 | TemplateName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4103 | ASTReader::ReadTemplateName(const RecordData &Record, unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4104 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4105 | switch (Kind) { |
| 4106 | case TemplateName::Template: |
| 4107 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 4108 | |
| 4109 | case TemplateName::OverloadedTemplate: { |
| 4110 | unsigned size = Record[Idx++]; |
| 4111 | UnresolvedSet<8> Decls; |
| 4112 | while (size--) |
| 4113 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 4114 | |
| 4115 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 4116 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4117 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4118 | case TemplateName::QualifiedTemplate: { |
| 4119 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4120 | bool hasTemplKeyword = Record[Idx++]; |
| 4121 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 4122 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 4123 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4124 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4125 | case TemplateName::DependentTemplate: { |
| 4126 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4127 | if (Record[Idx++]) // isIdentifier |
| 4128 | return Context->getDependentTemplateName(NNS, |
| 4129 | GetIdentifierInfo(Record, Idx)); |
| 4130 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4131 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4132 | } |
| 4133 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4134 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4135 | assert(0 && "Unhandled template name kind!"); |
| 4136 | return TemplateName(); |
| 4137 | } |
| 4138 | |
| 4139 | TemplateArgument |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4140 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4141 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4142 | switch ((TemplateArgument::ArgKind)Record[Idx++]) { |
| 4143 | case TemplateArgument::Null: |
| 4144 | return TemplateArgument(); |
| 4145 | case TemplateArgument::Type: |
| 4146 | return TemplateArgument(GetType(Record[Idx++])); |
| 4147 | case TemplateArgument::Declaration: |
| 4148 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4149 | case TemplateArgument::Integral: { |
| 4150 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 4151 | QualType T = GetType(Record[Idx++]); |
| 4152 | return TemplateArgument(Value, T); |
| 4153 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4154 | case TemplateArgument::Template: |
| 4155 | return TemplateArgument(ReadTemplateName(Record, Idx)); |
| 4156 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4157 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4158 | case TemplateArgument::Pack: { |
| 4159 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4160 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 4161 | for (unsigned I = 0; I != NumArgs; ++I) |
| 4162 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 4163 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4164 | } |
| 4165 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4166 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4167 | assert(0 && "Unhandled template argument kind!"); |
| 4168 | return TemplateArgument(); |
| 4169 | } |
| 4170 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4171 | TemplateParameterList * |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4172 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 4173 | const RecordData &Record, unsigned &Idx) { |
| 4174 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 4175 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 4176 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4177 | |
| 4178 | unsigned NumParams = Record[Idx++]; |
| 4179 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 4180 | Params.reserve(NumParams); |
| 4181 | while (NumParams--) |
| 4182 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4183 | |
| 4184 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4185 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 4186 | Params.data(), Params.size(), RAngleLoc); |
| 4187 | return TemplateParams; |
| 4188 | } |
| 4189 | |
| 4190 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4191 | ASTReader:: |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4192 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4193 | PerFileData &F, const RecordData &Record, |
| 4194 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4195 | unsigned NumTemplateArgs = Record[Idx++]; |
| 4196 | TemplArgs.reserve(NumTemplateArgs); |
| 4197 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4198 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4199 | } |
| 4200 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4201 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4202 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4203 | const RecordData &Record, unsigned &Idx) { |
| 4204 | unsigned NumDecls = Record[Idx++]; |
| 4205 | while (NumDecls--) { |
| 4206 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 4207 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 4208 | Set.addDecl(D, AS); |
| 4209 | } |
| 4210 | } |
| 4211 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4212 | CXXBaseSpecifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4213 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4214 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4215 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 4216 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 4217 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4218 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4219 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4220 | return CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, TInfo); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4221 | } |
| 4222 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4223 | std::pair<CXXBaseOrMemberInitializer **, unsigned> |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4224 | ASTReader::ReadCXXBaseOrMemberInitializers(PerFileData &F, |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4225 | const RecordData &Record, |
| 4226 | unsigned &Idx) { |
| 4227 | CXXBaseOrMemberInitializer **BaseOrMemberInitializers = 0; |
| 4228 | unsigned NumInitializers = Record[Idx++]; |
| 4229 | if (NumInitializers) { |
| 4230 | ASTContext &C = *getContext(); |
| 4231 | |
| 4232 | BaseOrMemberInitializers |
| 4233 | = new (C) CXXBaseOrMemberInitializer*[NumInitializers]; |
| 4234 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 4235 | TypeSourceInfo *BaseClassInfo = 0; |
| 4236 | bool IsBaseVirtual = false; |
| 4237 | FieldDecl *Member = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4238 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4239 | bool IsBaseInitializer = Record[Idx++]; |
| 4240 | if (IsBaseInitializer) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4241 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4242 | IsBaseVirtual = Record[Idx++]; |
| 4243 | } else { |
| 4244 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
| 4245 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4246 | SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx); |
| 4247 | Expr *Init = ReadExpr(F); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4248 | FieldDecl *AnonUnionMember |
| 4249 | = cast_or_null<FieldDecl>(GetDecl(Record[Idx++])); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4250 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 4251 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4252 | bool IsWritten = Record[Idx++]; |
| 4253 | unsigned SourceOrderOrNumArrayIndices; |
| 4254 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 4255 | if (IsWritten) { |
| 4256 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4257 | } else { |
| 4258 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4259 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 4260 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 4261 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 4262 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4263 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4264 | CXXBaseOrMemberInitializer *BOMInit; |
| 4265 | if (IsBaseInitializer) { |
| 4266 | BOMInit = new (C) CXXBaseOrMemberInitializer(C, BaseClassInfo, |
| 4267 | IsBaseVirtual, LParenLoc, |
| 4268 | Init, RParenLoc); |
| 4269 | } else if (IsWritten) { |
| 4270 | BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc, |
| 4271 | LParenLoc, Init, RParenLoc); |
| 4272 | } else { |
| 4273 | BOMInit = CXXBaseOrMemberInitializer::Create(C, Member, MemberLoc, |
| 4274 | LParenLoc, Init, RParenLoc, |
| 4275 | Indices.data(), |
| 4276 | Indices.size()); |
| 4277 | } |
| 4278 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 4279 | if (IsWritten) |
| 4280 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4281 | BOMInit->setAnonUnionMember(AnonUnionMember); |
| 4282 | BaseOrMemberInitializers[i] = BOMInit; |
| 4283 | } |
| 4284 | } |
| 4285 | |
| 4286 | return std::make_pair(BaseOrMemberInitializers, NumInitializers); |
| 4287 | } |
| 4288 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4289 | NestedNameSpecifier * |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4290 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4291 | unsigned N = Record[Idx++]; |
| 4292 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 4293 | for (unsigned I = 0; I != N; ++I) { |
| 4294 | NestedNameSpecifier::SpecifierKind Kind |
| 4295 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4296 | switch (Kind) { |
| 4297 | case NestedNameSpecifier::Identifier: { |
| 4298 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 4299 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 4300 | break; |
| 4301 | } |
| 4302 | |
| 4303 | case NestedNameSpecifier::Namespace: { |
| 4304 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 4305 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 4306 | break; |
| 4307 | } |
| 4308 | |
| 4309 | case NestedNameSpecifier::TypeSpec: |
| 4310 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 4311 | Type *T = GetType(Record[Idx++]).getTypePtr(); |
| 4312 | bool Template = Record[Idx++]; |
| 4313 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 4314 | break; |
| 4315 | } |
| 4316 | |
| 4317 | case NestedNameSpecifier::Global: { |
| 4318 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4319 | // No associated value, and there can't be a prefix. |
| 4320 | break; |
| 4321 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4322 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 4323 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4324 | } |
| 4325 | return NNS; |
| 4326 | } |
| 4327 | |
| 4328 | SourceRange |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4329 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 4330 | unsigned &Idx) { |
| 4331 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 4332 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 4333 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4334 | } |
| 4335 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4336 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4337 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4338 | unsigned BitWidth = Record[Idx++]; |
| 4339 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 4340 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 4341 | Idx += NumWords; |
| 4342 | return Result; |
| 4343 | } |
| 4344 | |
| 4345 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4346 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4347 | bool isUnsigned = Record[Idx++]; |
| 4348 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 4349 | } |
| 4350 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4351 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4352 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4353 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 4354 | } |
| 4355 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4356 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4357 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4358 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 4359 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4360 | Idx += Len; |
| 4361 | return Result; |
| 4362 | } |
| 4363 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4364 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4365 | unsigned &Idx) { |
| 4366 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 4367 | return CXXTemporary::Create(*Context, Decl); |
| 4368 | } |
| 4369 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4370 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 4371 | return Diag(SourceLocation(), DiagID); |
| 4372 | } |
| 4373 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4374 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4375 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4376 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4377 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4378 | /// \brief Retrieve the identifier table associated with the |
| 4379 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4380 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4381 | assert(PP && "Forgot to set Preprocessor ?"); |
| 4382 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4383 | } |
| 4384 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4385 | /// \brief Record that the given ID maps to the given switch-case |
| 4386 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4387 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4388 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 4389 | SwitchCaseStmts[ID] = SC; |
| 4390 | } |
| 4391 | |
| 4392 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4393 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4394 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 4395 | return SwitchCaseStmts[ID]; |
| 4396 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4397 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4398 | void ASTReader::ClearSwitchCaseIDs() { |
| 4399 | SwitchCaseStmts.clear(); |
| 4400 | } |
| 4401 | |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4402 | /// \brief Record that the given label statement has been |
| 4403 | /// deserialized and has the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4404 | void ASTReader::RecordLabelStmt(LabelStmt *S, unsigned ID) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4405 | assert(LabelStmts.find(ID) == LabelStmts.end() && |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4406 | "Deserialized label twice"); |
| 4407 | LabelStmts[ID] = S; |
| 4408 | |
| 4409 | // If we've already seen any goto statements that point to this |
| 4410 | // label, resolve them now. |
| 4411 | typedef std::multimap<unsigned, GotoStmt *>::iterator GotoIter; |
| 4412 | std::pair<GotoIter, GotoIter> Gotos = UnresolvedGotoStmts.equal_range(ID); |
| 4413 | for (GotoIter Goto = Gotos.first; Goto != Gotos.second; ++Goto) |
| 4414 | Goto->second->setLabel(S); |
| 4415 | UnresolvedGotoStmts.erase(Gotos.first, Gotos.second); |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4416 | |
| 4417 | // If we've already seen any address-label statements that point to |
| 4418 | // this label, resolve them now. |
| 4419 | typedef std::multimap<unsigned, AddrLabelExpr *>::iterator AddrLabelIter; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4420 | std::pair<AddrLabelIter, AddrLabelIter> AddrLabels |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4421 | = UnresolvedAddrLabelExprs.equal_range(ID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4422 | for (AddrLabelIter AddrLabel = AddrLabels.first; |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4423 | AddrLabel != AddrLabels.second; ++AddrLabel) |
| 4424 | AddrLabel->second->setLabel(S); |
| 4425 | UnresolvedAddrLabelExprs.erase(AddrLabels.first, AddrLabels.second); |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4426 | } |
| 4427 | |
| 4428 | /// \brief Set the label of the given statement to the label |
| 4429 | /// identified by ID. |
| 4430 | /// |
| 4431 | /// Depending on the order in which the label and other statements |
| 4432 | /// referencing that label occur, this operation may complete |
| 4433 | /// immediately (updating the statement) or it may queue the |
| 4434 | /// statement to be back-patched later. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4435 | void ASTReader::SetLabelOf(GotoStmt *S, unsigned ID) { |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4436 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 4437 | if (Label != LabelStmts.end()) { |
| 4438 | // We've already seen this label, so set the label of the goto and |
| 4439 | // we're done. |
| 4440 | S->setLabel(Label->second); |
| 4441 | } else { |
| 4442 | // We haven't seen this label yet, so add this goto to the set of |
| 4443 | // unresolved goto statements. |
| 4444 | UnresolvedGotoStmts.insert(std::make_pair(ID, S)); |
| 4445 | } |
| 4446 | } |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4447 | |
| 4448 | /// \brief Set the label of the given expression to the label |
| 4449 | /// identified by ID. |
| 4450 | /// |
| 4451 | /// Depending on the order in which the label and other statements |
| 4452 | /// referencing that label occur, this operation may complete |
| 4453 | /// immediately (updating the statement) or it may queue the |
| 4454 | /// statement to be back-patched later. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4455 | void ASTReader::SetLabelOf(AddrLabelExpr *S, unsigned ID) { |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4456 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 4457 | if (Label != LabelStmts.end()) { |
| 4458 | // We've already seen this label, so set the label of the |
| 4459 | // label-address expression and we're done. |
| 4460 | S->setLabel(Label->second); |
| 4461 | } else { |
| 4462 | // We haven't seen this label yet, so add this label-address |
| 4463 | // expression to the set of unresolved label-address expressions. |
| 4464 | UnresolvedAddrLabelExprs.insert(std::make_pair(ID, S)); |
| 4465 | } |
| 4466 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4467 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4468 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4469 | assert(NumCurrentElementsDeserializing && |
| 4470 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 4471 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4472 | // If any identifiers with corresponding top-level declarations have |
| 4473 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4474 | while (!PendingIdentifierInfos.empty()) { |
| 4475 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 4476 | PendingIdentifierInfos.front().DeclIDs, true); |
| 4477 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4478 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4479 | |
| 4480 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 4481 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4482 | if (Consumer) |
| 4483 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 4484 | |
| 4485 | assert(PendingForwardRefs.size() == 0 && |
| 4486 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4487 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4488 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4489 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4490 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4491 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
| 4492 | const char *isysroot, bool DisableValidation) |
| 4493 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 4494 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 4495 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
| 4496 | Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), |
| 4497 | NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4498 | TotalNumSLocEntries(0), NextSLocOffset(0), NumStatementsRead(0), |
| 4499 | TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), |
| 4500 | NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4501 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4502 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4503 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
| 4504 | RelocatablePCH = false; |
| 4505 | } |
| 4506 | |
| 4507 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 4508 | Diagnostic &Diags, const char *isysroot, |
| 4509 | bool DisableValidation) |
| 4510 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
| 4511 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), |
| 4512 | isysroot(isysroot), DisableValidation(DisableValidation), NumStatHits(0), |
| 4513 | NumStatMisses(0), NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4514 | NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0), |
| 4515 | NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), |
| 4516 | NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
| 4517 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4518 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4519 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4520 | RelocatablePCH = false; |
| 4521 | } |
| 4522 | |
| 4523 | ASTReader::~ASTReader() { |
| 4524 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 4525 | delete Chain[e - i - 1]; |
| 4526 | // Delete all visible decl lookup tables |
| 4527 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 4528 | E = DeclContextOffsets.end(); |
| 4529 | I != E; ++I) { |
| 4530 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 4531 | J != F; ++J) { |
| 4532 | if (J->NameLookupTableData) |
| 4533 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 4534 | J->NameLookupTableData); |
| 4535 | } |
| 4536 | } |
| 4537 | for (DeclContextVisibleUpdatesPending::iterator |
| 4538 | I = PendingVisibleUpdates.begin(), |
| 4539 | E = PendingVisibleUpdates.end(); |
| 4540 | I != E; ++I) { |
| 4541 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 4542 | F = I->second.end(); |
| 4543 | J != F; ++J) |
| 4544 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 4545 | } |
| 4546 | } |
| 4547 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 4548 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
| 4549 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 4550 | LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), |
| 4551 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
| 4552 | MacroDefinitionOffsets(0), LocalNumSelectors(0), SelectorOffsets(0), |
| 4553 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4554 | DeclOffsets(0), LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
| 4555 | LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 4556 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4557 | {} |
| 4558 | |
| 4559 | ASTReader::PerFileData::~PerFileData() { |
| 4560 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
| 4561 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 4562 | } |
| 4563 | |