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