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