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