Sebastian Redl | 904c9c8 | 2010-08-18 23:57:11 +0000 | [diff] [blame] | 1 | //===--- ASTReader.cpp - AST File Reader ------------------------*- C++ -*-===// |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 10 | // This file defines the ASTReader class, which reads AST files. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 13 | |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTReader.h" |
| 15 | #include "clang/Serialization/ASTDeserializationListener.h" |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 16 | #include "ASTCommon.h" |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 17 | #include "clang/Frontend/FrontendDiagnostic.h" |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/Utils.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 19 | #include "clang/Sema/Sema.h" |
John McCall | 5f1e094 | 2010-08-24 08:50:51 +0000 | [diff] [blame] | 20 | #include "clang/Sema/Scope.h" |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 21 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 22 | #include "clang/AST/ASTContext.h" |
John McCall | 2a7fb27 | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 24 | #include "clang/AST/Expr.h" |
John McCall | 7a1fad3 | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 26 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 27 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 28 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 29 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 30 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 31 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 32 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 33 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 34 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 35 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 36 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 37 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 38 | #include "clang/Basic/Version.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 39 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 40 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 41 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 42 | #include "llvm/Support/ErrorHandling.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 43 | #include "llvm/Support/Path.h" |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 44 | #include "llvm/Support/system_error.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 45 | #include <algorithm> |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 46 | #include <iterator> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 47 | #include <cstdio> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 48 | #include <sys/stat.h> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 49 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 50 | using namespace clang::serialization; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 51 | |
| 52 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 53 | // PCH validator implementation |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 54 | //===----------------------------------------------------------------------===// |
| 55 | |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 56 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 57 | |
| 58 | bool |
| 59 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 60 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 61 | #define PARSE_LANGOPT_BENIGN(Option) |
| 62 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 63 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 64 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 65 | return true; \ |
| 66 | } |
| 67 | |
| 68 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 69 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 70 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 71 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 72 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 73 | PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 74 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 75 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 76 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 77 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
| 78 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 79 | PARSE_LANGOPT_BENIGN(MSCVersion); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 80 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 81 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 82 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 83 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 84 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 85 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 86 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 87 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 88 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 89 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 90 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 91 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 92 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 93 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 94 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 95 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 96 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 97 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 98 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 99 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 100 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 101 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 102 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 103 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 104 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 105 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 106 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 107 | diag::warn_pch_heinous_extensions); |
| 108 | // FIXME: Most of the options below are benign if the macro wasn't |
| 109 | // used. Unfortunately, this means that a PCH compiled without |
| 110 | // optimization can't be used with optimization turned on, even |
| 111 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 112 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 113 | // doesn't matter. We could consider making this some special kind |
| 114 | // of check. |
| 115 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 116 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 117 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 118 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 119 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 120 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
| 121 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 122 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 123 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 124 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 125 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 126 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 127 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 128 | return true; |
| 129 | } |
| 130 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 131 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 132 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 133 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 134 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 135 | PARSE_LANGOPT_IMPORTANT(CUDA, diag::warn_pch_cuda); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 136 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 137 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 138 | PARSE_LANGOPT_BENIGN(SpellChecking); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 139 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 140 | #undef PARSE_LANGOPT_BENIGN |
| 141 | |
| 142 | return false; |
| 143 | } |
| 144 | |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 145 | bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) { |
| 146 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 147 | return false; |
| 148 | |
| 149 | Reader.Diag(diag::warn_pch_target_triple) |
| 150 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 151 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 154 | namespace { |
| 155 | struct EmptyStringRef { |
| 156 | bool operator ()(llvm::StringRef r) const { return r.empty(); } |
| 157 | }; |
| 158 | struct EmptyBlock { |
| 159 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 160 | }; |
| 161 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 162 | |
| 163 | static bool EqualConcatenations(llvm::SmallVector<llvm::StringRef, 2> L, |
| 164 | PCHPredefinesBlocks R) { |
| 165 | // First, sum up the lengths. |
| 166 | unsigned LL = 0, RL = 0; |
| 167 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 168 | LL += L[I].size(); |
| 169 | } |
| 170 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 171 | RL += R[I].Data.size(); |
| 172 | } |
| 173 | if (LL != RL) |
| 174 | return false; |
| 175 | if (LL == 0 && RL == 0) |
| 176 | return true; |
| 177 | |
| 178 | // Kick out empty parts, they confuse the algorithm below. |
| 179 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 180 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 181 | |
| 182 | // Do it the hard way. At this point, both vectors must be non-empty. |
| 183 | llvm::StringRef LR = L[0], RR = R[0].Data; |
| 184 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 185 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 186 | for (;;) { |
| 187 | // Compare the current pieces. |
| 188 | if (LR.size() == RR.size()) { |
| 189 | // If they're the same length, it's pretty easy. |
| 190 | if (LR != RR) |
| 191 | return false; |
| 192 | // Both pieces are done, advance. |
| 193 | ++LI; |
| 194 | ++RI; |
| 195 | // If either string is done, they're both done, since they're the same |
| 196 | // length. |
| 197 | if (LI == LN) { |
| 198 | assert(RI == RN && "Strings not the same length after all?"); |
| 199 | return true; |
| 200 | } |
| 201 | LR = L[LI]; |
| 202 | RR = R[RI].Data; |
| 203 | } else if (LR.size() < RR.size()) { |
| 204 | // Right piece is longer. |
| 205 | if (!RR.startswith(LR)) |
| 206 | return false; |
| 207 | ++LI; |
| 208 | assert(LI != LN && "Strings not the same length after all?"); |
| 209 | RR = RR.substr(LR.size()); |
| 210 | LR = L[LI]; |
| 211 | } else { |
| 212 | // Left piece is longer. |
| 213 | if (!LR.startswith(RR)) |
| 214 | return false; |
| 215 | ++RI; |
| 216 | assert(RI != RN && "Strings not the same length after all?"); |
| 217 | LR = LR.substr(RR.size()); |
| 218 | RR = R[RI].Data; |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | static std::pair<FileID, llvm::StringRef::size_type> |
| 224 | FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) { |
| 225 | std::pair<FileID, llvm::StringRef::size_type> Res; |
| 226 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 227 | Res.second = Buffers[I].Data.find(MacroDef); |
| 228 | if (Res.second != llvm::StringRef::npos) { |
| 229 | Res.first = Buffers[I].BufferID; |
| 230 | break; |
| 231 | } |
| 232 | } |
| 233 | return Res; |
| 234 | } |
| 235 | |
| 236 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 237 | llvm::StringRef OriginalFileName, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 238 | std::string &SuggestedPredefines) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 239 | // We are in the context of an implicit include, so the predefines buffer will |
| 240 | // have a #include entry for the PCH file itself (as normalized by the |
| 241 | // preprocessor initialization). Find it and skip over it in the checking |
| 242 | // below. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 243 | llvm::SmallString<256> PCHInclude; |
| 244 | PCHInclude += "#include \""; |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 245 | PCHInclude += NormalizeDashIncludePath(OriginalFileName); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 246 | PCHInclude += "\"\n"; |
| 247 | std::pair<llvm::StringRef,llvm::StringRef> Split = |
| 248 | llvm::StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 249 | llvm::StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 250 | if (Left == PP.getPredefines()) { |
| 251 | Error("Missing PCH include entry!"); |
| 252 | return true; |
| 253 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 254 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 255 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 256 | // command line, we're done. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 257 | llvm::SmallVector<llvm::StringRef, 2> CommandLine; |
| 258 | CommandLine.push_back(Left); |
| 259 | CommandLine.push_back(Right); |
| 260 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 261 | return false; |
| 262 | |
| 263 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 264 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 265 | // The predefines buffers are different. Determine what the differences are, |
| 266 | // and whether they require us to reject the PCH file. |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 267 | llvm::SmallVector<llvm::StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 268 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 269 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 270 | |
| 271 | llvm::SmallVector<llvm::StringRef, 8> CmdLineLines; |
| 272 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 273 | |
| 274 | // Pick out implicit #includes after the PCH and don't consider them for |
| 275 | // validation; we will insert them into SuggestedPredefines so that the |
| 276 | // preprocessor includes them. |
| 277 | std::string IncludesAfterPCH; |
| 278 | llvm::SmallVector<llvm::StringRef, 8> AfterPCHLines; |
| 279 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 280 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 281 | if (AfterPCHLines[i].startswith("#include ")) { |
| 282 | IncludesAfterPCH += AfterPCHLines[i]; |
| 283 | IncludesAfterPCH += '\n'; |
| 284 | } else { |
| 285 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | // Make sure we add the includes last into SuggestedPredefines before we |
| 290 | // exit this function. |
| 291 | struct AddIncludesRAII { |
| 292 | std::string &SuggestedPredefines; |
| 293 | std::string &IncludesAfterPCH; |
| 294 | |
| 295 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 296 | std::string &IncludesAfterPCH) |
| 297 | : SuggestedPredefines(SuggestedPredefines), |
| 298 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 299 | ~AddIncludesRAII() { |
| 300 | SuggestedPredefines += IncludesAfterPCH; |
| 301 | } |
| 302 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 303 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 304 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 305 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 306 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 307 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 308 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 309 | // Determine which predefines that were used to build the PCH file are missing |
| 310 | // from the command line. |
| 311 | std::vector<llvm::StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 312 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 313 | CmdLineLines.begin(), CmdLineLines.end(), |
| 314 | std::back_inserter(MissingPredefines)); |
| 315 | |
| 316 | bool MissingDefines = false; |
| 317 | bool ConflictingDefines = false; |
| 318 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 319 | llvm::StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 320 | if (Missing.startswith("#include ")) { |
| 321 | // An -include was specified when generating the PCH; it is included in |
| 322 | // the PCH, just ignore it. |
| 323 | continue; |
| 324 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 325 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 326 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 327 | return true; |
| 328 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 329 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 330 | // This is a macro definition. Determine the name of the macro we're |
| 331 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 332 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 333 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 334 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 335 | assert(EndOfMacroName != std::string::npos && |
| 336 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 337 | llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 338 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 339 | // Determine whether this macro was given a different definition on the |
| 340 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 341 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 342 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 343 | llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 344 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 345 | MacroDefStart); |
| 346 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 347 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 348 | // Different macro; we're done. |
| 349 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 350 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 351 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 352 | |
| 353 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 354 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 355 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 356 | (*ConflictPos)[MacroDefLen] != '(') |
| 357 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 359 | // We found a conflicting macro definition. |
| 360 | break; |
| 361 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 362 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 363 | if (ConflictPos != CmdLineLines.end()) { |
| 364 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 365 | << MacroName; |
| 366 | |
| 367 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 368 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 369 | FindMacro(Buffers, Missing); |
| 370 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 371 | SourceLocation PCHMissingLoc = |
| 372 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 373 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 374 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 375 | |
| 376 | ConflictingDefines = true; |
| 377 | continue; |
| 378 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 379 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 380 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 381 | // 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] | 382 | if (ConflictingDefines) |
| 383 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 384 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 385 | if (!MissingDefines) { |
| 386 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 387 | MissingDefines = true; |
| 388 | } |
| 389 | |
| 390 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 391 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 392 | FindMacro(Buffers, Missing); |
| 393 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 394 | SourceLocation PCHMissingLoc = |
| 395 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 396 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 397 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 398 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 400 | if (ConflictingDefines) |
| 401 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 402 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 403 | // Determine what predefines were introduced based on command-line |
| 404 | // parameters that were not present when building the PCH |
| 405 | // file. Extra #defines are okay, so long as the identifiers being |
| 406 | // defined were not used within the precompiled header. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 407 | std::vector<llvm::StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 408 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 409 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 410 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 411 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 412 | llvm::StringRef &Extra = ExtraPredefines[I]; |
| 413 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 414 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 415 | return true; |
| 416 | } |
| 417 | |
| 418 | // This is an extra macro definition. Determine the name of the |
| 419 | // macro we're defining. |
| 420 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 421 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 422 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 423 | assert(EndOfMacroName != std::string::npos && |
| 424 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 425 | llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 426 | |
| 427 | // Check whether this name was used somewhere in the PCH file. If |
| 428 | // so, defining it as a macro could change behavior, so we reject |
| 429 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 430 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 431 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 432 | return true; |
| 433 | } |
| 434 | |
| 435 | // Add this definition to the suggested predefines buffer. |
| 436 | SuggestedPredefines += Extra; |
| 437 | SuggestedPredefines += '\n'; |
| 438 | } |
| 439 | |
| 440 | // If we get here, it's because the predefines buffer had compatible |
| 441 | // contents. Accept the PCH file. |
| 442 | return false; |
| 443 | } |
| 444 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 445 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 446 | unsigned ID) { |
| 447 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 448 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | void PCHValidator::ReadCounter(unsigned Value) { |
| 452 | PP.setCounterValue(Value); |
| 453 | } |
| 454 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 455 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 456 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 457 | //===----------------------------------------------------------------------===// |
| 458 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 459 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 460 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 461 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 464 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 465 | namespace { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 466 | class ASTSelectorLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 467 | ASTReader &Reader; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 468 | |
| 469 | public: |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 470 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 471 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 472 | ObjCMethodList Instance, Factory; |
| 473 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 474 | |
| 475 | typedef Selector external_key_type; |
| 476 | typedef external_key_type internal_key_type; |
| 477 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 478 | explicit ASTSelectorLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 479 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 480 | static bool EqualKey(const internal_key_type& a, |
| 481 | const internal_key_type& b) { |
| 482 | return a == b; |
| 483 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 484 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 485 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 486 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 487 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 488 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 489 | // This hopefully will just get inlined and removed by the optimizer. |
| 490 | static const internal_key_type& |
| 491 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 492 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 493 | static std::pair<unsigned, unsigned> |
| 494 | ReadKeyDataLength(const unsigned char*& d) { |
| 495 | using namespace clang::io; |
| 496 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 497 | unsigned DataLen = ReadUnalignedLE16(d); |
| 498 | return std::make_pair(KeyLen, DataLen); |
| 499 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 500 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 501 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 502 | using namespace clang::io; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 503 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 504 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 505 | IdentifierInfo *FirstII |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 506 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 507 | if (N == 0) |
| 508 | return SelTable.getNullarySelector(FirstII); |
| 509 | else if (N == 1) |
| 510 | return SelTable.getUnarySelector(FirstII); |
| 511 | |
| 512 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 513 | Args.push_back(FirstII); |
| 514 | for (unsigned I = 1; I != N; ++I) |
| 515 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 516 | |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 517 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 518 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 520 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 521 | using namespace clang::io; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 522 | |
| 523 | data_type Result; |
| 524 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 525 | Result.ID = ReadUnalignedLE32(d); |
| 526 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 527 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 528 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 529 | // Load instance methods |
| 530 | ObjCMethodList *Prev = 0; |
| 531 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 532 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 533 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 534 | if (!Result.Instance.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 535 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 536 | Result.Instance.Method = Method; |
| 537 | Prev = &Result.Instance; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 538 | continue; |
| 539 | } |
| 540 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 541 | ObjCMethodList *Mem = |
| 542 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 543 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 544 | Prev = Prev->Next; |
| 545 | } |
| 546 | |
| 547 | // Load factory methods |
| 548 | Prev = 0; |
| 549 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 550 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 551 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 552 | if (!Result.Factory.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 553 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 554 | Result.Factory.Method = Method; |
| 555 | Prev = &Result.Factory; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 556 | continue; |
| 557 | } |
| 558 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 559 | ObjCMethodList *Mem = |
| 560 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 561 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 562 | Prev = Prev->Next; |
| 563 | } |
| 564 | |
| 565 | return Result; |
| 566 | } |
| 567 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 568 | |
| 569 | } // end anonymous namespace |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 570 | |
| 571 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 572 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 573 | ASTSelectorLookupTable; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 574 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 575 | namespace clang { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 576 | class ASTIdentifierLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 577 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 578 | ASTReader::PerFileData &F; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 579 | |
| 580 | // If we know the IdentifierInfo in advance, it is here and we will |
| 581 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 582 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 583 | IdentifierInfo *KnownII; |
| 584 | |
| 585 | public: |
| 586 | typedef IdentifierInfo * data_type; |
| 587 | |
| 588 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 589 | |
| 590 | typedef external_key_type internal_key_type; |
| 591 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 592 | ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 593 | IdentifierInfo *II = 0) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 594 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 595 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 596 | static bool EqualKey(const internal_key_type& a, |
| 597 | const internal_key_type& b) { |
| 598 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 599 | : false; |
| 600 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 601 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 602 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 603 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 604 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 605 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 606 | // This hopefully will just get inlined and removed by the optimizer. |
| 607 | static const internal_key_type& |
| 608 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 609 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 610 | // This hopefully will just get inlined and removed by the optimizer. |
| 611 | static const external_key_type& |
| 612 | GetExternalKey(const internal_key_type& x) { return x; } |
| 613 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 614 | static std::pair<unsigned, unsigned> |
| 615 | ReadKeyDataLength(const unsigned char*& d) { |
| 616 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 617 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 618 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 619 | return std::make_pair(KeyLen, DataLen); |
| 620 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 621 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 622 | static std::pair<const char*, unsigned> |
| 623 | ReadKey(const unsigned char* d, unsigned n) { |
| 624 | assert(n >= 2 && d[n-1] == '\0'); |
| 625 | return std::make_pair((const char*) d, n-1); |
| 626 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 627 | |
| 628 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 629 | const unsigned char* d, |
| 630 | unsigned DataLen) { |
| 631 | using namespace clang::io; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 632 | IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 633 | bool IsInteresting = ID & 0x01; |
| 634 | |
| 635 | // Wipe out the "is interesting" bit. |
| 636 | ID = ID >> 1; |
| 637 | |
| 638 | if (!IsInteresting) { |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 639 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 640 | // and associate it with the persistent ID. |
| 641 | IdentifierInfo *II = KnownII; |
| 642 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 643 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 644 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 645 | II->setIsFromAST(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 646 | return II; |
| 647 | } |
| 648 | |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 649 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 650 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 651 | Bits >>= 1; |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 652 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 653 | Bits >>= 1; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 654 | bool Poisoned = Bits & 0x01; |
| 655 | Bits >>= 1; |
| 656 | bool ExtensionToken = Bits & 0x01; |
| 657 | Bits >>= 1; |
| 658 | bool hasMacroDefinition = Bits & 0x01; |
| 659 | Bits >>= 1; |
| 660 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 661 | Bits >>= 10; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 662 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 663 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 664 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 665 | |
| 666 | // Build the IdentifierInfo itself and link the identifier ID with |
| 667 | // the new IdentifierInfo. |
| 668 | IdentifierInfo *II = KnownII; |
| 669 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 670 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 671 | Reader.SetIdentifierInfo(ID, II); |
| 672 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 673 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 674 | // Token IDs are read-only. |
| 675 | if (HasRevertedTokenIDToIdentifier) |
| 676 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 677 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 678 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 679 | "Incorrect extension token flag"); |
| 680 | (void)ExtensionToken; |
| 681 | II->setIsPoisoned(Poisoned); |
| 682 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 683 | "Incorrect C++ operator keyword flag"); |
| 684 | (void)CPlusPlusOperatorKeyword; |
| 685 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 686 | // If this identifier is a macro, deserialize the macro |
| 687 | // definition. |
| 688 | if (hasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 689 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 690 | Reader.SetIdentifierIsMacro(II, F, Offset); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 691 | DataLen -= 4; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 692 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 693 | |
| 694 | // Read all of the declarations visible at global scope with this |
| 695 | // name. |
Chris Lattner | 6bf690f | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 696 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 697 | if (DataLen > 0) { |
| 698 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 699 | for (; DataLen > 0; DataLen -= 4) |
| 700 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 701 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 702 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 703 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 704 | II->setIsFromAST(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 705 | return II; |
| 706 | } |
| 707 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 708 | |
| 709 | } // end anonymous namespace |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 710 | |
| 711 | /// \brief The on-disk hash table used to contain information about |
| 712 | /// all of the identifiers in the program. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 713 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 714 | ASTIdentifierLookupTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 715 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 716 | namespace { |
| 717 | class ASTDeclContextNameLookupTrait { |
| 718 | ASTReader &Reader; |
| 719 | |
| 720 | public: |
| 721 | /// \brief Pair of begin/end iterators for DeclIDs. |
| 722 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 723 | |
| 724 | /// \brief Special internal key for declaration names. |
| 725 | /// The hash table creates keys for comparison; we do not create |
| 726 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 727 | struct DeclNameKey { |
| 728 | DeclarationName::NameKind Kind; |
| 729 | uint64_t Data; |
| 730 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 731 | }; |
| 732 | |
| 733 | typedef DeclarationName external_key_type; |
| 734 | typedef DeclNameKey internal_key_type; |
| 735 | |
| 736 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
| 737 | |
| 738 | static bool EqualKey(const internal_key_type& a, |
| 739 | const internal_key_type& b) { |
| 740 | return a.Kind == b.Kind && a.Data == b.Data; |
| 741 | } |
| 742 | |
| 743 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 744 | llvm::FoldingSetNodeID ID; |
| 745 | ID.AddInteger(Key.Kind); |
| 746 | |
| 747 | switch (Key.Kind) { |
| 748 | case DeclarationName::Identifier: |
| 749 | case DeclarationName::CXXLiteralOperatorName: |
| 750 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 751 | break; |
| 752 | case DeclarationName::ObjCZeroArgSelector: |
| 753 | case DeclarationName::ObjCOneArgSelector: |
| 754 | case DeclarationName::ObjCMultiArgSelector: |
| 755 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 756 | break; |
| 757 | case DeclarationName::CXXConstructorName: |
| 758 | case DeclarationName::CXXDestructorName: |
| 759 | case DeclarationName::CXXConversionFunctionName: |
| 760 | ID.AddInteger((TypeID)Key.Data); |
| 761 | break; |
| 762 | case DeclarationName::CXXOperatorName: |
| 763 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 764 | break; |
| 765 | case DeclarationName::CXXUsingDirective: |
| 766 | break; |
| 767 | } |
| 768 | |
| 769 | return ID.ComputeHash(); |
| 770 | } |
| 771 | |
| 772 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 773 | DeclNameKey Key; |
| 774 | Key.Kind = Name.getNameKind(); |
| 775 | switch (Name.getNameKind()) { |
| 776 | case DeclarationName::Identifier: |
| 777 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 778 | break; |
| 779 | case DeclarationName::ObjCZeroArgSelector: |
| 780 | case DeclarationName::ObjCOneArgSelector: |
| 781 | case DeclarationName::ObjCMultiArgSelector: |
| 782 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 783 | break; |
| 784 | case DeclarationName::CXXConstructorName: |
| 785 | case DeclarationName::CXXDestructorName: |
| 786 | case DeclarationName::CXXConversionFunctionName: |
| 787 | Key.Data = Reader.GetTypeID(Name.getCXXNameType()); |
| 788 | break; |
| 789 | case DeclarationName::CXXOperatorName: |
| 790 | Key.Data = Name.getCXXOverloadedOperator(); |
| 791 | break; |
| 792 | case DeclarationName::CXXLiteralOperatorName: |
| 793 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 794 | break; |
| 795 | case DeclarationName::CXXUsingDirective: |
| 796 | break; |
| 797 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 798 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 799 | return Key; |
| 800 | } |
| 801 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 802 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 803 | ASTContext *Context = Reader.getContext(); |
| 804 | switch (Key.Kind) { |
| 805 | case DeclarationName::Identifier: |
| 806 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 807 | |
| 808 | case DeclarationName::ObjCZeroArgSelector: |
| 809 | case DeclarationName::ObjCOneArgSelector: |
| 810 | case DeclarationName::ObjCMultiArgSelector: |
| 811 | return DeclarationName(Selector(Key.Data)); |
| 812 | |
| 813 | case DeclarationName::CXXConstructorName: |
| 814 | return Context->DeclarationNames.getCXXConstructorName( |
| 815 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 816 | |
| 817 | case DeclarationName::CXXDestructorName: |
| 818 | return Context->DeclarationNames.getCXXDestructorName( |
| 819 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 820 | |
| 821 | case DeclarationName::CXXConversionFunctionName: |
| 822 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 823 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 824 | |
| 825 | case DeclarationName::CXXOperatorName: |
| 826 | return Context->DeclarationNames.getCXXOperatorName( |
| 827 | (OverloadedOperatorKind)Key.Data); |
| 828 | |
| 829 | case DeclarationName::CXXLiteralOperatorName: |
| 830 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 831 | (IdentifierInfo*)Key.Data); |
| 832 | |
| 833 | case DeclarationName::CXXUsingDirective: |
| 834 | return DeclarationName::getUsingDirectiveName(); |
| 835 | } |
| 836 | |
| 837 | llvm_unreachable("Invalid Name Kind ?"); |
| 838 | } |
| 839 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 840 | static std::pair<unsigned, unsigned> |
| 841 | ReadKeyDataLength(const unsigned char*& d) { |
| 842 | using namespace clang::io; |
| 843 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 844 | unsigned DataLen = ReadUnalignedLE16(d); |
| 845 | return std::make_pair(KeyLen, DataLen); |
| 846 | } |
| 847 | |
| 848 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 849 | using namespace clang::io; |
| 850 | |
| 851 | DeclNameKey Key; |
| 852 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 853 | switch (Key.Kind) { |
| 854 | case DeclarationName::Identifier: |
| 855 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 856 | break; |
| 857 | case DeclarationName::ObjCZeroArgSelector: |
| 858 | case DeclarationName::ObjCOneArgSelector: |
| 859 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 860 | Key.Data = |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 861 | (uint64_t)Reader.DecodeSelector(ReadUnalignedLE32(d)).getAsOpaquePtr(); |
| 862 | break; |
| 863 | case DeclarationName::CXXConstructorName: |
| 864 | case DeclarationName::CXXDestructorName: |
| 865 | case DeclarationName::CXXConversionFunctionName: |
| 866 | Key.Data = ReadUnalignedLE32(d); // TypeID |
| 867 | break; |
| 868 | case DeclarationName::CXXOperatorName: |
| 869 | Key.Data = *d++; // OverloadedOperatorKind |
| 870 | break; |
| 871 | case DeclarationName::CXXLiteralOperatorName: |
| 872 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 873 | break; |
| 874 | case DeclarationName::CXXUsingDirective: |
| 875 | break; |
| 876 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 877 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 878 | return Key; |
| 879 | } |
| 880 | |
| 881 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 882 | unsigned DataLen) { |
| 883 | using namespace clang::io; |
| 884 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 885 | DeclID *Start = (DeclID *)d; |
| 886 | return std::make_pair(Start, Start + NumDecls); |
| 887 | } |
| 888 | }; |
| 889 | |
| 890 | } // end anonymous namespace |
| 891 | |
| 892 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 893 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 894 | ASTDeclContextNameLookupTable; |
| 895 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 896 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 897 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 898 | DeclContextInfo &Info) { |
| 899 | SavedStreamPosition SavedPosition(Cursor); |
| 900 | // First the lexical decls. |
| 901 | if (Offsets.first != 0) { |
| 902 | Cursor.JumpToBit(Offsets.first); |
| 903 | |
| 904 | RecordData Record; |
| 905 | const char *Blob; |
| 906 | unsigned BlobLen; |
| 907 | unsigned Code = Cursor.ReadCode(); |
| 908 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 909 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 910 | Error("Expected lexical block"); |
| 911 | return true; |
| 912 | } |
| 913 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 914 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 915 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 916 | } else { |
| 917 | Info.LexicalDecls = 0; |
| 918 | Info.NumLexicalDecls = 0; |
| 919 | } |
| 920 | |
| 921 | // Now the lookup table. |
| 922 | if (Offsets.second != 0) { |
| 923 | Cursor.JumpToBit(Offsets.second); |
| 924 | |
| 925 | RecordData Record; |
| 926 | const char *Blob; |
| 927 | unsigned BlobLen; |
| 928 | unsigned Code = Cursor.ReadCode(); |
| 929 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 930 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 931 | Error("Expected visible lookup table block"); |
| 932 | return true; |
| 933 | } |
| 934 | Info.NameLookupTableData |
| 935 | = ASTDeclContextNameLookupTable::Create( |
| 936 | (const unsigned char *)Blob + Record[0], |
| 937 | (const unsigned char *)Blob, |
| 938 | ASTDeclContextNameLookupTrait(*this)); |
Sebastian Redl | 0ea8f7f | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 939 | } else { |
| 940 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | return false; |
| 944 | } |
| 945 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 946 | void ASTReader::Error(const char *Msg) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 947 | Diag(diag::err_fe_pch_malformed) << Msg; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 948 | } |
| 949 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 950 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 951 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 952 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 953 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 954 | ActualOriginalFileName, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 955 | SuggestedPredefines); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 956 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 957 | } |
| 958 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 959 | //===----------------------------------------------------------------------===// |
| 960 | // Source Manager Deserialization |
| 961 | //===----------------------------------------------------------------------===// |
| 962 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 963 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 964 | /// \returns true if there was an error. |
| 965 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 966 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 967 | unsigned Idx = 0; |
| 968 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 969 | |
| 970 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 971 | std::map<int, int> FileIDs; |
| 972 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 973 | // Extract the file name |
| 974 | unsigned FilenameLen = Record[Idx++]; |
| 975 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 976 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 977 | MaybeAddSystemRootToFilename(Filename); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 978 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 979 | Filename.size()); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | // Parse the line entries |
| 983 | std::vector<LineEntry> Entries; |
| 984 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 985 | int FID = Record[Idx++]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 986 | |
| 987 | // Extract the line entries |
| 988 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 989 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 990 | Entries.clear(); |
| 991 | Entries.reserve(NumEntries); |
| 992 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 993 | unsigned FileOffset = Record[Idx++]; |
| 994 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 995 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 996 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 997 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 998 | unsigned IncludeOffset = Record[Idx++]; |
| 999 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1000 | FileKind, IncludeOffset)); |
| 1001 | } |
| 1002 | LineTable.AddEntry(FID, Entries); |
| 1003 | } |
| 1004 | |
| 1005 | return false; |
| 1006 | } |
| 1007 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1008 | namespace { |
| 1009 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1010 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1011 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1012 | const ino_t ino; |
| 1013 | const dev_t dev; |
| 1014 | const mode_t mode; |
| 1015 | const time_t mtime; |
| 1016 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1017 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1018 | ASTStatData(ino_t i, dev_t d, mode_t mo, time_t m, off_t s) |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1019 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1020 | }; |
| 1021 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1022 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1023 | public: |
| 1024 | typedef const char *external_key_type; |
| 1025 | typedef const char *internal_key_type; |
| 1026 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1027 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1028 | |
| 1029 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1030 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1034 | |
| 1035 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1036 | return strcmp(a, b) == 0; |
| 1037 | } |
| 1038 | |
| 1039 | static std::pair<unsigned, unsigned> |
| 1040 | ReadKeyDataLength(const unsigned char*& d) { |
| 1041 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1042 | unsigned DataLen = (unsigned) *d++; |
| 1043 | return std::make_pair(KeyLen + 1, DataLen); |
| 1044 | } |
| 1045 | |
| 1046 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1047 | return (const char *)d; |
| 1048 | } |
| 1049 | |
| 1050 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1051 | unsigned /*DataLen*/) { |
| 1052 | using namespace clang::io; |
| 1053 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1054 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1055 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1056 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1057 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1058 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1059 | return data_type(ino, dev, mode, mtime, size); |
| 1060 | } |
| 1061 | }; |
| 1062 | |
| 1063 | /// \brief stat() cache for precompiled headers. |
| 1064 | /// |
| 1065 | /// This cache is very similar to the stat cache used by pretokenized |
| 1066 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1067 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1068 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1069 | CacheTy *Cache; |
| 1070 | |
| 1071 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1072 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1073 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1074 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1075 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1076 | Cache = CacheTy::Create(Buckets, Base); |
| 1077 | } |
| 1078 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1079 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1080 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1081 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1082 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1083 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1084 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1085 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1086 | // 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] | 1087 | if (I == Cache->end()) { |
| 1088 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1089 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1090 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1091 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1092 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1093 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1095 | StatBuf.st_ino = Data.ino; |
| 1096 | StatBuf.st_dev = Data.dev; |
| 1097 | StatBuf.st_mtime = Data.mtime; |
| 1098 | StatBuf.st_mode = Data.mode; |
| 1099 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1100 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1101 | } |
| 1102 | }; |
| 1103 | } // end anonymous namespace |
| 1104 | |
| 1105 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1106 | /// \brief Read a source manager block |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1107 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1108 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1109 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1110 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1111 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1112 | // Set the source-location entry cursor to the current position in |
| 1113 | // the stream. This cursor will be used to read the contents of the |
| 1114 | // source manager block initially, and then lazily read |
| 1115 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1116 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1117 | |
| 1118 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1119 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1120 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1121 | return Failure; |
| 1122 | } |
| 1123 | |
| 1124 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1125 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1126 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1127 | return Failure; |
| 1128 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1129 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1130 | RecordData Record; |
| 1131 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1132 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1133 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1134 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1135 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1136 | return Failure; |
| 1137 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1138 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1139 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1140 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1141 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1142 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1143 | SLocEntryCursor.ReadSubBlockID(); |
| 1144 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1145 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1146 | return Failure; |
| 1147 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1148 | continue; |
| 1149 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1151 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1152 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1153 | continue; |
| 1154 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1155 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1156 | // Read a record. |
| 1157 | const char *BlobStart; |
| 1158 | unsigned BlobLen; |
| 1159 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1160 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1161 | default: // Default behavior: ignore. |
| 1162 | break; |
| 1163 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1164 | case SM_LINE_TABLE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1165 | if (ParseLineTable(F, Record)) |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1166 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1167 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1168 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1169 | case SM_SLOC_FILE_ENTRY: |
| 1170 | case SM_SLOC_BUFFER_ENTRY: |
| 1171 | case SM_SLOC_INSTANTIATION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1172 | // Once we hit one of the source location entries, we're done. |
| 1173 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1178 | /// \brief Get a cursor that's correctly positioned for reading the source |
| 1179 | /// location entry with the given ID. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1180 | ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1181 | assert(ID != 0 && ID <= TotalNumSLocEntries && |
| 1182 | "SLocCursorForID should only be called for real IDs."); |
| 1183 | |
| 1184 | ID -= 1; |
| 1185 | PerFileData *F = 0; |
| 1186 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1187 | F = Chain[N - I - 1]; |
| 1188 | if (ID < F->LocalNumSLocEntries) |
| 1189 | break; |
| 1190 | ID -= F->LocalNumSLocEntries; |
| 1191 | } |
| 1192 | assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); |
| 1193 | |
| 1194 | F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1195 | return F; |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1198 | /// \brief Read in the source location entry with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1199 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1200 | if (ID == 0) |
| 1201 | return Success; |
| 1202 | |
| 1203 | if (ID > TotalNumSLocEntries) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1204 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1205 | return Failure; |
| 1206 | } |
| 1207 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1208 | PerFileData *F = SLocCursorForID(ID); |
| 1209 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1210 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1211 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1212 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1213 | if (Code == llvm::bitc::END_BLOCK || |
| 1214 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1215 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1216 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1217 | return Failure; |
| 1218 | } |
| 1219 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1220 | RecordData Record; |
| 1221 | const char *BlobStart; |
| 1222 | unsigned BlobLen; |
| 1223 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1224 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1225 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1226 | return Failure; |
| 1227 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1228 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1229 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1230 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1231 | const FileEntry *File = FileMgr.getFile(Filename); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1232 | if (File == 0) { |
| 1233 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1234 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1235 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1236 | Error(ErrorStr.c_str()); |
| 1237 | return Failure; |
| 1238 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1239 | |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1240 | if (Record.size() < 10) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1241 | Error("source location entry is incorrect"); |
| 1242 | return Failure; |
| 1243 | } |
| 1244 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1245 | if (!DisableValidation && |
| 1246 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1247 | #if !defined(LLVM_ON_WIN32) |
| 1248 | // In our regression testing, the Windows file system seems to |
| 1249 | // have inconsistent modification times that sometimes |
| 1250 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1251 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1252 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1253 | )) { |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1254 | Diag(diag::err_fe_pch_file_modified) |
| 1255 | << Filename; |
| 1256 | return Failure; |
| 1257 | } |
| 1258 | |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1259 | FileID FID = SourceMgr.createFileID(File, ReadSourceLocation(*F, Record[1]), |
| 1260 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1261 | ID, Record[0]); |
| 1262 | if (Record[3]) |
| 1263 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1264 | .setHasLineDirectives(); |
| 1265 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 1266 | // Reconstruct header-search information for this file. |
| 1267 | HeaderFileInfo HFI; |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1268 | HFI.isImport = Record[6]; |
| 1269 | HFI.DirInfo = Record[7]; |
| 1270 | HFI.NumIncludes = Record[8]; |
| 1271 | HFI.ControllingMacroID = Record[9]; |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 1272 | if (Listener) |
| 1273 | Listener->ReadHeaderFileInfo(HFI, File->getUID()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1274 | break; |
| 1275 | } |
| 1276 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1277 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1278 | const char *Name = BlobStart; |
| 1279 | unsigned Offset = Record[0]; |
| 1280 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1281 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1282 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1283 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1284 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1285 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1286 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1287 | return Failure; |
| 1288 | } |
| 1289 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1290 | llvm::MemoryBuffer *Buffer |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1291 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1292 | Name); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1293 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1294 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1295 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1296 | PCHPredefinesBlock Block = { |
| 1297 | BufferID, |
| 1298 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1299 | }; |
| 1300 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1301 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1302 | |
| 1303 | break; |
| 1304 | } |
| 1305 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1306 | case SM_SLOC_INSTANTIATION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1307 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1308 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1309 | ReadSourceLocation(*F, Record[2]), |
| 1310 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1311 | Record[4], |
| 1312 | ID, |
| 1313 | Record[0]); |
| 1314 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1315 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | return Success; |
| 1319 | } |
| 1320 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1321 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1322 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1323 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1324 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1325 | unsigned BlockID) { |
| 1326 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1327 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1328 | return Failure; |
| 1329 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1331 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1332 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1333 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1334 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1335 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1336 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1337 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1338 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1339 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1340 | Cursor.ReadAbbrevRecord(); |
| 1341 | } |
| 1342 | } |
| 1343 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1344 | PreprocessedEntity *ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1345 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1346 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1347 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1348 | // Keep track of where we are in the stream, then jump back there |
| 1349 | // after reading this macro. |
| 1350 | SavedStreamPosition SavedPosition(Stream); |
| 1351 | |
| 1352 | Stream.JumpToBit(Offset); |
| 1353 | RecordData Record; |
| 1354 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1355 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1356 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1357 | while (true) { |
| 1358 | unsigned Code = Stream.ReadCode(); |
| 1359 | switch (Code) { |
| 1360 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1361 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1362 | |
| 1363 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1364 | // No known subblocks, always skip them. |
| 1365 | Stream.ReadSubBlockID(); |
| 1366 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1367 | Error("malformed block record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1368 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1369 | } |
| 1370 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1371 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1372 | case llvm::bitc::DEFINE_ABBREV: |
| 1373 | Stream.ReadAbbrevRecord(); |
| 1374 | continue; |
| 1375 | default: break; |
| 1376 | } |
| 1377 | |
| 1378 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1379 | const char *BlobStart = 0; |
| 1380 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1381 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1382 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1383 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1384 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1385 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1386 | case PP_MACRO_OBJECT_LIKE: |
| 1387 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1388 | // If we already have a macro, that means that we've hit the end |
| 1389 | // of the definition of the macro we were looking for. We're |
| 1390 | // done. |
| 1391 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1392 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1393 | |
| 1394 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1395 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1396 | Error("macro must have a name in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1397 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1398 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1399 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1400 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1401 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1402 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1403 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1404 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1405 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1406 | unsigned NextIndex = 3; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1407 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1408 | // Decode function-like macro info. |
| 1409 | bool isC99VarArgs = Record[3]; |
| 1410 | bool isGNUVarArgs = Record[4]; |
| 1411 | MacroArgs.clear(); |
| 1412 | unsigned NumArgs = Record[5]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1413 | NextIndex = 6 + NumArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1414 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1415 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1416 | |
| 1417 | // Install function-like macro info. |
| 1418 | MI->setIsFunctionLike(); |
| 1419 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1420 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1421 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1422 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1426 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1427 | |
| 1428 | // Remember that we saw this macro last so that we add the tokens that |
| 1429 | // form its body to it. |
| 1430 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1431 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1432 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1433 | // We have a macro definition. Load it now. |
| 1434 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1435 | getMacroDefinition(Record[NextIndex])); |
| 1436 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1437 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1438 | ++NumMacrosRead; |
| 1439 | break; |
| 1440 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1441 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1442 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1443 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1444 | // erroneous, just pretend we didn't see this. |
| 1445 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1446 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1447 | Token Tok; |
| 1448 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1449 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1450 | Tok.setLength(Record[1]); |
| 1451 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1452 | Tok.setIdentifierInfo(II); |
| 1453 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1454 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1455 | Macro->AddTokenToBody(Tok); |
| 1456 | break; |
| 1457 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1458 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1459 | case PP_MACRO_INSTANTIATION: { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1460 | // If we already have a macro, that means that we've hit the end |
| 1461 | // of the definition of the macro we were looking for. We're |
| 1462 | // done. |
| 1463 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1464 | return 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1465 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1466 | if (!PP->getPreprocessingRecord()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1467 | Error("missing preprocessing record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1468 | return 0; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1469 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1470 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1471 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1472 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1473 | return PE; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1474 | |
| 1475 | MacroInstantiation *MI |
| 1476 | = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1477 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1478 | ReadSourceLocation(F, Record[2])), |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1479 | getMacroDefinition(Record[4])); |
| 1480 | PPRec.SetPreallocatedEntity(Record[0], MI); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1481 | return MI; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1484 | case PP_MACRO_DEFINITION: { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1485 | // If we already have a macro, that means that we've hit the end |
| 1486 | // of the definition of the macro we were looking for. We're |
| 1487 | // done. |
| 1488 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1489 | return 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1490 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1491 | if (!PP->getPreprocessingRecord()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1492 | Error("missing preprocessing record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1493 | return 0; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1494 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1495 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1496 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1497 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1498 | return PE; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1499 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1500 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1501 | Error("out-of-bounds macro definition record"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1502 | return 0; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1505 | // Decode the identifier info and then check again; if the macro is |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1506 | // still defined and associated with the identifier, |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1507 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1508 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1509 | MacroDefinition *MD |
| 1510 | = new (PPRec) MacroDefinition(II, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1511 | ReadSourceLocation(F, Record[5]), |
Douglas Gregor | b1a7d9a | 2010-10-01 20:33:34 +0000 | [diff] [blame] | 1512 | SourceRange( |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1513 | ReadSourceLocation(F, Record[2]), |
| 1514 | ReadSourceLocation(F, Record[3]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1515 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1516 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1517 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1518 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1519 | if (DeserializationListener) |
| 1520 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1521 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1522 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1523 | return MacroDefinitionsLoaded[Record[1] - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1524 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1525 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1526 | case PP_INCLUSION_DIRECTIVE: { |
| 1527 | // If we already have a macro, that means that we've hit the end |
| 1528 | // of the definition of the macro we were looking for. We're |
| 1529 | // done. |
| 1530 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1531 | return 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1532 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1533 | if (!PP->getPreprocessingRecord()) { |
| 1534 | Error("missing preprocessing record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1535 | return 0; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1536 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1537 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1538 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1539 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1540 | return PE; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1541 | |
| 1542 | const char *FullFileNameStart = BlobStart + Record[3]; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1543 | const FileEntry *File |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1544 | = PP->getFileManager().getFile(llvm::StringRef(FullFileNameStart, |
| 1545 | BlobLen - Record[3])); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1546 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1547 | // FIXME: Stable encoding |
| 1548 | InclusionDirective::InclusionKind Kind |
| 1549 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1550 | InclusionDirective *ID |
Douglas Gregor | 4ab829c | 2010-11-01 15:03:47 +0000 | [diff] [blame] | 1551 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1552 | llvm::StringRef(BlobStart, Record[3]), |
| 1553 | Record[4], |
| 1554 | File, |
| 1555 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1556 | ReadSourceLocation(F, Record[2]))); |
| 1557 | PPRec.SetPreallocatedEntity(Record[0], ID); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1558 | return ID; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1559 | } |
Sebastian Redl | b57a624 | 2010-09-27 22:18:47 +0000 | [diff] [blame] | 1560 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1561 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1562 | |
| 1563 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1566 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F, |
| 1567 | uint64_t Offset) { |
| 1568 | // Note that this identifier has a macro definition. |
| 1569 | II->setHasMacroDefinition(true); |
| 1570 | |
| 1571 | // Adjust the offset based on our position in the chain. |
| 1572 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1573 | if (Chain[I] == &F) |
| 1574 | break; |
| 1575 | |
| 1576 | Offset += Chain[I]->SizeInBits; |
| 1577 | } |
| 1578 | |
| 1579 | UnreadMacroRecordOffsets[II] = Offset; |
| 1580 | } |
| 1581 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1582 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1583 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1584 | PerFileData &F = *Chain[N - I - 1]; |
| 1585 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1586 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1587 | // If there was no preprocessor block, skip this file. |
| 1588 | if (!MacroCursor.getBitStreamReader()) |
| 1589 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1590 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1591 | llvm::BitstreamCursor Cursor = MacroCursor; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1592 | Cursor.JumpToBit(F.MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1593 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1594 | RecordData Record; |
| 1595 | while (true) { |
Sebastian Redl | edadecc | 2010-09-28 02:55:49 +0000 | [diff] [blame] | 1596 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1597 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1598 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1599 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1600 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1601 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1602 | // No known subblocks, always skip them. |
| 1603 | Cursor.ReadSubBlockID(); |
| 1604 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1605 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1606 | return; |
| 1607 | } |
| 1608 | continue; |
| 1609 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1610 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1611 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1612 | Cursor.ReadAbbrevRecord(); |
| 1613 | continue; |
| 1614 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1615 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1616 | // Read a record. |
| 1617 | const char *BlobStart; |
| 1618 | unsigned BlobLen; |
| 1619 | Record.clear(); |
| 1620 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1621 | default: // Default behavior: ignore. |
| 1622 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1623 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1624 | case PP_MACRO_OBJECT_LIKE: |
| 1625 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1626 | DecodeIdentifierInfo(Record[0]); |
| 1627 | break; |
| 1628 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1629 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1630 | // Ignore tokens. |
| 1631 | break; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1632 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1633 | case PP_MACRO_INSTANTIATION: |
| 1634 | case PP_MACRO_DEFINITION: |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1635 | case PP_INCLUSION_DIRECTIVE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1636 | // Read the macro record. |
Sebastian Redl | edadecc | 2010-09-28 02:55:49 +0000 | [diff] [blame] | 1637 | // FIXME: That's a stupid way to do this. We should reuse this cursor. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1638 | ReadMacroRecord(F, Offset); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1639 | break; |
| 1640 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1641 | } |
| 1642 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1643 | |
| 1644 | // Drain the unread macro-record offsets map. |
| 1645 | while (!UnreadMacroRecordOffsets.empty()) |
| 1646 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1647 | } |
| 1648 | |
| 1649 | void ASTReader::LoadMacroDefinition( |
| 1650 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1651 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
| 1652 | PerFileData *F = 0; |
| 1653 | uint64_t Offset = Pos->second; |
| 1654 | UnreadMacroRecordOffsets.erase(Pos); |
| 1655 | |
| 1656 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1657 | if (Offset < Chain[I]->SizeInBits) { |
| 1658 | F = Chain[I]; |
| 1659 | break; |
| 1660 | } |
| 1661 | |
| 1662 | Offset -= Chain[I]->SizeInBits; |
| 1663 | } |
| 1664 | if (!F) { |
| 1665 | Error("Malformed macro record offset"); |
| 1666 | return; |
| 1667 | } |
| 1668 | |
| 1669 | ReadMacroRecord(*F, Offset); |
| 1670 | } |
| 1671 | |
| 1672 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1673 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1674 | = UnreadMacroRecordOffsets.find(II); |
| 1675 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1678 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1679 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1680 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1681 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1682 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1683 | unsigned Index = ID - 1; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1684 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1685 | PerFileData &F = *Chain[N - I - 1]; |
| 1686 | if (Index < F.LocalNumMacroDefinitions) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1687 | ReadMacroRecord(F, F.MacroDefinitionOffsets[Index]); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1688 | break; |
| 1689 | } |
| 1690 | Index -= F.LocalNumMacroDefinitions; |
| 1691 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1692 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1695 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1698 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1699 | /// not an absolute path, add the system root to the beginning of the file |
| 1700 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1701 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1702 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1703 | if (!RelocatablePCH) |
| 1704 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1705 | |
Daniel Dunbar | d5b2197 | 2009-11-18 19:50:41 +0000 | [diff] [blame] | 1706 | if (Filename.empty() || llvm::sys::Path(Filename).isAbsolute()) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1707 | return; |
| 1708 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1709 | if (isysroot == 0) { |
| 1710 | // If no system root was given, default to '/' |
| 1711 | Filename.insert(Filename.begin(), '/'); |
| 1712 | return; |
| 1713 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1714 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1715 | unsigned Length = strlen(isysroot); |
| 1716 | if (isysroot[Length - 1] != '/') |
| 1717 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1718 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1719 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1720 | } |
| 1721 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1722 | ASTReader::ASTReadResult |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1723 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1724 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1725 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1726 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1727 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1728 | return Failure; |
| 1729 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1730 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1731 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1732 | RecordData Record; |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1733 | bool First = true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1734 | while (!Stream.AtEndOfStream()) { |
| 1735 | unsigned Code = Stream.ReadCode(); |
| 1736 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1737 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1738 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1739 | return Failure; |
| 1740 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1741 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1742 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1746 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1747 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1748 | // We lazily load the decls block, but we want to set up the |
| 1749 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1750 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1751 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1752 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1753 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1754 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1755 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1756 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1757 | return Failure; |
| 1758 | } |
| 1759 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1761 | case DECL_UPDATES_BLOCK_ID: |
| 1762 | if (Stream.SkipBlock()) { |
| 1763 | Error("malformed block record in AST file"); |
| 1764 | return Failure; |
| 1765 | } |
| 1766 | break; |
| 1767 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1768 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1769 | F.MacroCursor = Stream; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1770 | if (PP) |
| 1771 | PP->setExternalSource(this); |
| 1772 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1773 | if (Stream.SkipBlock() || |
| 1774 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1775 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1776 | return Failure; |
| 1777 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1778 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1779 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1780 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1781 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1782 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1783 | case Success: |
| 1784 | break; |
| 1785 | |
| 1786 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1787 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1788 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1789 | |
| 1790 | case IgnorePCH: |
| 1791 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1792 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1793 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1794 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1795 | First = false; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1796 | continue; |
| 1797 | } |
| 1798 | |
| 1799 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1800 | Stream.ReadAbbrevRecord(); |
| 1801 | continue; |
| 1802 | } |
| 1803 | |
| 1804 | // Read and process a record. |
| 1805 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1806 | const char *BlobStart = 0; |
| 1807 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1808 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1809 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1810 | default: // Default behavior: ignore. |
| 1811 | break; |
| 1812 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1813 | case METADATA: { |
| 1814 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1815 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1816 | : diag::warn_pch_version_too_new); |
| 1817 | return IgnorePCH; |
| 1818 | } |
| 1819 | |
| 1820 | RelocatablePCH = Record[4]; |
| 1821 | if (Listener) { |
| 1822 | std::string TargetTriple(BlobStart, BlobLen); |
| 1823 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1824 | return IgnorePCH; |
| 1825 | } |
| 1826 | break; |
| 1827 | } |
| 1828 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1829 | case CHAINED_METADATA: { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1830 | if (!First) { |
| 1831 | Error("CHAINED_METADATA is not first record in block"); |
| 1832 | return Failure; |
| 1833 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1834 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1835 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1836 | : diag::warn_pch_version_too_new); |
| 1837 | return IgnorePCH; |
| 1838 | } |
| 1839 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 1840 | // Load the chained file, which is always a PCH file. |
| 1841 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1842 | case Failure: return Failure; |
| 1843 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1844 | case IgnorePCH: return IgnorePCH; |
| 1845 | case Success: break; |
| 1846 | } |
| 1847 | break; |
| 1848 | } |
| 1849 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1850 | case TYPE_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1851 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1852 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1853 | return Failure; |
| 1854 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1855 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1856 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1857 | break; |
| 1858 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1859 | case DECL_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1860 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1861 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1862 | return Failure; |
| 1863 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1864 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 1865 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1866 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1867 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1868 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1869 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 1870 | /* No visible information */ 0, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 1871 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 1872 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1873 | }; |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 1874 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 1875 | .push_back(Info); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1876 | break; |
| 1877 | } |
| 1878 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1879 | case UPDATE_VISIBLE: { |
| 1880 | serialization::DeclID ID = Record[0]; |
| 1881 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 1882 | (const unsigned char *)BlobStart + Record[1], |
| 1883 | (const unsigned char *)BlobStart, |
| 1884 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 1885 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1886 | DeclContextInfo Info = { |
| 1887 | Table, /* No lexical inforamtion */ 0, 0 |
| 1888 | }; |
| 1889 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 1890 | } else |
| 1891 | PendingVisibleUpdates[ID].push_back(Table); |
| 1892 | break; |
| 1893 | } |
| 1894 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1895 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1896 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 1897 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1898 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1899 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 1900 | Latest > FirstLatestDeclIDs[First]) && |
| 1901 | "The new latest is supposed to come after the previous latest"); |
| 1902 | FirstLatestDeclIDs[First] = Latest; |
| 1903 | } |
| 1904 | break; |
| 1905 | } |
| 1906 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1907 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1908 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1909 | return IgnorePCH; |
| 1910 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1911 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1912 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1913 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1914 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1915 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1916 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1917 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 1918 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1919 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1920 | if (PP) |
| 1921 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1922 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1923 | break; |
| 1924 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1925 | case IDENTIFIER_OFFSET: |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1926 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1927 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1928 | return Failure; |
| 1929 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1930 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1931 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1932 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1933 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1934 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1935 | // Optimization for the first block. |
| 1936 | if (ExternalDefinitions.empty()) |
| 1937 | ExternalDefinitions.swap(Record); |
| 1938 | else |
| 1939 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 1940 | Record.begin(), Record.end()); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1941 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1942 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1943 | case SPECIAL_TYPES: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1944 | // Optimization for the first block |
| 1945 | if (SpecialTypes.empty()) |
| 1946 | SpecialTypes.swap(Record); |
| 1947 | else |
| 1948 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1949 | break; |
| 1950 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1951 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1952 | TotalNumStatements += Record[0]; |
| 1953 | TotalNumMacros += Record[1]; |
| 1954 | TotalLexicalDeclContexts += Record[2]; |
| 1955 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1956 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1957 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1958 | case TENTATIVE_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1959 | // Optimization for the first block. |
| 1960 | if (TentativeDefinitions.empty()) |
| 1961 | TentativeDefinitions.swap(Record); |
| 1962 | else |
| 1963 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 1964 | Record.begin(), Record.end()); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 1965 | break; |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1966 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1967 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1968 | // Optimization for the first block. |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 1969 | if (UnusedFileScopedDecls.empty()) |
| 1970 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1971 | else |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 1972 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 1973 | Record.begin(), Record.end()); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 1974 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1975 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1976 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 1977 | // Later blocks overwrite earlier ones. |
| 1978 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 1979 | break; |
| 1980 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1981 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1982 | // Optimization for the first block. |
| 1983 | if (LocallyScopedExternalDecls.empty()) |
| 1984 | LocallyScopedExternalDecls.swap(Record); |
| 1985 | else |
| 1986 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 1987 | Record.begin(), Record.end()); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1988 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1989 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1990 | case SELECTOR_OFFSETS: |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 1991 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1992 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1993 | break; |
| 1994 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1995 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1996 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1997 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1998 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1999 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2000 | F.SelectorLookupTableData + Record[0], |
| 2001 | F.SelectorLookupTableData, |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2002 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2003 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2004 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2005 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2006 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2007 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2008 | break; |
| 2009 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2010 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2011 | if (!Record.empty() && Listener) |
| 2012 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2013 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2014 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2015 | case SOURCE_LOCATION_OFFSETS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2016 | F.SLocOffsets = (const uint32_t *)BlobStart; |
| 2017 | F.LocalNumSLocEntries = Record[0]; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2018 | F.LocalSLocSize = Record[1]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2019 | break; |
| 2020 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2021 | case SOURCE_LOCATION_PRELOADS: |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2022 | if (PreloadSLocEntries.empty()) |
| 2023 | PreloadSLocEntries.swap(Record); |
| 2024 | else |
| 2025 | PreloadSLocEntries.insert(PreloadSLocEntries.end(), |
| 2026 | Record.begin(), Record.end()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2027 | break; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2028 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2029 | case STAT_CACHE: { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2030 | ASTStatCache *MyStatCache = |
| 2031 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2032 | (const unsigned char *)BlobStart, |
| 2033 | NumStatHits, NumStatMisses); |
| 2034 | FileMgr.addStatCache(MyStatCache); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2035 | F.StatCache = MyStatCache; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2036 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2037 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2038 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2039 | case EXT_VECTOR_DECLS: |
Sebastian Redl | a9f2368 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 2040 | // Optimization for the first block. |
| 2041 | if (ExtVectorDecls.empty()) |
| 2042 | ExtVectorDecls.swap(Record); |
| 2043 | else |
| 2044 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 2045 | Record.begin(), Record.end()); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2046 | break; |
| 2047 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2048 | case VTABLE_USES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2049 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2050 | VTableUses.swap(Record); |
| 2051 | break; |
| 2052 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2053 | case DYNAMIC_CLASSES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2054 | // Optimization for the first block. |
| 2055 | if (DynamicClasses.empty()) |
| 2056 | DynamicClasses.swap(Record); |
| 2057 | else |
| 2058 | DynamicClasses.insert(DynamicClasses.end(), |
| 2059 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2060 | break; |
| 2061 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2062 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2063 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2064 | break; |
| 2065 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2066 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2067 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2068 | SemaDeclRefs.swap(Record); |
| 2069 | break; |
| 2070 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2071 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2072 | // 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] | 2073 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2074 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2075 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2076 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2077 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2078 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2079 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2080 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2081 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 2082 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2083 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2084 | return IgnorePCH; |
| 2085 | } |
| 2086 | break; |
| 2087 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2088 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2089 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2090 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2091 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2092 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2093 | break; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2094 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2095 | case DECL_UPDATE_OFFSETS: { |
| 2096 | if (Record.size() % 2 != 0) { |
| 2097 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2098 | return Failure; |
| 2099 | } |
| 2100 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
| 2101 | DeclUpdateOffsets[static_cast<DeclID>(Record[I])] |
| 2102 | .push_back(std::make_pair(&F, Record[I+1])); |
| 2103 | break; |
| 2104 | } |
| 2105 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2106 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2107 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2108 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2109 | return Failure; |
| 2110 | } |
| 2111 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2112 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2113 | std::make_pair(&F, Record[I+1]); |
| 2114 | break; |
| 2115 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2116 | |
| 2117 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2118 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2119 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2120 | return Failure; |
| 2121 | } |
| 2122 | |
| 2123 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2124 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
| 2125 | break; |
| 2126 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2127 | |
| 2128 | case DIAG_USER_MAPPINGS: |
| 2129 | if (Record.size() % 2 != 0) { |
| 2130 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2131 | return Failure; |
| 2132 | } |
| 2133 | if (UserDiagMappings.empty()) |
| 2134 | UserDiagMappings.swap(Record); |
| 2135 | else |
| 2136 | UserDiagMappings.insert(UserDiagMappings.end(), |
| 2137 | Record.begin(), Record.end()); |
| 2138 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2139 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2140 | First = false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2141 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2142 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2143 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2146 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2147 | ASTFileType Type) { |
| 2148 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2149 | case Failure: return Failure; |
| 2150 | case IgnorePCH: return IgnorePCH; |
| 2151 | case Success: break; |
| 2152 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2153 | |
| 2154 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2155 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2156 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2157 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2158 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2159 | TotalNumSelectors = 0; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2160 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2161 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2162 | NextSLocOffset += Chain[I]->LocalSLocSize; |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2163 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2164 | TotalNumTypes += Chain[I]->LocalNumTypes; |
| 2165 | TotalNumDecls += Chain[I]->LocalNumDecls; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2166 | TotalNumPreallocatedPreprocessingEntities += |
| 2167 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2168 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2169 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2170 | } |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2171 | SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset); |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2172 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2173 | TypesLoaded.resize(TotalNumTypes); |
| 2174 | DeclsLoaded.resize(TotalNumDecls); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2175 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2176 | if (PP) { |
| 2177 | if (TotalNumIdentifiers > 0) |
| 2178 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2179 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2180 | if (!PP->getPreprocessingRecord()) |
| 2181 | PP->createPreprocessingRecord(); |
| 2182 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2183 | TotalNumPreallocatedPreprocessingEntities); |
| 2184 | } |
| 2185 | } |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2186 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2187 | // Preload SLocEntries. |
| 2188 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2189 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2190 | if (Result != Success) |
| 2191 | return Result; |
| 2192 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2193 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2194 | // Check the predefines buffers. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2195 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2196 | return IgnorePCH; |
| 2197 | |
| 2198 | if (PP) { |
| 2199 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2200 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2201 | // loaded into the IdentifierTable before we intercepted the |
| 2202 | // creation of identifiers. Iterate through the list of known |
| 2203 | // identifiers and determine whether we have to establish |
| 2204 | // preprocessor definitions or top-level identifier declaration |
| 2205 | // chains for those identifiers. |
| 2206 | // |
| 2207 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2208 | // since de-serializing declarations or macro definitions can add |
| 2209 | // new entries into the identifier table, invalidating the |
| 2210 | // iterators. |
| 2211 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2212 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2213 | IdEnd = PP->getIdentifierTable().end(); |
| 2214 | Id != IdEnd; ++Id) |
| 2215 | Identifiers.push_back(Id->second); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2216 | // We need to search the tables in all files. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2217 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2218 | ASTIdentifierLookupTable *IdTable |
| 2219 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2220 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2221 | // ones. |
| 2222 | if (!IdTable) |
| 2223 | continue; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2224 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2225 | IdentifierInfo *II = Identifiers[I]; |
| 2226 | // Look in the on-disk hash tables for an entry for this identifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2227 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2228 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2229 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2230 | if (Pos == IdTable->end()) |
| 2231 | continue; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2232 | |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2233 | // Dereferencing the iterator has the effect of populating the |
| 2234 | // IdentifierInfo node with the various declarations it needs. |
| 2235 | (void)*Pos; |
| 2236 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2237 | } |
| 2238 | } |
| 2239 | |
| 2240 | if (Context) |
| 2241 | InitializeContext(*Context); |
| 2242 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2243 | if (DeserializationListener) |
| 2244 | DeserializationListener->ReaderInitialized(this); |
| 2245 | |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2246 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2247 | // the source manager to the file source file from which the preamble was |
| 2248 | // built. This is the only valid way to use a precompiled preamble. |
| 2249 | if (Type == Preamble) { |
| 2250 | SourceLocation Loc |
| 2251 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2252 | if (Loc.isValid()) { |
| 2253 | std::pair<FileID, unsigned> Decomposed = SourceMgr.getDecomposedLoc(Loc); |
| 2254 | SourceMgr.SetPreambleFileID(Decomposed.first); |
| 2255 | } |
| 2256 | } |
| 2257 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2258 | return Success; |
| 2259 | } |
| 2260 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2261 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2262 | ASTFileType Type) { |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2263 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2264 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2265 | PerFileData &F = *Chain.back(); |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2266 | if (Prev) |
| 2267 | Prev->NextInSource = &F; |
| 2268 | else |
| 2269 | FirstInSource = &F; |
| 2270 | F.Loaders.push_back(Prev); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2271 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2272 | // Set the AST file name. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2273 | F.FileName = FileName; |
| 2274 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2275 | // Open the AST file. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2276 | // |
| 2277 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2278 | std::string ErrStr; |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 2279 | llvm::error_code ec; |
| 2280 | if (FileName == "-") { |
| 2281 | F.Buffer.reset(llvm::MemoryBuffer::getSTDIN(ec)); |
| 2282 | if (ec) |
| 2283 | ErrStr = ec.message(); |
| 2284 | } else |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2285 | F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr)); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2286 | if (!F.Buffer) { |
| 2287 | Error(ErrStr.c_str()); |
| 2288 | return IgnorePCH; |
| 2289 | } |
| 2290 | |
| 2291 | // Initialize the stream |
| 2292 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2293 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2294 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2295 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2296 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2297 | |
| 2298 | // Sniff for the signature. |
| 2299 | if (Stream.Read(8) != 'C' || |
| 2300 | Stream.Read(8) != 'P' || |
| 2301 | Stream.Read(8) != 'C' || |
| 2302 | Stream.Read(8) != 'H') { |
| 2303 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2304 | return Failure; |
| 2305 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2306 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2307 | while (!Stream.AtEndOfStream()) { |
| 2308 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2309 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2310 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2311 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2312 | return Failure; |
| 2313 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2314 | |
| 2315 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2316 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2317 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2318 | switch (BlockID) { |
| 2319 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2320 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2321 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2322 | return Failure; |
| 2323 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2324 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2325 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2326 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2327 | case Success: |
| 2328 | break; |
| 2329 | |
| 2330 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2331 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2332 | |
| 2333 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2334 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2335 | // AST block, skipping subblocks, to see if there are other |
| 2336 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2337 | |
| 2338 | // Clear out any preallocated source location entries, so that |
| 2339 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2340 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2341 | |
| 2342 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2343 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2344 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2345 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2346 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2347 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2348 | break; |
| 2349 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2350 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2351 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2352 | return Failure; |
| 2353 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2354 | break; |
| 2355 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2356 | } |
| 2357 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2358 | return Success; |
| 2359 | } |
| 2360 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2361 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2362 | PP = &pp; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2363 | |
| 2364 | unsigned TotalNum = 0; |
| 2365 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2366 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2367 | if (TotalNum) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2368 | if (!PP->getPreprocessingRecord()) |
| 2369 | PP->createPreprocessingRecord(); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2370 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2371 | } |
| 2372 | } |
| 2373 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2374 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2375 | Context = &Ctx; |
| 2376 | assert(Context && "Passed null context!"); |
| 2377 | |
| 2378 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2379 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2380 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2381 | PP->setExternalSource(this); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2382 | |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2383 | // If we have an update block for the TU waiting, we have to add it before |
| 2384 | // deserializing the decl. |
| 2385 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2386 | if (DCU != DeclContextOffsets.end()) { |
| 2387 | // Insertion could invalidate map, so grab vector. |
| 2388 | DeclContextInfos T; |
| 2389 | T.swap(DCU->second); |
| 2390 | DeclContextOffsets.erase(DCU); |
| 2391 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2392 | } |
| 2393 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2394 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2395 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2396 | |
| 2397 | // Load the special types. |
| 2398 | Context->setBuiltinVaListType( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2399 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2400 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2401 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2402 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2403 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2404 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2405 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2406 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2407 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2408 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2409 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2410 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2411 | if (unsigned FastEnum |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2412 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2413 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2414 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2415 | QualType FileType = GetType(File); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2416 | if (FileType.isNull()) { |
| 2417 | Error("FILE type is NULL"); |
| 2418 | return; |
| 2419 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2420 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2421 | Context->setFILEDecl(Typedef->getDecl()); |
| 2422 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2423 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2424 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2425 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2426 | return; |
| 2427 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2428 | Context->setFILEDecl(Tag->getDecl()); |
| 2429 | } |
| 2430 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2431 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2432 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2433 | if (Jmp_bufType.isNull()) { |
| 2434 | Error("jmp_bug type is NULL"); |
| 2435 | return; |
| 2436 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2437 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2438 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2439 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2440 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2441 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2442 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2443 | return; |
| 2444 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2445 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2446 | } |
| 2447 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2448 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2449 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2450 | if (Sigjmp_bufType.isNull()) { |
| 2451 | Error("sigjmp_buf type is NULL"); |
| 2452 | return; |
| 2453 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2454 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2455 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2456 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2457 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2458 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2459 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2460 | } |
| 2461 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2462 | if (unsigned ObjCIdRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2463 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2464 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2465 | if (unsigned ObjCClassRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2466 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2467 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2468 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2469 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2470 | if (unsigned String |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2471 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2472 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2473 | if (unsigned ObjCSelRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2474 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2475 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2476 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2477 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2478 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2479 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2480 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2481 | |
| 2482 | ReadUserDiagnosticMappings(Context->getDiagnostics()); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2483 | } |
| 2484 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2485 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2486 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2487 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2488 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2489 | FileManager &FileMgr, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2490 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2491 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2492 | std::string ErrStr; |
| 2493 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2494 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2495 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2496 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2497 | return std::string(); |
| 2498 | } |
| 2499 | |
| 2500 | // Initialize the stream |
| 2501 | llvm::BitstreamReader StreamFile; |
| 2502 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2503 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2504 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2505 | Stream.init(StreamFile); |
| 2506 | |
| 2507 | // Sniff for the signature. |
| 2508 | if (Stream.Read(8) != 'C' || |
| 2509 | Stream.Read(8) != 'P' || |
| 2510 | Stream.Read(8) != 'C' || |
| 2511 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2512 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2513 | return std::string(); |
| 2514 | } |
| 2515 | |
| 2516 | RecordData Record; |
| 2517 | while (!Stream.AtEndOfStream()) { |
| 2518 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2519 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2520 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2521 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2522 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2523 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2524 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2525 | case AST_BLOCK_ID: |
| 2526 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2527 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2528 | return std::string(); |
| 2529 | } |
| 2530 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2531 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2532 | default: |
| 2533 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2534 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2535 | return std::string(); |
| 2536 | } |
| 2537 | break; |
| 2538 | } |
| 2539 | continue; |
| 2540 | } |
| 2541 | |
| 2542 | if (Code == llvm::bitc::END_BLOCK) { |
| 2543 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2544 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2545 | return std::string(); |
| 2546 | } |
| 2547 | continue; |
| 2548 | } |
| 2549 | |
| 2550 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2551 | Stream.ReadAbbrevRecord(); |
| 2552 | continue; |
| 2553 | } |
| 2554 | |
| 2555 | Record.clear(); |
| 2556 | const char *BlobStart = 0; |
| 2557 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2558 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2559 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2560 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2561 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2562 | |
| 2563 | return std::string(); |
| 2564 | } |
| 2565 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2566 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2567 | /// structure. |
| 2568 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2569 | /// This routine parses the language options from the AST file and then gives |
| 2570 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2571 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2572 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2573 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2574 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2575 | if (Listener) { |
| 2576 | LangOptions LangOpts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2577 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2578 | #define PARSE_LANGOPT(Option) \ |
| 2579 | LangOpts.Option = Record[Idx]; \ |
| 2580 | ++Idx |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2581 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2582 | unsigned Idx = 0; |
| 2583 | PARSE_LANGOPT(Trigraphs); |
| 2584 | PARSE_LANGOPT(BCPLComment); |
| 2585 | PARSE_LANGOPT(DollarIdents); |
| 2586 | PARSE_LANGOPT(AsmPreprocessor); |
| 2587 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2588 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2589 | PARSE_LANGOPT(ImplicitInt); |
| 2590 | PARSE_LANGOPT(Digraphs); |
| 2591 | PARSE_LANGOPT(HexFloats); |
| 2592 | PARSE_LANGOPT(C99); |
| 2593 | PARSE_LANGOPT(Microsoft); |
| 2594 | PARSE_LANGOPT(CPlusPlus); |
| 2595 | PARSE_LANGOPT(CPlusPlus0x); |
| 2596 | PARSE_LANGOPT(CXXOperatorNames); |
| 2597 | PARSE_LANGOPT(ObjC1); |
| 2598 | PARSE_LANGOPT(ObjC2); |
| 2599 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 2600 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 2601 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2602 | PARSE_LANGOPT(PascalStrings); |
| 2603 | PARSE_LANGOPT(WritableStrings); |
| 2604 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2605 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2606 | PARSE_LANGOPT(Exceptions); |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 2607 | PARSE_LANGOPT(SjLjExceptions); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2608 | PARSE_LANGOPT(NeXTRuntime); |
| 2609 | PARSE_LANGOPT(Freestanding); |
| 2610 | PARSE_LANGOPT(NoBuiltin); |
| 2611 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 2612 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2613 | PARSE_LANGOPT(Blocks); |
| 2614 | PARSE_LANGOPT(EmitAllDecls); |
| 2615 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2616 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 2617 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2618 | PARSE_LANGOPT(HeinousExtensions); |
| 2619 | PARSE_LANGOPT(Optimize); |
| 2620 | PARSE_LANGOPT(OptimizeSize); |
| 2621 | PARSE_LANGOPT(Static); |
| 2622 | PARSE_LANGOPT(PICLevel); |
| 2623 | PARSE_LANGOPT(GNUInline); |
| 2624 | PARSE_LANGOPT(NoInline); |
| 2625 | PARSE_LANGOPT(AccessControl); |
| 2626 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2627 | PARSE_LANGOPT(ShortWChar); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2628 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2629 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 2630 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2631 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2632 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2633 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 2634 | PARSE_LANGOPT(CUDA); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2635 | PARSE_LANGOPT(CatchUndefined); |
| 2636 | // FIXME: Missing ElideConstructors?! |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2637 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2638 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2639 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2640 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2641 | |
| 2642 | return false; |
| 2643 | } |
| 2644 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2645 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2646 | ReadDefinedMacros(); |
| 2647 | } |
| 2648 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2649 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(uint64_t Offset) { |
| 2650 | PerFileData *F = 0; |
| 2651 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2652 | if (Offset < Chain[I]->SizeInBits) { |
| 2653 | F = Chain[I]; |
| 2654 | break; |
| 2655 | } |
| 2656 | |
| 2657 | Offset -= Chain[I]->SizeInBits; |
| 2658 | } |
| 2659 | |
| 2660 | if (!F) { |
| 2661 | Error("Malformed preprocessed entity offset"); |
| 2662 | return 0; |
| 2663 | } |
| 2664 | |
| 2665 | return ReadMacroRecord(*F, Offset); |
| 2666 | } |
| 2667 | |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2668 | void ASTReader::ReadUserDiagnosticMappings(Diagnostic &Diag) { |
| 2669 | unsigned Idx = 0; |
| 2670 | while (Idx < UserDiagMappings.size()) { |
| 2671 | unsigned DiagID = UserDiagMappings[Idx++]; |
| 2672 | unsigned Map = UserDiagMappings[Idx++]; |
| 2673 | Diag.setDiagnosticMappingInternal(DiagID, Map, /*isUser=*/true); |
| 2674 | } |
| 2675 | } |
| 2676 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2677 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2678 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2679 | PerFileData *F = 0; |
| 2680 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2681 | F = Chain[N - I - 1]; |
| 2682 | if (Index < F->LocalNumTypes) |
| 2683 | break; |
| 2684 | Index -= F->LocalNumTypes; |
| 2685 | } |
| 2686 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2687 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2691 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2692 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 2693 | /// routine actually reads the record corresponding to the type at the given |
| 2694 | /// location. It is a helper routine for GetType, which deals with reading type |
| 2695 | /// IDs. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2696 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2697 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2698 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2699 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2700 | // Keep track of where we are in the stream, then jump back there |
| 2701 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2702 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2703 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 2704 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 2705 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2706 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 2707 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2708 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2709 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2710 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2711 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2712 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 2713 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2714 | if (Record.size() != 2) { |
| 2715 | Error("Incorrect encoding of extended qualifier type"); |
| 2716 | return QualType(); |
| 2717 | } |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2718 | QualType Base = GetType(Record[0]); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2719 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 2720 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2721 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2722 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2723 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2724 | if (Record.size() != 1) { |
| 2725 | Error("Incorrect encoding of complex type"); |
| 2726 | return QualType(); |
| 2727 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2728 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2729 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2730 | } |
| 2731 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2732 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2733 | if (Record.size() != 1) { |
| 2734 | Error("Incorrect encoding of pointer type"); |
| 2735 | return QualType(); |
| 2736 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2737 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2738 | return Context->getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2741 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2742 | if (Record.size() != 1) { |
| 2743 | Error("Incorrect encoding of block pointer type"); |
| 2744 | return QualType(); |
| 2745 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2746 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2747 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2748 | } |
| 2749 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2750 | case TYPE_LVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2751 | if (Record.size() != 1) { |
| 2752 | Error("Incorrect encoding of lvalue reference type"); |
| 2753 | return QualType(); |
| 2754 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2755 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2756 | return Context->getLValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2757 | } |
| 2758 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2759 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2760 | if (Record.size() != 1) { |
| 2761 | Error("Incorrect encoding of rvalue reference type"); |
| 2762 | return QualType(); |
| 2763 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2764 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2765 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2768 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 2769 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2770 | Error("Incorrect encoding of member pointer type"); |
| 2771 | return QualType(); |
| 2772 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2773 | QualType PointeeType = GetType(Record[0]); |
| 2774 | QualType ClassType = GetType(Record[1]); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 2775 | if (PointeeType.isNull() || ClassType.isNull()) |
| 2776 | return QualType(); |
| 2777 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2778 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2779 | } |
| 2780 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2781 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2782 | QualType ElementType = GetType(Record[0]); |
| 2783 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2784 | unsigned IndexTypeQuals = Record[2]; |
| 2785 | unsigned Idx = 3; |
| 2786 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 2787 | return Context->getConstantArrayType(ElementType, Size, |
| 2788 | ASM, IndexTypeQuals); |
| 2789 | } |
| 2790 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2791 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2792 | QualType ElementType = GetType(Record[0]); |
| 2793 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2794 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2795 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2796 | } |
| 2797 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2798 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2799 | QualType ElementType = GetType(Record[0]); |
| 2800 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2801 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2802 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 2803 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 2804 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 2805 | ASM, IndexTypeQuals, |
| 2806 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2807 | } |
| 2808 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2809 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2810 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2811 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2812 | return QualType(); |
| 2813 | } |
| 2814 | |
| 2815 | QualType ElementType = GetType(Record[0]); |
| 2816 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 2817 | unsigned VecKind = Record[2]; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2818 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 2819 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2820 | } |
| 2821 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2822 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2823 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2824 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2825 | return QualType(); |
| 2826 | } |
| 2827 | |
| 2828 | QualType ElementType = GetType(Record[0]); |
| 2829 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2830 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2831 | } |
| 2832 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2833 | case TYPE_FUNCTION_NO_PROTO: { |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2834 | if (Record.size() != 4) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 2835 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2836 | return QualType(); |
| 2837 | } |
| 2838 | QualType ResultType = GetType(Record[0]); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2839 | FunctionType::ExtInfo Info(Record[1], Record[2], (CallingConv)Record[3]); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 2840 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2841 | } |
| 2842 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2843 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2844 | QualType ResultType = GetType(Record[0]); |
John McCall | 0e88aa7 | 2010-12-14 06:51:39 +0000 | [diff] [blame^] | 2845 | |
| 2846 | FunctionProtoType::ExtProtoInfo EPI; |
| 2847 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
| 2848 | /*regparm*/ Record[2], |
| 2849 | static_cast<CallingConv>(Record[3])); |
| 2850 | |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2851 | unsigned Idx = 4; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2852 | unsigned NumParams = Record[Idx++]; |
| 2853 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 2854 | for (unsigned I = 0; I != NumParams; ++I) |
| 2855 | ParamTypes.push_back(GetType(Record[Idx++])); |
John McCall | 0e88aa7 | 2010-12-14 06:51:39 +0000 | [diff] [blame^] | 2856 | |
| 2857 | EPI.Variadic = Record[Idx++]; |
| 2858 | EPI.TypeQuals = Record[Idx++]; |
| 2859 | EPI.HasExceptionSpec = Record[Idx++]; |
| 2860 | EPI.HasAnyExceptionSpec = Record[Idx++]; |
| 2861 | EPI.NumExceptions = Record[Idx++]; |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 2862 | llvm::SmallVector<QualType, 2> Exceptions; |
John McCall | 0e88aa7 | 2010-12-14 06:51:39 +0000 | [diff] [blame^] | 2863 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 2864 | Exceptions.push_back(GetType(Record[Idx++])); |
John McCall | 0e88aa7 | 2010-12-14 06:51:39 +0000 | [diff] [blame^] | 2865 | EPI.Exceptions = Exceptions.data(); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 2866 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | 0e88aa7 | 2010-12-14 06:51:39 +0000 | [diff] [blame^] | 2867 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2870 | case TYPE_UNRESOLVED_USING: |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2871 | return Context->getTypeDeclType( |
| 2872 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 2873 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2874 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2875 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2876 | Error("incorrect encoding of typedef type"); |
| 2877 | return QualType(); |
| 2878 | } |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2879 | TypedefDecl *Decl = cast<TypedefDecl>(GetDecl(Record[0])); |
| 2880 | QualType Canonical = GetType(Record[1]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 2881 | if (!Canonical.isNull()) |
| 2882 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2883 | return Context->getTypedefType(Decl, Canonical); |
| 2884 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2885 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2886 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2887 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2888 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2889 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2890 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2891 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2892 | return QualType(); |
| 2893 | } |
| 2894 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2895 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2896 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2897 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2898 | case TYPE_DECLTYPE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2899 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 2900 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2901 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2902 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2903 | Error("incorrect encoding of record type"); |
| 2904 | return QualType(); |
| 2905 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2906 | bool IsDependent = Record[0]; |
| 2907 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
John McCall | b870b88 | 2010-10-14 21:48:26 +0000 | [diff] [blame] | 2908 | T->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2909 | return T; |
| 2910 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2911 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2912 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2913 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2914 | Error("incorrect encoding of enum type"); |
| 2915 | return QualType(); |
| 2916 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2917 | bool IsDependent = Record[0]; |
| 2918 | QualType T = Context->getEnumType(cast<EnumDecl>(GetDecl(Record[1]))); |
John McCall | b870b88 | 2010-10-14 21:48:26 +0000 | [diff] [blame] | 2919 | T->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2920 | return T; |
| 2921 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2922 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 2923 | case TYPE_PAREN: { |
| 2924 | if (Record.size() != 1) { |
| 2925 | Error("incorrect encoding of paren type"); |
| 2926 | return QualType(); |
| 2927 | } |
| 2928 | QualType InnerType = GetType(Record[0]); |
| 2929 | return Context->getParenType(InnerType); |
| 2930 | } |
| 2931 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2932 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 2933 | unsigned Idx = 0; |
| 2934 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 2935 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 2936 | QualType NamedType = GetType(Record[Idx++]); |
| 2937 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2938 | } |
| 2939 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2940 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2941 | unsigned Idx = 0; |
| 2942 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2943 | return Context->getObjCInterfaceType(ItfD); |
| 2944 | } |
| 2945 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2946 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2947 | unsigned Idx = 0; |
| 2948 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2949 | unsigned NumProtos = Record[Idx++]; |
| 2950 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 2951 | for (unsigned I = 0; I != NumProtos; ++I) |
| 2952 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2953 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2954 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2955 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2956 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 2957 | unsigned Idx = 0; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2958 | QualType Pointee = GetType(Record[Idx++]); |
| 2959 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 2960 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2961 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2962 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2963 | unsigned Idx = 0; |
| 2964 | QualType Parm = GetType(Record[Idx++]); |
| 2965 | QualType Replacement = GetType(Record[Idx++]); |
| 2966 | return |
| 2967 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 2968 | Replacement); |
| 2969 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2970 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2971 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2972 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 2973 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 2974 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2975 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 2976 | return |
| 2977 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2978 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2979 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2980 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2981 | unsigned Idx = 0; |
| 2982 | unsigned Depth = Record[Idx++]; |
| 2983 | unsigned Index = Record[Idx++]; |
| 2984 | bool Pack = Record[Idx++]; |
| 2985 | IdentifierInfo *Name = GetIdentifierInfo(Record, Idx); |
| 2986 | return Context->getTemplateTypeParmType(Depth, Index, Pack, Name); |
| 2987 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2988 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2989 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 2990 | unsigned Idx = 0; |
| 2991 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 2992 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 2993 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 2994 | QualType Canon = GetType(Record[Idx++]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 2995 | if (!Canon.isNull()) |
| 2996 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 2997 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 2998 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2999 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3000 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3001 | unsigned Idx = 0; |
| 3002 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3003 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3004 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
| 3005 | unsigned NumArgs = Record[Idx++]; |
| 3006 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 3007 | Args.reserve(NumArgs); |
| 3008 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3009 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3010 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3011 | Args.size(), Args.data()); |
| 3012 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3013 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3014 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3015 | unsigned Idx = 0; |
| 3016 | |
| 3017 | // ArrayType |
| 3018 | QualType ElementType = GetType(Record[Idx++]); |
| 3019 | ArrayType::ArraySizeModifier ASM |
| 3020 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3021 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3022 | |
| 3023 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3024 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3025 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3026 | |
| 3027 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3028 | IndexTypeQuals, Brackets); |
| 3029 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3030 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3031 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3032 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3033 | bool IsDependent = Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3034 | TemplateName Name = ReadTemplateName(Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3035 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3036 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3037 | QualType Canon = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3038 | QualType T; |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3039 | if (Canon.isNull()) |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3040 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3041 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3042 | else |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3043 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
| 3044 | Args.size(), Canon); |
John McCall | b870b88 | 2010-10-14 21:48:26 +0000 | [diff] [blame] | 3045 | T->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3046 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3047 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3048 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3049 | // Suppress a GCC warning |
| 3050 | return QualType(); |
| 3051 | } |
| 3052 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3053 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3054 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3055 | ASTReader::PerFileData &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3056 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3057 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3058 | unsigned &Idx; |
| 3059 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3060 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3061 | unsigned &I) { |
| 3062 | return Reader.ReadSourceLocation(F, R, I); |
| 3063 | } |
| 3064 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3065 | public: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3066 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3067 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3068 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3069 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3070 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3071 | // We want compile-time assurance that we've enumerated all of |
| 3072 | // these, so unfortunately we have to declare them first, then |
| 3073 | // define them out-of-line. |
| 3074 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3075 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3076 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3077 | #include "clang/AST/TypeLocNodes.def" |
| 3078 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3079 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3080 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3081 | }; |
| 3082 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3083 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3084 | // nothing to do |
| 3085 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3086 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3087 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3088 | if (TL.needsExtraLocalData()) { |
| 3089 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3090 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3091 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3092 | TL.setModeAttr(Record[Idx++]); |
| 3093 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3094 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3095 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3096 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3097 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3098 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3099 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3100 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3101 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3102 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3103 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3104 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3105 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3106 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3107 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3108 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3109 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3110 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3111 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3112 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3113 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3114 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3115 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3116 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3117 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3118 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3119 | TL.setSizeExpr(0); |
| 3120 | } |
| 3121 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3122 | VisitArrayTypeLoc(TL); |
| 3123 | } |
| 3124 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3125 | VisitArrayTypeLoc(TL); |
| 3126 | } |
| 3127 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3128 | VisitArrayTypeLoc(TL); |
| 3129 | } |
| 3130 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3131 | DependentSizedArrayTypeLoc TL) { |
| 3132 | VisitArrayTypeLoc(TL); |
| 3133 | } |
| 3134 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3135 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3136 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3137 | } |
| 3138 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3139 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3140 | } |
| 3141 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3142 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3143 | } |
| 3144 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3145 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3146 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3147 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3148 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | 86acc2a | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 3149 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3150 | } |
| 3151 | } |
| 3152 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3153 | VisitFunctionTypeLoc(TL); |
| 3154 | } |
| 3155 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3156 | VisitFunctionTypeLoc(TL); |
| 3157 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3158 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3159 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3160 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3161 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3162 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3163 | } |
| 3164 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3165 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3166 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3167 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3168 | } |
| 3169 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3170 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3171 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3172 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3173 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3174 | } |
| 3175 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3176 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3177 | } |
| 3178 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3179 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3180 | } |
| 3181 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3182 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3183 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3184 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3185 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3186 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3187 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3188 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3189 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3190 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3191 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3192 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3193 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3194 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3195 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3196 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3197 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3198 | Reader.GetTemplateArgumentLocInfo(F, |
| 3199 | TL.getTypePtr()->getArg(i).getKind(), |
| 3200 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3201 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3202 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3203 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3204 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3205 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3206 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3207 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3208 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3209 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3210 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3211 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3212 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3213 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3214 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3215 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3216 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3217 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3218 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3219 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3220 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3221 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3222 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3223 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3224 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3225 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3226 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3227 | Reader.GetTemplateArgumentLocInfo(F, |
| 3228 | TL.getTypePtr()->getArg(I).getKind(), |
| 3229 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3230 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3231 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3232 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3233 | } |
| 3234 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3235 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3236 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3237 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3238 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3239 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3240 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3241 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3242 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3243 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3244 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3245 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3246 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3247 | unsigned &Idx) { |
| 3248 | QualType InfoTy = GetType(Record[Idx++]); |
| 3249 | if (InfoTy.isNull()) |
| 3250 | return 0; |
| 3251 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3252 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3253 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3254 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3255 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3256 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3257 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3258 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3259 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3260 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3261 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3262 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3263 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3264 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3265 | switch ((PredefinedTypeIDs)Index) { |
| 3266 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3267 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3268 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3269 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3270 | case PREDEF_TYPE_CHAR_U_ID: |
| 3271 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3272 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3273 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3274 | break; |
| 3275 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3276 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3277 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3278 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3279 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3280 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3281 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3282 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3283 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3284 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3285 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3286 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3287 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3288 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3289 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3290 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3291 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3292 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
| 3293 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
| 3294 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3295 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3296 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3297 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3298 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3299 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3303 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3304 | } |
| 3305 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3306 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3307 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3308 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3309 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3310 | if (TypesLoaded[Index].isNull()) |
| 3311 | return QualType(); |
| 3312 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3313 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3314 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3315 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3316 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3317 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3318 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3319 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3320 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3321 | } |
| 3322 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3323 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3324 | return MakeTypeID(T, |
| 3325 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3326 | } |
| 3327 | |
| 3328 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3329 | if (T.isNull()) |
| 3330 | return TypeIdx(); |
| 3331 | assert(!T.getLocalFastQualifiers()); |
| 3332 | |
| 3333 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3334 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3335 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3336 | // If the type didn't come from the AST file use a specially marked index |
| 3337 | // so that any hash/key comparison fail since no such index is stored |
| 3338 | // in a AST file. |
| 3339 | if (I == TypeIdxs.end()) |
| 3340 | return TypeIdx(-1); |
| 3341 | return I->second; |
| 3342 | } |
| 3343 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3344 | unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const { |
| 3345 | unsigned Result = 0; |
| 3346 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 3347 | Result += Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3348 | |
| 3349 | return Result; |
| 3350 | } |
| 3351 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3352 | TemplateArgumentLocInfo |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3353 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3354 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3355 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3356 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3357 | switch (Kind) { |
| 3358 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3359 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3360 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3361 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3362 | case TemplateArgument::Template: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3363 | SourceRange QualifierRange = ReadSourceRange(F, Record, Index); |
| 3364 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3365 | return TemplateArgumentLocInfo(QualifierRange, TemplateNameLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3366 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3367 | case TemplateArgument::Null: |
| 3368 | case TemplateArgument::Integral: |
| 3369 | case TemplateArgument::Declaration: |
| 3370 | case TemplateArgument::Pack: |
| 3371 | return TemplateArgumentLocInfo(); |
| 3372 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3373 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3374 | return TemplateArgumentLocInfo(); |
| 3375 | } |
| 3376 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3377 | TemplateArgumentLoc |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3378 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3379 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3380 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3381 | |
| 3382 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3383 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3384 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3385 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3386 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3387 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3388 | } |
| 3389 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3390 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3391 | return GetDecl(ID); |
| 3392 | } |
| 3393 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3394 | uint64_t |
| 3395 | ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) { |
| 3396 | if (ID == 0) |
| 3397 | return 0; |
| 3398 | |
| 3399 | --ID; |
| 3400 | uint64_t Offset = 0; |
| 3401 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3402 | if (ID < Chain[I]->LocalNumCXXBaseSpecifiers) |
| 3403 | return Offset + Chain[I]->CXXBaseSpecifiersOffsets[ID]; |
| 3404 | |
| 3405 | ID -= Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3406 | Offset += Chain[I]->SizeInBits; |
| 3407 | } |
| 3408 | |
| 3409 | assert(false && "CXXBaseSpecifiers not found"); |
| 3410 | return 0; |
| 3411 | } |
| 3412 | |
| 3413 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 3414 | // Figure out which AST file contains this offset. |
| 3415 | PerFileData *F = 0; |
| 3416 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3417 | if (Offset < Chain[I]->SizeInBits) { |
| 3418 | F = Chain[I]; |
| 3419 | break; |
| 3420 | } |
| 3421 | |
| 3422 | Offset -= Chain[I]->SizeInBits; |
| 3423 | } |
| 3424 | |
| 3425 | if (!F) { |
| 3426 | Error("Malformed AST file: C++ base specifiers at impossible offset"); |
| 3427 | return 0; |
| 3428 | } |
| 3429 | |
| 3430 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3431 | SavedStreamPosition SavedPosition(Cursor); |
| 3432 | Cursor.JumpToBit(Offset); |
| 3433 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3434 | RecordData Record; |
| 3435 | unsigned Code = Cursor.ReadCode(); |
| 3436 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 3437 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 3438 | Error("Malformed AST file: missing C++ base specifiers"); |
| 3439 | return 0; |
| 3440 | } |
| 3441 | |
| 3442 | unsigned Idx = 0; |
| 3443 | unsigned NumBases = Record[Idx++]; |
| 3444 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 3445 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 3446 | for (unsigned I = 0; I != NumBases; ++I) |
| 3447 | Bases[I] = ReadCXXBaseSpecifier(*F, Record, Idx); |
| 3448 | return Bases; |
| 3449 | } |
| 3450 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3451 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3452 | if (!DeclsLoaded[0]) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 3453 | ReadDeclRecord(0, 1); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3454 | if (DeserializationListener) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3455 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3456 | } |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 3457 | |
| 3458 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 3459 | } |
| 3460 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3461 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3462 | if (ID == 0) |
| 3463 | return 0; |
| 3464 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3465 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3466 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3467 | return 0; |
| 3468 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3469 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3470 | unsigned Index = ID - 1; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3471 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3472 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3473 | if (DeserializationListener) |
| 3474 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3475 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3476 | |
| 3477 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3478 | } |
| 3479 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3480 | /// \brief Resolve the offset of a statement into a statement. |
| 3481 | /// |
| 3482 | /// This operation will read a new statement from the external |
| 3483 | /// source each time it is called, and is meant to be used via a |
| 3484 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3485 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 3486 | // Switch case IDs are per Decl. |
| 3487 | ClearSwitchCaseIDs(); |
| 3488 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3489 | // Offset here is a global offset across the entire chain. |
| 3490 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3491 | PerFileData &F = *Chain[N - I - 1]; |
| 3492 | if (Offset < F.SizeInBits) { |
| 3493 | // Since we know that this statement is part of a decl, make sure to use |
| 3494 | // the decl cursor to read it. |
| 3495 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3496 | return ReadStmtFromStream(F); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3497 | } |
| 3498 | Offset -= F.SizeInBits; |
| 3499 | } |
| 3500 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 3501 | } |
| 3502 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3503 | bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3504 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3505 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3506 | assert(DC->hasExternalLexicalStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3507 | "DeclContext has no lexical decls in storage"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3508 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3509 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 3510 | // at least. |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3511 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 3512 | // so make a copy of the vector. |
| 3513 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3514 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3515 | I != E; ++I) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3516 | // IDs can be 0 if this context doesn't contain declarations. |
| 3517 | if (!I->LexicalDecls) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3518 | continue; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3519 | |
| 3520 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3521 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 3522 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 3523 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 3524 | continue; |
| 3525 | |
| 3526 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3527 | assert(D && "Null decl in lexical decls"); |
| 3528 | Decls.push_back(D); |
| 3529 | } |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3530 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3531 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3532 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3533 | return false; |
| 3534 | } |
| 3535 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3536 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3537 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3538 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3539 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3540 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3541 | if (!Name) |
| 3542 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 3543 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3544 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3545 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 8b12273 | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 3546 | // There might be visible decls in multiple parts of the chain, for the TU |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3547 | // and namespaces. For any given name, the last available results replace |
| 3548 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3549 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3550 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3551 | I != E; ++I) { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3552 | if (!I->NameLookupTableData) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3553 | continue; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3554 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3555 | ASTDeclContextNameLookupTable *LookupTable = |
| 3556 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3557 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 3558 | if (Pos == LookupTable->end()) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3559 | continue; |
| 3560 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3561 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 3562 | for (; Data.first != Data.second; ++Data.first) |
| 3563 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3564 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3565 | } |
| 3566 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3567 | ++NumVisibleDeclContextsRead; |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3568 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3569 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3570 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3571 | } |
| 3572 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 3573 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 3574 | assert(DC->hasExternalVisibleStorage() && |
| 3575 | "DeclContext has no visible decls in storage"); |
| 3576 | |
| 3577 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 3578 | // There might be visible decls in multiple parts of the chain, for the TU |
| 3579 | // and namespaces. |
| 3580 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 3581 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3582 | I != E; ++I) { |
| 3583 | if (!I->NameLookupTableData) |
| 3584 | continue; |
| 3585 | |
| 3586 | ASTDeclContextNameLookupTable *LookupTable = |
| 3587 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3588 | for (ASTDeclContextNameLookupTable::item_iterator |
| 3589 | ItemI = LookupTable->item_begin(), |
| 3590 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 3591 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 3592 | = *ItemI; |
| 3593 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 3594 | Decls.clear(); |
| 3595 | for (; Data.first != Data.second; ++Data.first) |
| 3596 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 3597 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 3598 | } |
| 3599 | } |
| 3600 | } |
| 3601 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3602 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3603 | assert(Consumer); |
| 3604 | while (!InterestingDecls.empty()) { |
| 3605 | DeclGroupRef DG(InterestingDecls.front()); |
| 3606 | InterestingDecls.pop_front(); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3607 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3608 | } |
| 3609 | } |
| 3610 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3611 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 3612 | this->Consumer = Consumer; |
| 3613 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3614 | if (!Consumer) |
| 3615 | return; |
| 3616 | |
| 3617 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3618 | // Force deserialization of this decl, which will cause it to be queued for |
| 3619 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 3620 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3621 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 3622 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3623 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3624 | } |
| 3625 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3626 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3627 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3628 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3629 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3630 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3631 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3632 | unsigned NumDeclsLoaded |
| 3633 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 3634 | (Decl *)0); |
| 3635 | unsigned NumIdentifiersLoaded |
| 3636 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 3637 | IdentifiersLoaded.end(), |
| 3638 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3639 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3640 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 3641 | SelectorsLoaded.end(), |
| 3642 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 3643 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3644 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 3645 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 3646 | if (TotalNumSLocEntries) |
| 3647 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 3648 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 3649 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3650 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3651 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3652 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 3653 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 3654 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3655 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3656 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 3657 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3658 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3659 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3660 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 3661 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3662 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3663 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3664 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 3665 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3666 | if (TotalNumStatements) |
| 3667 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 3668 | NumStatementsRead, TotalNumStatements, |
| 3669 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 3670 | if (TotalNumMacros) |
| 3671 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 3672 | NumMacrosRead, TotalNumMacros, |
| 3673 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 3674 | if (TotalLexicalDeclContexts) |
| 3675 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 3676 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 3677 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 3678 | * 100)); |
| 3679 | if (TotalVisibleDeclContexts) |
| 3680 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 3681 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 3682 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 3683 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3684 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3685 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3686 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 3687 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3688 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3689 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3690 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3691 | std::fprintf(stderr, "\n"); |
| 3692 | } |
| 3693 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3694 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3695 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3696 | S.ExternalSource = this; |
| 3697 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 3698 | // Makes sure any declarations that were deserialized "too early" |
| 3699 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3700 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 3701 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 3702 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3703 | |
| 3704 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3705 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 3706 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3707 | |
| 3708 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 3709 | // them to Sema's list of tentative definitions. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3710 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 3711 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 3712 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3713 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 3714 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3715 | // If there were any unused file scoped decls, deserialize them and add to |
| 3716 | // Sema's list of unused file scoped decls. |
| 3717 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 3718 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 3719 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 3720 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3721 | |
| 3722 | // If there were any locally-scoped external declarations, |
| 3723 | // deserialize them and add them to Sema's table of locally-scoped |
| 3724 | // external declarations. |
| 3725 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 3726 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 3727 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 3728 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3729 | |
| 3730 | // If there were any ext_vector type declarations, deserialize them |
| 3731 | // and add them to Sema's vector of such declarations. |
| 3732 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 3733 | SemaObj->ExtVectorDecls.push_back( |
| 3734 | cast<TypedefDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3735 | |
| 3736 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 3737 | // Can we cut them down before writing them ? |
| 3738 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3739 | // If there were any dynamic classes declarations, deserialize them |
| 3740 | // and add them to Sema's vector of such declarations. |
| 3741 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 3742 | SemaObj->DynamicClasses.push_back( |
| 3743 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3744 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3745 | // Load the offsets of the declarations that Sema references. |
| 3746 | // They will be lazily deserialized when needed. |
| 3747 | if (!SemaDeclRefs.empty()) { |
| 3748 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 3749 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 3750 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 3751 | } |
| 3752 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3753 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 3754 | |
| 3755 | // If there are @selector references added them to its pool. This is for |
| 3756 | // implementation of -Wselector. |
| 3757 | if (!F->ReferencedSelectorsData.empty()) { |
| 3758 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 3759 | unsigned I = 0; |
| 3760 | while (I < DataSize) { |
| 3761 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 3762 | SourceLocation SelLoc = ReadSourceLocation( |
| 3763 | *F, F->ReferencedSelectorsData, I); |
| 3764 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 3765 | } |
| 3766 | } |
| 3767 | |
| 3768 | // If there were any pending implicit instantiations, deserialize them |
| 3769 | // and add them to Sema's queue of such instantiations. |
| 3770 | assert(F->PendingInstantiations.size() % 2 == 0 && |
| 3771 | "Expected pairs of entries"); |
| 3772 | for (unsigned Idx = 0, N = F->PendingInstantiations.size(); Idx < N;) { |
| 3773 | ValueDecl *D=cast<ValueDecl>(GetDecl(F->PendingInstantiations[Idx++])); |
| 3774 | SourceLocation Loc = ReadSourceLocation(*F, F->PendingInstantiations,Idx); |
| 3775 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 3776 | } |
| 3777 | } |
| 3778 | |
| 3779 | // The two special data sets below always come from the most recent PCH, |
| 3780 | // which is at the front of the chain. |
| 3781 | PerFileData &F = *Chain.front(); |
| 3782 | |
| 3783 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 3784 | // Sema's list of weak undeclared identifiers. |
| 3785 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 3786 | unsigned Idx = 0; |
| 3787 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 3788 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 3789 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 3790 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 3791 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 3792 | Sema::WeakInfo WI(AliasId, Loc); |
| 3793 | WI.setUsed(Used); |
| 3794 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 3795 | } |
| 3796 | } |
| 3797 | |
| 3798 | // If there were any VTable uses, deserialize the information and add it |
| 3799 | // to Sema's vector and map of VTable uses. |
| 3800 | if (!VTableUses.empty()) { |
| 3801 | unsigned Idx = 0; |
| 3802 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 3803 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 3804 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 3805 | bool DefinitionRequired = VTableUses[Idx++]; |
| 3806 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 3807 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3808 | } |
| 3809 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3810 | } |
| 3811 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3812 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3813 | // Try to find this name within our on-disk hash tables. We start with the |
| 3814 | // 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] | 3815 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3816 | ASTIdentifierLookupTable *IdTable |
| 3817 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3818 | if (!IdTable) |
| 3819 | continue; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3820 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3821 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3822 | if (Pos == IdTable->end()) |
| 3823 | continue; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3824 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3825 | // Dereferencing the iterator has the effect of building the |
| 3826 | // IdentifierInfo node and populating it with the various |
| 3827 | // declarations it needs. |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3828 | return *Pos; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3829 | } |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3830 | return 0; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3831 | } |
| 3832 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 3833 | namespace clang { |
| 3834 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 3835 | /// identifiers stored within a set of AST files. |
| 3836 | class ASTIdentifierIterator : public IdentifierIterator { |
| 3837 | /// \brief The AST reader whose identifiers are being enumerated. |
| 3838 | const ASTReader &Reader; |
| 3839 | |
| 3840 | /// \brief The current index into the chain of AST files stored in |
| 3841 | /// the AST reader. |
| 3842 | unsigned Index; |
| 3843 | |
| 3844 | /// \brief The current position within the identifier lookup table |
| 3845 | /// of the current AST file. |
| 3846 | ASTIdentifierLookupTable::key_iterator Current; |
| 3847 | |
| 3848 | /// \brief The end position within the identifier lookup table of |
| 3849 | /// the current AST file. |
| 3850 | ASTIdentifierLookupTable::key_iterator End; |
| 3851 | |
| 3852 | public: |
| 3853 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 3854 | |
| 3855 | virtual llvm::StringRef Next(); |
| 3856 | }; |
| 3857 | } |
| 3858 | |
| 3859 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 3860 | : Reader(Reader), Index(Reader.Chain.size() - 1) { |
| 3861 | ASTIdentifierLookupTable *IdTable |
| 3862 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 3863 | Current = IdTable->key_begin(); |
| 3864 | End = IdTable->key_end(); |
| 3865 | } |
| 3866 | |
| 3867 | llvm::StringRef ASTIdentifierIterator::Next() { |
| 3868 | while (Current == End) { |
| 3869 | // If we have exhausted all of our AST files, we're done. |
| 3870 | if (Index == 0) |
| 3871 | return llvm::StringRef(); |
| 3872 | |
| 3873 | --Index; |
| 3874 | ASTIdentifierLookupTable *IdTable |
| 3875 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 3876 | Current = IdTable->key_begin(); |
| 3877 | End = IdTable->key_end(); |
| 3878 | } |
| 3879 | |
| 3880 | // We have any identifiers remaining in the current AST file; return |
| 3881 | // the next one. |
| 3882 | std::pair<const char*, unsigned> Key = *Current; |
| 3883 | ++Current; |
| 3884 | return llvm::StringRef(Key.first, Key.second); |
| 3885 | } |
| 3886 | |
| 3887 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 3888 | return new ASTIdentifierIterator(*this); |
| 3889 | } |
| 3890 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3891 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3892 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3893 | // Find this selector in a hash table. We want to find the most recent entry. |
| 3894 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3895 | PerFileData &F = *Chain[I]; |
| 3896 | if (!F.SelectorLookupTable) |
| 3897 | continue; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3898 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3899 | ASTSelectorLookupTable *PoolTable |
| 3900 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 3901 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3902 | if (Pos != PoolTable->end()) { |
| 3903 | ++NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3904 | // FIXME: Not quite happy with the statistics here. We probably should |
| 3905 | // disable this tracking when called via LoadSelector. |
| 3906 | // Also, should entries without methods count as misses? |
| 3907 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3908 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3909 | if (DeserializationListener) |
| 3910 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 3911 | return std::make_pair(Data.Instance, Data.Factory); |
| 3912 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3913 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3914 | |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3915 | ++NumMethodPoolMisses; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3916 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3917 | } |
| 3918 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3919 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3920 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 3921 | ReadMethodPool(Sel); |
| 3922 | } |
| 3923 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3924 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3925 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3926 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3927 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3928 | if (DeserializationListener) |
| 3929 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3930 | } |
| 3931 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3932 | /// \brief Set the globally-visible declarations associated with the given |
| 3933 | /// identifier. |
| 3934 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3935 | /// 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] | 3936 | /// 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] | 3937 | /// them. |
| 3938 | /// |
| 3939 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 3940 | /// declarations. |
| 3941 | /// |
| 3942 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 3943 | /// visible at global scope. |
| 3944 | /// |
| 3945 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 3946 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 3947 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3948 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3949 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3950 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 3951 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3952 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3953 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 3954 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 3955 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 3956 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3957 | return; |
| 3958 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3959 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3960 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 3961 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 3962 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 3963 | if (SemaObj->TUScope) { |
| 3964 | // Introduce this declaration into the translation-unit scope |
| 3965 | // and add it to the declaration chain for this identifier, so |
| 3966 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 3967 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 3968 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3969 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3970 | } else { |
| 3971 | // Queue this declaration so that it will be added to the |
| 3972 | // translation unit scope and identifier's declaration chain |
| 3973 | // once a Sema object is known. |
| 3974 | PreloadedDecls.push_back(D); |
| 3975 | } |
| 3976 | } |
| 3977 | } |
| 3978 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3979 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3980 | if (ID == 0) |
| 3981 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3982 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3983 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3984 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3985 | return 0; |
| 3986 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3987 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3988 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3989 | ID -= 1; |
| 3990 | if (!IdentifiersLoaded[ID]) { |
| 3991 | unsigned Index = ID; |
| 3992 | const char *Str = 0; |
| 3993 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3994 | PerFileData *F = Chain[N - I - 1]; |
| 3995 | if (Index < F->LocalNumIdentifiers) { |
| 3996 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 3997 | Str = F->IdentifierTableData + Offset; |
| 3998 | break; |
| 3999 | } |
| 4000 | Index -= F->LocalNumIdentifiers; |
| 4001 | } |
| 4002 | assert(Str && "Broken Chain"); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4003 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4004 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4005 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4006 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4007 | // unsigned integers. This is important to avoid integer overflow when |
| 4008 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4009 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4010 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4011 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4012 | IdentifiersLoaded[ID] |
Kovarththanan Rajaratnam | 811f426 | 2010-03-12 10:32:27 +0000 | [diff] [blame] | 4013 | = &PP->getIdentifierTable().get(Str, StrLen); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4014 | if (DeserializationListener) |
| 4015 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4016 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4017 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4018 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4019 | } |
| 4020 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4021 | void ASTReader::ReadSLocEntry(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4022 | ReadSLocEntryRecord(ID); |
| 4023 | } |
| 4024 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4025 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4026 | if (ID == 0) |
| 4027 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4028 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4029 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4030 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4031 | return Selector(); |
| 4032 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4033 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4034 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4035 | // Load this selector from the selector table. |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4036 | unsigned Idx = ID - 1; |
| 4037 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4038 | PerFileData &F = *Chain[N - I - 1]; |
| 4039 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4040 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4041 | SelectorsLoaded[ID - 1] = |
| 4042 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 4043 | if (DeserializationListener) |
| 4044 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 4045 | break; |
| 4046 | } |
| 4047 | Idx -= F.LocalNumSelectors; |
| 4048 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4049 | } |
| 4050 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4051 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4052 | } |
| 4053 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4054 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4055 | return DecodeSelector(ID); |
| 4056 | } |
| 4057 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4058 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4059 | // ID 0 (the null selector) is considered an external selector. |
| 4060 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4061 | } |
| 4062 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4063 | DeclarationName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4064 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4065 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4066 | switch (Kind) { |
| 4067 | case DeclarationName::Identifier: |
| 4068 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 4069 | |
| 4070 | case DeclarationName::ObjCZeroArgSelector: |
| 4071 | case DeclarationName::ObjCOneArgSelector: |
| 4072 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 4073 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4074 | |
| 4075 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4076 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4077 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4078 | |
| 4079 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4080 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4081 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4082 | |
| 4083 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4084 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4085 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4086 | |
| 4087 | case DeclarationName::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4088 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4089 | (OverloadedOperatorKind)Record[Idx++]); |
| 4090 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4091 | case DeclarationName::CXXLiteralOperatorName: |
| 4092 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 4093 | GetIdentifierInfo(Record, Idx)); |
| 4094 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4095 | case DeclarationName::CXXUsingDirective: |
| 4096 | return DeclarationName::getUsingDirectiveName(); |
| 4097 | } |
| 4098 | |
| 4099 | // Required to silence GCC warning |
| 4100 | return DeclarationName(); |
| 4101 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4102 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4103 | void ASTReader::ReadDeclarationNameLoc(PerFileData &F, |
| 4104 | DeclarationNameLoc &DNLoc, |
| 4105 | DeclarationName Name, |
| 4106 | const RecordData &Record, unsigned &Idx) { |
| 4107 | switch (Name.getNameKind()) { |
| 4108 | case DeclarationName::CXXConstructorName: |
| 4109 | case DeclarationName::CXXDestructorName: |
| 4110 | case DeclarationName::CXXConversionFunctionName: |
| 4111 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4112 | break; |
| 4113 | |
| 4114 | case DeclarationName::CXXOperatorName: |
| 4115 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4116 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4117 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4118 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4119 | break; |
| 4120 | |
| 4121 | case DeclarationName::CXXLiteralOperatorName: |
| 4122 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4123 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4124 | break; |
| 4125 | |
| 4126 | case DeclarationName::Identifier: |
| 4127 | case DeclarationName::ObjCZeroArgSelector: |
| 4128 | case DeclarationName::ObjCOneArgSelector: |
| 4129 | case DeclarationName::ObjCMultiArgSelector: |
| 4130 | case DeclarationName::CXXUsingDirective: |
| 4131 | break; |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | void ASTReader::ReadDeclarationNameInfo(PerFileData &F, |
| 4136 | DeclarationNameInfo &NameInfo, |
| 4137 | const RecordData &Record, unsigned &Idx) { |
| 4138 | NameInfo.setName(ReadDeclarationName(Record, Idx)); |
| 4139 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4140 | DeclarationNameLoc DNLoc; |
| 4141 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4142 | NameInfo.setInfo(DNLoc); |
| 4143 | } |
| 4144 | |
| 4145 | void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info, |
| 4146 | const RecordData &Record, unsigned &Idx) { |
| 4147 | Info.NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4148 | Info.NNSRange = ReadSourceRange(F, Record, Idx); |
| 4149 | unsigned NumTPLists = Record[Idx++]; |
| 4150 | Info.NumTemplParamLists = NumTPLists; |
| 4151 | if (NumTPLists) { |
| 4152 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 4153 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4154 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4155 | } |
| 4156 | } |
| 4157 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4158 | TemplateName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4159 | ASTReader::ReadTemplateName(const RecordData &Record, unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4160 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4161 | switch (Kind) { |
| 4162 | case TemplateName::Template: |
| 4163 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 4164 | |
| 4165 | case TemplateName::OverloadedTemplate: { |
| 4166 | unsigned size = Record[Idx++]; |
| 4167 | UnresolvedSet<8> Decls; |
| 4168 | while (size--) |
| 4169 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 4170 | |
| 4171 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 4172 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4173 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4174 | case TemplateName::QualifiedTemplate: { |
| 4175 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4176 | bool hasTemplKeyword = Record[Idx++]; |
| 4177 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 4178 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 4179 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4180 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4181 | case TemplateName::DependentTemplate: { |
| 4182 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4183 | if (Record[Idx++]) // isIdentifier |
| 4184 | return Context->getDependentTemplateName(NNS, |
| 4185 | GetIdentifierInfo(Record, Idx)); |
| 4186 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4187 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4188 | } |
| 4189 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4190 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4191 | assert(0 && "Unhandled template name kind!"); |
| 4192 | return TemplateName(); |
| 4193 | } |
| 4194 | |
| 4195 | TemplateArgument |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4196 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4197 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4198 | switch ((TemplateArgument::ArgKind)Record[Idx++]) { |
| 4199 | case TemplateArgument::Null: |
| 4200 | return TemplateArgument(); |
| 4201 | case TemplateArgument::Type: |
| 4202 | return TemplateArgument(GetType(Record[Idx++])); |
| 4203 | case TemplateArgument::Declaration: |
| 4204 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4205 | case TemplateArgument::Integral: { |
| 4206 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 4207 | QualType T = GetType(Record[Idx++]); |
| 4208 | return TemplateArgument(Value, T); |
| 4209 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4210 | case TemplateArgument::Template: |
| 4211 | return TemplateArgument(ReadTemplateName(Record, Idx)); |
| 4212 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4213 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4214 | case TemplateArgument::Pack: { |
| 4215 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4216 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 4217 | for (unsigned I = 0; I != NumArgs; ++I) |
| 4218 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 4219 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4220 | } |
| 4221 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4222 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4223 | assert(0 && "Unhandled template argument kind!"); |
| 4224 | return TemplateArgument(); |
| 4225 | } |
| 4226 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4227 | TemplateParameterList * |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4228 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 4229 | const RecordData &Record, unsigned &Idx) { |
| 4230 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 4231 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 4232 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4233 | |
| 4234 | unsigned NumParams = Record[Idx++]; |
| 4235 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 4236 | Params.reserve(NumParams); |
| 4237 | while (NumParams--) |
| 4238 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4239 | |
| 4240 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4241 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 4242 | Params.data(), Params.size(), RAngleLoc); |
| 4243 | return TemplateParams; |
| 4244 | } |
| 4245 | |
| 4246 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4247 | ASTReader:: |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4248 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4249 | PerFileData &F, const RecordData &Record, |
| 4250 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4251 | unsigned NumTemplateArgs = Record[Idx++]; |
| 4252 | TemplArgs.reserve(NumTemplateArgs); |
| 4253 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4254 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4255 | } |
| 4256 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4257 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4258 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4259 | const RecordData &Record, unsigned &Idx) { |
| 4260 | unsigned NumDecls = Record[Idx++]; |
| 4261 | while (NumDecls--) { |
| 4262 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 4263 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 4264 | Set.addDecl(D, AS); |
| 4265 | } |
| 4266 | } |
| 4267 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4268 | CXXBaseSpecifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4269 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4270 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4271 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 4272 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 4273 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4274 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4275 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4276 | return CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, TInfo); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4277 | } |
| 4278 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4279 | std::pair<CXXBaseOrMemberInitializer **, unsigned> |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4280 | ASTReader::ReadCXXBaseOrMemberInitializers(PerFileData &F, |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4281 | const RecordData &Record, |
| 4282 | unsigned &Idx) { |
| 4283 | CXXBaseOrMemberInitializer **BaseOrMemberInitializers = 0; |
| 4284 | unsigned NumInitializers = Record[Idx++]; |
| 4285 | if (NumInitializers) { |
| 4286 | ASTContext &C = *getContext(); |
| 4287 | |
| 4288 | BaseOrMemberInitializers |
| 4289 | = new (C) CXXBaseOrMemberInitializer*[NumInitializers]; |
| 4290 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 4291 | TypeSourceInfo *BaseClassInfo = 0; |
| 4292 | bool IsBaseVirtual = false; |
| 4293 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4294 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4295 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4296 | bool IsBaseInitializer = Record[Idx++]; |
| 4297 | if (IsBaseInitializer) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4298 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4299 | IsBaseVirtual = Record[Idx++]; |
| 4300 | } else { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4301 | bool IsIndirectMemberInitializer = Record[Idx++]; |
| 4302 | if (IsIndirectMemberInitializer) |
| 4303 | IndirectMember = cast<IndirectFieldDecl>(GetDecl(Record[Idx++])); |
| 4304 | else |
| 4305 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4306 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4307 | SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx); |
| 4308 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4309 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 4310 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4311 | bool IsWritten = Record[Idx++]; |
| 4312 | unsigned SourceOrderOrNumArrayIndices; |
| 4313 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 4314 | if (IsWritten) { |
| 4315 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4316 | } else { |
| 4317 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4318 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 4319 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 4320 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 4321 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4322 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4323 | CXXBaseOrMemberInitializer *BOMInit; |
| 4324 | if (IsBaseInitializer) { |
| 4325 | BOMInit = new (C) CXXBaseOrMemberInitializer(C, BaseClassInfo, |
| 4326 | IsBaseVirtual, LParenLoc, |
| 4327 | Init, RParenLoc); |
| 4328 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4329 | if (Member) |
| 4330 | BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc, |
| 4331 | LParenLoc, Init, |
| 4332 | RParenLoc); |
| 4333 | else |
| 4334 | BOMInit = new (C) CXXBaseOrMemberInitializer(C, IndirectMember, |
| 4335 | MemberLoc, LParenLoc, |
| 4336 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4337 | } else { |
| 4338 | BOMInit = CXXBaseOrMemberInitializer::Create(C, Member, MemberLoc, |
| 4339 | LParenLoc, Init, RParenLoc, |
| 4340 | Indices.data(), |
| 4341 | Indices.size()); |
| 4342 | } |
| 4343 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 4344 | if (IsWritten) |
| 4345 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4346 | BaseOrMemberInitializers[i] = BOMInit; |
| 4347 | } |
| 4348 | } |
| 4349 | |
| 4350 | return std::make_pair(BaseOrMemberInitializers, NumInitializers); |
| 4351 | } |
| 4352 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4353 | NestedNameSpecifier * |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4354 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4355 | unsigned N = Record[Idx++]; |
| 4356 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 4357 | for (unsigned I = 0; I != N; ++I) { |
| 4358 | NestedNameSpecifier::SpecifierKind Kind |
| 4359 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4360 | switch (Kind) { |
| 4361 | case NestedNameSpecifier::Identifier: { |
| 4362 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 4363 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 4364 | break; |
| 4365 | } |
| 4366 | |
| 4367 | case NestedNameSpecifier::Namespace: { |
| 4368 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 4369 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 4370 | break; |
| 4371 | } |
| 4372 | |
| 4373 | case NestedNameSpecifier::TypeSpec: |
| 4374 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 4375 | Type *T = GetType(Record[Idx++]).getTypePtrOrNull(); |
| 4376 | if (!T) |
| 4377 | return 0; |
| 4378 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4379 | bool Template = Record[Idx++]; |
| 4380 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 4381 | break; |
| 4382 | } |
| 4383 | |
| 4384 | case NestedNameSpecifier::Global: { |
| 4385 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4386 | // No associated value, and there can't be a prefix. |
| 4387 | break; |
| 4388 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4389 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 4390 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4391 | } |
| 4392 | return NNS; |
| 4393 | } |
| 4394 | |
| 4395 | SourceRange |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4396 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 4397 | unsigned &Idx) { |
| 4398 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 4399 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 4400 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4401 | } |
| 4402 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4403 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4404 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4405 | unsigned BitWidth = Record[Idx++]; |
| 4406 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 4407 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 4408 | Idx += NumWords; |
| 4409 | return Result; |
| 4410 | } |
| 4411 | |
| 4412 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4413 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4414 | bool isUnsigned = Record[Idx++]; |
| 4415 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 4416 | } |
| 4417 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4418 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4419 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4420 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 4421 | } |
| 4422 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4423 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4424 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4425 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 4426 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4427 | Idx += Len; |
| 4428 | return Result; |
| 4429 | } |
| 4430 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4431 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4432 | unsigned &Idx) { |
| 4433 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 4434 | return CXXTemporary::Create(*Context, Decl); |
| 4435 | } |
| 4436 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4437 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 4438 | return Diag(SourceLocation(), DiagID); |
| 4439 | } |
| 4440 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4441 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4442 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4443 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4444 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4445 | /// \brief Retrieve the identifier table associated with the |
| 4446 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4447 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4448 | assert(PP && "Forgot to set Preprocessor ?"); |
| 4449 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4450 | } |
| 4451 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4452 | /// \brief Record that the given ID maps to the given switch-case |
| 4453 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4454 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4455 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 4456 | SwitchCaseStmts[ID] = SC; |
| 4457 | } |
| 4458 | |
| 4459 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4460 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4461 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 4462 | return SwitchCaseStmts[ID]; |
| 4463 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4464 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4465 | void ASTReader::ClearSwitchCaseIDs() { |
| 4466 | SwitchCaseStmts.clear(); |
| 4467 | } |
| 4468 | |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4469 | /// \brief Record that the given label statement has been |
| 4470 | /// deserialized and has the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4471 | void ASTReader::RecordLabelStmt(LabelStmt *S, unsigned ID) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4472 | assert(LabelStmts.find(ID) == LabelStmts.end() && |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4473 | "Deserialized label twice"); |
| 4474 | LabelStmts[ID] = S; |
| 4475 | |
| 4476 | // If we've already seen any goto statements that point to this |
| 4477 | // label, resolve them now. |
| 4478 | typedef std::multimap<unsigned, GotoStmt *>::iterator GotoIter; |
| 4479 | std::pair<GotoIter, GotoIter> Gotos = UnresolvedGotoStmts.equal_range(ID); |
| 4480 | for (GotoIter Goto = Gotos.first; Goto != Gotos.second; ++Goto) |
| 4481 | Goto->second->setLabel(S); |
| 4482 | UnresolvedGotoStmts.erase(Gotos.first, Gotos.second); |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4483 | |
| 4484 | // If we've already seen any address-label statements that point to |
| 4485 | // this label, resolve them now. |
| 4486 | typedef std::multimap<unsigned, AddrLabelExpr *>::iterator AddrLabelIter; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4487 | std::pair<AddrLabelIter, AddrLabelIter> AddrLabels |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4488 | = UnresolvedAddrLabelExprs.equal_range(ID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4489 | for (AddrLabelIter AddrLabel = AddrLabels.first; |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4490 | AddrLabel != AddrLabels.second; ++AddrLabel) |
| 4491 | AddrLabel->second->setLabel(S); |
| 4492 | UnresolvedAddrLabelExprs.erase(AddrLabels.first, AddrLabels.second); |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | /// \brief Set the label of the given statement to the label |
| 4496 | /// identified by ID. |
| 4497 | /// |
| 4498 | /// Depending on the order in which the label and other statements |
| 4499 | /// referencing that label occur, this operation may complete |
| 4500 | /// immediately (updating the statement) or it may queue the |
| 4501 | /// statement to be back-patched later. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4502 | void ASTReader::SetLabelOf(GotoStmt *S, unsigned ID) { |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4503 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 4504 | if (Label != LabelStmts.end()) { |
| 4505 | // We've already seen this label, so set the label of the goto and |
| 4506 | // we're done. |
| 4507 | S->setLabel(Label->second); |
| 4508 | } else { |
| 4509 | // We haven't seen this label yet, so add this goto to the set of |
| 4510 | // unresolved goto statements. |
| 4511 | UnresolvedGotoStmts.insert(std::make_pair(ID, S)); |
| 4512 | } |
| 4513 | } |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4514 | |
| 4515 | /// \brief Set the label of the given expression to the label |
| 4516 | /// identified by ID. |
| 4517 | /// |
| 4518 | /// Depending on the order in which the label and other statements |
| 4519 | /// referencing that label occur, this operation may complete |
| 4520 | /// immediately (updating the statement) or it may queue the |
| 4521 | /// statement to be back-patched later. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4522 | void ASTReader::SetLabelOf(AddrLabelExpr *S, unsigned ID) { |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4523 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 4524 | if (Label != LabelStmts.end()) { |
| 4525 | // We've already seen this label, so set the label of the |
| 4526 | // label-address expression and we're done. |
| 4527 | S->setLabel(Label->second); |
| 4528 | } else { |
| 4529 | // We haven't seen this label yet, so add this label-address |
| 4530 | // expression to the set of unresolved label-address expressions. |
| 4531 | UnresolvedAddrLabelExprs.insert(std::make_pair(ID, S)); |
| 4532 | } |
| 4533 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4534 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4535 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4536 | assert(NumCurrentElementsDeserializing && |
| 4537 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 4538 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4539 | // If any identifiers with corresponding top-level declarations have |
| 4540 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4541 | while (!PendingIdentifierInfos.empty()) { |
| 4542 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 4543 | PendingIdentifierInfos.front().DeclIDs, true); |
| 4544 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4545 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4546 | |
| 4547 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 4548 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4549 | if (Consumer) |
| 4550 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 4551 | |
| 4552 | assert(PendingForwardRefs.size() == 0 && |
| 4553 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4554 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4555 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4556 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4557 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4558 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
| 4559 | const char *isysroot, bool DisableValidation) |
| 4560 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 4561 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 4562 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
| 4563 | Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), |
| 4564 | NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4565 | TotalNumSLocEntries(0), NextSLocOffset(0), NumStatementsRead(0), |
| 4566 | TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), |
| 4567 | NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4568 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4569 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4570 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
| 4571 | RelocatablePCH = false; |
| 4572 | } |
| 4573 | |
| 4574 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 4575 | Diagnostic &Diags, const char *isysroot, |
| 4576 | bool DisableValidation) |
| 4577 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
| 4578 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), |
| 4579 | isysroot(isysroot), DisableValidation(DisableValidation), NumStatHits(0), |
| 4580 | NumStatMisses(0), NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4581 | NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0), |
| 4582 | NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), |
| 4583 | NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
| 4584 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4585 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4586 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4587 | RelocatablePCH = false; |
| 4588 | } |
| 4589 | |
| 4590 | ASTReader::~ASTReader() { |
| 4591 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 4592 | delete Chain[e - i - 1]; |
| 4593 | // Delete all visible decl lookup tables |
| 4594 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 4595 | E = DeclContextOffsets.end(); |
| 4596 | I != E; ++I) { |
| 4597 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 4598 | J != F; ++J) { |
| 4599 | if (J->NameLookupTableData) |
| 4600 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 4601 | J->NameLookupTableData); |
| 4602 | } |
| 4603 | } |
| 4604 | for (DeclContextVisibleUpdatesPending::iterator |
| 4605 | I = PendingVisibleUpdates.begin(), |
| 4606 | E = PendingVisibleUpdates.end(); |
| 4607 | I != E; ++I) { |
| 4608 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 4609 | F = I->second.end(); |
| 4610 | J != F; ++J) |
| 4611 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 4612 | } |
| 4613 | } |
| 4614 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 4615 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
| 4616 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 4617 | LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), |
| 4618 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
| 4619 | MacroDefinitionOffsets(0), LocalNumSelectors(0), SelectorOffsets(0), |
| 4620 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4621 | DeclOffsets(0), LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
| 4622 | LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 4623 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4624 | {} |
| 4625 | |
| 4626 | ASTReader::PerFileData::~PerFileData() { |
| 4627 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
| 4628 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 4629 | } |
| 4630 | |