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