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); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 87 | PARSE_LANGOPT_IMPORTANT(AppleKext, diag::warn_pch_apple_kext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 88 | PARSE_LANGOPT_IMPORTANT(ObjCDefaultSynthProperties, |
| 89 | diag::warn_pch_objc_auto_properties); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 90 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 91 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 92 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 93 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 94 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 95 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 96 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 97 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 98 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 99 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 100 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 101 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 103 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 104 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 105 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 106 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 107 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 108 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 109 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 110 | diag::warn_pch_heinous_extensions); |
| 111 | // FIXME: Most of the options below are benign if the macro wasn't |
| 112 | // used. Unfortunately, this means that a PCH compiled without |
| 113 | // optimization can't be used with optimization turned on, even |
| 114 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 115 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 116 | // doesn't matter. We could consider making this some special kind |
| 117 | // of check. |
| 118 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 119 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 120 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 121 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 122 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 123 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
| 124 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 125 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 126 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 127 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 128 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 130 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 131 | return true; |
| 132 | } |
| 133 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 134 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 135 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 136 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 137 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 138 | PARSE_LANGOPT_IMPORTANT(CUDA, diag::warn_pch_cuda); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 139 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 140 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 141 | PARSE_LANGOPT_BENIGN(SpellChecking); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 142 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 143 | #undef PARSE_LANGOPT_BENIGN |
| 144 | |
| 145 | return false; |
| 146 | } |
| 147 | |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 148 | bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) { |
| 149 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 150 | return false; |
| 151 | |
| 152 | Reader.Diag(diag::warn_pch_target_triple) |
| 153 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 154 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 157 | namespace { |
| 158 | struct EmptyStringRef { |
| 159 | bool operator ()(llvm::StringRef r) const { return r.empty(); } |
| 160 | }; |
| 161 | struct EmptyBlock { |
| 162 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 163 | }; |
| 164 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 165 | |
| 166 | static bool EqualConcatenations(llvm::SmallVector<llvm::StringRef, 2> L, |
| 167 | PCHPredefinesBlocks R) { |
| 168 | // First, sum up the lengths. |
| 169 | unsigned LL = 0, RL = 0; |
| 170 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 171 | LL += L[I].size(); |
| 172 | } |
| 173 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 174 | RL += R[I].Data.size(); |
| 175 | } |
| 176 | if (LL != RL) |
| 177 | return false; |
| 178 | if (LL == 0 && RL == 0) |
| 179 | return true; |
| 180 | |
| 181 | // Kick out empty parts, they confuse the algorithm below. |
| 182 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 183 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 184 | |
| 185 | // Do it the hard way. At this point, both vectors must be non-empty. |
| 186 | llvm::StringRef LR = L[0], RR = R[0].Data; |
| 187 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 188 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 189 | for (;;) { |
| 190 | // Compare the current pieces. |
| 191 | if (LR.size() == RR.size()) { |
| 192 | // If they're the same length, it's pretty easy. |
| 193 | if (LR != RR) |
| 194 | return false; |
| 195 | // Both pieces are done, advance. |
| 196 | ++LI; |
| 197 | ++RI; |
| 198 | // If either string is done, they're both done, since they're the same |
| 199 | // length. |
| 200 | if (LI == LN) { |
| 201 | assert(RI == RN && "Strings not the same length after all?"); |
| 202 | return true; |
| 203 | } |
| 204 | LR = L[LI]; |
| 205 | RR = R[RI].Data; |
| 206 | } else if (LR.size() < RR.size()) { |
| 207 | // Right piece is longer. |
| 208 | if (!RR.startswith(LR)) |
| 209 | return false; |
| 210 | ++LI; |
| 211 | assert(LI != LN && "Strings not the same length after all?"); |
| 212 | RR = RR.substr(LR.size()); |
| 213 | LR = L[LI]; |
| 214 | } else { |
| 215 | // Left piece is longer. |
| 216 | if (!LR.startswith(RR)) |
| 217 | return false; |
| 218 | ++RI; |
| 219 | assert(RI != RN && "Strings not the same length after all?"); |
| 220 | LR = LR.substr(RR.size()); |
| 221 | RR = R[RI].Data; |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | static std::pair<FileID, llvm::StringRef::size_type> |
| 227 | FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) { |
| 228 | std::pair<FileID, llvm::StringRef::size_type> Res; |
| 229 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 230 | Res.second = Buffers[I].Data.find(MacroDef); |
| 231 | if (Res.second != llvm::StringRef::npos) { |
| 232 | Res.first = Buffers[I].BufferID; |
| 233 | break; |
| 234 | } |
| 235 | } |
| 236 | return Res; |
| 237 | } |
| 238 | |
| 239 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 240 | llvm::StringRef OriginalFileName, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 241 | std::string &SuggestedPredefines) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 242 | // We are in the context of an implicit include, so the predefines buffer will |
| 243 | // have a #include entry for the PCH file itself (as normalized by the |
| 244 | // preprocessor initialization). Find it and skip over it in the checking |
| 245 | // below. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 246 | llvm::SmallString<256> PCHInclude; |
| 247 | PCHInclude += "#include \""; |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 248 | PCHInclude += NormalizeDashIncludePath(OriginalFileName); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 249 | PCHInclude += "\"\n"; |
| 250 | std::pair<llvm::StringRef,llvm::StringRef> Split = |
| 251 | llvm::StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 252 | llvm::StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 253 | if (Left == PP.getPredefines()) { |
| 254 | Error("Missing PCH include entry!"); |
| 255 | return true; |
| 256 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 257 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 258 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 259 | // command line, we're done. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 260 | llvm::SmallVector<llvm::StringRef, 2> CommandLine; |
| 261 | CommandLine.push_back(Left); |
| 262 | CommandLine.push_back(Right); |
| 263 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 264 | return false; |
| 265 | |
| 266 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 267 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 268 | // The predefines buffers are different. Determine what the differences are, |
| 269 | // and whether they require us to reject the PCH file. |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 270 | llvm::SmallVector<llvm::StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 271 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 272 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 273 | |
| 274 | llvm::SmallVector<llvm::StringRef, 8> CmdLineLines; |
| 275 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 276 | |
| 277 | // Pick out implicit #includes after the PCH and don't consider them for |
| 278 | // validation; we will insert them into SuggestedPredefines so that the |
| 279 | // preprocessor includes them. |
| 280 | std::string IncludesAfterPCH; |
| 281 | llvm::SmallVector<llvm::StringRef, 8> AfterPCHLines; |
| 282 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 283 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 284 | if (AfterPCHLines[i].startswith("#include ")) { |
| 285 | IncludesAfterPCH += AfterPCHLines[i]; |
| 286 | IncludesAfterPCH += '\n'; |
| 287 | } else { |
| 288 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | // Make sure we add the includes last into SuggestedPredefines before we |
| 293 | // exit this function. |
| 294 | struct AddIncludesRAII { |
| 295 | std::string &SuggestedPredefines; |
| 296 | std::string &IncludesAfterPCH; |
| 297 | |
| 298 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 299 | std::string &IncludesAfterPCH) |
| 300 | : SuggestedPredefines(SuggestedPredefines), |
| 301 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 302 | ~AddIncludesRAII() { |
| 303 | SuggestedPredefines += IncludesAfterPCH; |
| 304 | } |
| 305 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 306 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 307 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 308 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 309 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 310 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 311 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 312 | // Determine which predefines that were used to build the PCH file are missing |
| 313 | // from the command line. |
| 314 | std::vector<llvm::StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 315 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 316 | CmdLineLines.begin(), CmdLineLines.end(), |
| 317 | std::back_inserter(MissingPredefines)); |
| 318 | |
| 319 | bool MissingDefines = false; |
| 320 | bool ConflictingDefines = false; |
| 321 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 322 | llvm::StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 323 | if (Missing.startswith("#include ")) { |
| 324 | // An -include was specified when generating the PCH; it is included in |
| 325 | // the PCH, just ignore it. |
| 326 | continue; |
| 327 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 328 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 329 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 330 | return true; |
| 331 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 332 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 333 | // This is a macro definition. Determine the name of the macro we're |
| 334 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 335 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 336 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 337 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 338 | assert(EndOfMacroName != std::string::npos && |
| 339 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 340 | llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 341 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 342 | // Determine whether this macro was given a different definition on the |
| 343 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 344 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 345 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 346 | llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 347 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 348 | MacroDefStart); |
| 349 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 350 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 351 | // Different macro; we're done. |
| 352 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 353 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 354 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 355 | |
| 356 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 357 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 359 | (*ConflictPos)[MacroDefLen] != '(') |
| 360 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 361 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 362 | // We found a conflicting macro definition. |
| 363 | break; |
| 364 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 366 | if (ConflictPos != CmdLineLines.end()) { |
| 367 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 368 | << MacroName; |
| 369 | |
| 370 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 371 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 372 | FindMacro(Buffers, Missing); |
| 373 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 374 | SourceLocation PCHMissingLoc = |
| 375 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 376 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 377 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 378 | |
| 379 | ConflictingDefines = true; |
| 380 | continue; |
| 381 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 382 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 383 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 384 | // 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] | 385 | if (ConflictingDefines) |
| 386 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 387 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 388 | if (!MissingDefines) { |
| 389 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 390 | MissingDefines = true; |
| 391 | } |
| 392 | |
| 393 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 394 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 395 | FindMacro(Buffers, Missing); |
| 396 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 397 | SourceLocation PCHMissingLoc = |
| 398 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 399 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 400 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 401 | } |
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 | if (ConflictingDefines) |
| 404 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 405 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 406 | // Determine what predefines were introduced based on command-line |
| 407 | // parameters that were not present when building the PCH |
| 408 | // file. Extra #defines are okay, so long as the identifiers being |
| 409 | // defined were not used within the precompiled header. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 410 | std::vector<llvm::StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 411 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 412 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 413 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 414 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 415 | llvm::StringRef &Extra = ExtraPredefines[I]; |
| 416 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 417 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 418 | return true; |
| 419 | } |
| 420 | |
| 421 | // This is an extra macro definition. Determine the name of the |
| 422 | // macro we're defining. |
| 423 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 424 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 425 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 426 | assert(EndOfMacroName != std::string::npos && |
| 427 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 428 | llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 429 | |
| 430 | // Check whether this name was used somewhere in the PCH file. If |
| 431 | // so, defining it as a macro could change behavior, so we reject |
| 432 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 433 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 434 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 435 | return true; |
| 436 | } |
| 437 | |
| 438 | // Add this definition to the suggested predefines buffer. |
| 439 | SuggestedPredefines += Extra; |
| 440 | SuggestedPredefines += '\n'; |
| 441 | } |
| 442 | |
| 443 | // If we get here, it's because the predefines buffer had compatible |
| 444 | // contents. Accept the PCH file. |
| 445 | return false; |
| 446 | } |
| 447 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 448 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 449 | unsigned ID) { |
| 450 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 451 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | void PCHValidator::ReadCounter(unsigned Value) { |
| 455 | PP.setCounterValue(Value); |
| 456 | } |
| 457 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 458 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 459 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 460 | //===----------------------------------------------------------------------===// |
| 461 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 462 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 463 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 464 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 467 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 468 | namespace { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 469 | class ASTSelectorLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 470 | ASTReader &Reader; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 471 | |
| 472 | public: |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 473 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 474 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 475 | ObjCMethodList Instance, Factory; |
| 476 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 477 | |
| 478 | typedef Selector external_key_type; |
| 479 | typedef external_key_type internal_key_type; |
| 480 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 481 | explicit ASTSelectorLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 482 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 483 | static bool EqualKey(const internal_key_type& a, |
| 484 | const internal_key_type& b) { |
| 485 | return a == b; |
| 486 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 487 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 488 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 489 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 490 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 491 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 492 | // This hopefully will just get inlined and removed by the optimizer. |
| 493 | static const internal_key_type& |
| 494 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 496 | static std::pair<unsigned, unsigned> |
| 497 | ReadKeyDataLength(const unsigned char*& d) { |
| 498 | using namespace clang::io; |
| 499 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 500 | unsigned DataLen = ReadUnalignedLE16(d); |
| 501 | return std::make_pair(KeyLen, DataLen); |
| 502 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 503 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 504 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 505 | using namespace clang::io; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 506 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 507 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 508 | IdentifierInfo *FirstII |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 509 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 510 | if (N == 0) |
| 511 | return SelTable.getNullarySelector(FirstII); |
| 512 | else if (N == 1) |
| 513 | return SelTable.getUnarySelector(FirstII); |
| 514 | |
| 515 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 516 | Args.push_back(FirstII); |
| 517 | for (unsigned I = 1; I != N; ++I) |
| 518 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 519 | |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 520 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 521 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 522 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 523 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 524 | using namespace clang::io; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 525 | |
| 526 | data_type Result; |
| 527 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 528 | Result.ID = ReadUnalignedLE32(d); |
| 529 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 530 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 531 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 532 | // Load instance methods |
| 533 | ObjCMethodList *Prev = 0; |
| 534 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 535 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 536 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 537 | if (!Result.Instance.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 538 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 539 | Result.Instance.Method = Method; |
| 540 | Prev = &Result.Instance; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 541 | continue; |
| 542 | } |
| 543 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 544 | ObjCMethodList *Mem = |
| 545 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 546 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 547 | Prev = Prev->Next; |
| 548 | } |
| 549 | |
| 550 | // Load factory methods |
| 551 | Prev = 0; |
| 552 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 553 | ObjCMethodDecl *Method |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 554 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 555 | if (!Result.Factory.Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 556 | // This is the first method, which is the easy case. |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 557 | Result.Factory.Method = Method; |
| 558 | Prev = &Result.Factory; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 559 | continue; |
| 560 | } |
| 561 | |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 562 | ObjCMethodList *Mem = |
| 563 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 564 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 565 | Prev = Prev->Next; |
| 566 | } |
| 567 | |
| 568 | return Result; |
| 569 | } |
| 570 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 571 | |
| 572 | } // end anonymous namespace |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 573 | |
| 574 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 575 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 576 | ASTSelectorLookupTable; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 577 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 578 | namespace clang { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 579 | class ASTIdentifierLookupTrait { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 580 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 581 | ASTReader::PerFileData &F; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 582 | |
| 583 | // If we know the IdentifierInfo in advance, it is here and we will |
| 584 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 585 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 586 | IdentifierInfo *KnownII; |
| 587 | |
| 588 | public: |
| 589 | typedef IdentifierInfo * data_type; |
| 590 | |
| 591 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 592 | |
| 593 | typedef external_key_type internal_key_type; |
| 594 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 595 | ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 596 | IdentifierInfo *II = 0) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 597 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 598 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 599 | static bool EqualKey(const internal_key_type& a, |
| 600 | const internal_key_type& b) { |
| 601 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 602 | : false; |
| 603 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 604 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 605 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 606 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 607 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 608 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 609 | // This hopefully will just get inlined and removed by the optimizer. |
| 610 | static const internal_key_type& |
| 611 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 612 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 613 | // This hopefully will just get inlined and removed by the optimizer. |
| 614 | static const external_key_type& |
| 615 | GetExternalKey(const internal_key_type& x) { return x; } |
| 616 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 617 | static std::pair<unsigned, unsigned> |
| 618 | ReadKeyDataLength(const unsigned char*& d) { |
| 619 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 620 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 621 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 622 | return std::make_pair(KeyLen, DataLen); |
| 623 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 624 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 625 | static std::pair<const char*, unsigned> |
| 626 | ReadKey(const unsigned char* d, unsigned n) { |
| 627 | assert(n >= 2 && d[n-1] == '\0'); |
| 628 | return std::make_pair((const char*) d, n-1); |
| 629 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 630 | |
| 631 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 632 | const unsigned char* d, |
| 633 | unsigned DataLen) { |
| 634 | using namespace clang::io; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 635 | IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 636 | bool IsInteresting = ID & 0x01; |
| 637 | |
| 638 | // Wipe out the "is interesting" bit. |
| 639 | ID = ID >> 1; |
| 640 | |
| 641 | if (!IsInteresting) { |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 642 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 643 | // and associate it with the persistent ID. |
| 644 | IdentifierInfo *II = KnownII; |
| 645 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 646 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 647 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 648 | II->setIsFromAST(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 649 | return II; |
| 650 | } |
| 651 | |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 652 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 653 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 654 | Bits >>= 1; |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 655 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 656 | Bits >>= 1; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 657 | bool Poisoned = Bits & 0x01; |
| 658 | Bits >>= 1; |
| 659 | bool ExtensionToken = Bits & 0x01; |
| 660 | Bits >>= 1; |
| 661 | bool hasMacroDefinition = Bits & 0x01; |
| 662 | Bits >>= 1; |
| 663 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 664 | Bits >>= 10; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 665 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 666 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 667 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 668 | |
| 669 | // Build the IdentifierInfo itself and link the identifier ID with |
| 670 | // the new IdentifierInfo. |
| 671 | IdentifierInfo *II = KnownII; |
| 672 | if (!II) |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 673 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 674 | Reader.SetIdentifierInfo(ID, II); |
| 675 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 676 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 677 | // Token IDs are read-only. |
| 678 | if (HasRevertedTokenIDToIdentifier) |
| 679 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 680 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 681 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 682 | "Incorrect extension token flag"); |
| 683 | (void)ExtensionToken; |
| 684 | II->setIsPoisoned(Poisoned); |
| 685 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 686 | "Incorrect C++ operator keyword flag"); |
| 687 | (void)CPlusPlusOperatorKeyword; |
| 688 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 689 | // If this identifier is a macro, deserialize the macro |
| 690 | // definition. |
| 691 | if (hasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 692 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 693 | Reader.SetIdentifierIsMacro(II, F, Offset); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 694 | DataLen -= 4; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 695 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 696 | |
| 697 | // Read all of the declarations visible at global scope with this |
| 698 | // name. |
Chris Lattner | 6bf690f | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 699 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 700 | if (DataLen > 0) { |
| 701 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 702 | for (; DataLen > 0; DataLen -= 4) |
| 703 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 704 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 705 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 706 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 707 | II->setIsFromAST(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 708 | return II; |
| 709 | } |
| 710 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 711 | |
| 712 | } // end anonymous namespace |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 713 | |
| 714 | /// \brief The on-disk hash table used to contain information about |
| 715 | /// all of the identifiers in the program. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 716 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 717 | ASTIdentifierLookupTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 718 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 719 | namespace { |
| 720 | class ASTDeclContextNameLookupTrait { |
| 721 | ASTReader &Reader; |
| 722 | |
| 723 | public: |
| 724 | /// \brief Pair of begin/end iterators for DeclIDs. |
| 725 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 726 | |
| 727 | /// \brief Special internal key for declaration names. |
| 728 | /// The hash table creates keys for comparison; we do not create |
| 729 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 730 | struct DeclNameKey { |
| 731 | DeclarationName::NameKind Kind; |
| 732 | uint64_t Data; |
| 733 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 734 | }; |
| 735 | |
| 736 | typedef DeclarationName external_key_type; |
| 737 | typedef DeclNameKey internal_key_type; |
| 738 | |
| 739 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
| 740 | |
| 741 | static bool EqualKey(const internal_key_type& a, |
| 742 | const internal_key_type& b) { |
| 743 | return a.Kind == b.Kind && a.Data == b.Data; |
| 744 | } |
| 745 | |
| 746 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 747 | llvm::FoldingSetNodeID ID; |
| 748 | ID.AddInteger(Key.Kind); |
| 749 | |
| 750 | switch (Key.Kind) { |
| 751 | case DeclarationName::Identifier: |
| 752 | case DeclarationName::CXXLiteralOperatorName: |
| 753 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 754 | break; |
| 755 | case DeclarationName::ObjCZeroArgSelector: |
| 756 | case DeclarationName::ObjCOneArgSelector: |
| 757 | case DeclarationName::ObjCMultiArgSelector: |
| 758 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 759 | break; |
| 760 | case DeclarationName::CXXConstructorName: |
| 761 | case DeclarationName::CXXDestructorName: |
| 762 | case DeclarationName::CXXConversionFunctionName: |
| 763 | ID.AddInteger((TypeID)Key.Data); |
| 764 | break; |
| 765 | case DeclarationName::CXXOperatorName: |
| 766 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 767 | break; |
| 768 | case DeclarationName::CXXUsingDirective: |
| 769 | break; |
| 770 | } |
| 771 | |
| 772 | return ID.ComputeHash(); |
| 773 | } |
| 774 | |
| 775 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 776 | DeclNameKey Key; |
| 777 | Key.Kind = Name.getNameKind(); |
| 778 | switch (Name.getNameKind()) { |
| 779 | case DeclarationName::Identifier: |
| 780 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 781 | break; |
| 782 | case DeclarationName::ObjCZeroArgSelector: |
| 783 | case DeclarationName::ObjCOneArgSelector: |
| 784 | case DeclarationName::ObjCMultiArgSelector: |
| 785 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 786 | break; |
| 787 | case DeclarationName::CXXConstructorName: |
| 788 | case DeclarationName::CXXDestructorName: |
| 789 | case DeclarationName::CXXConversionFunctionName: |
| 790 | Key.Data = Reader.GetTypeID(Name.getCXXNameType()); |
| 791 | break; |
| 792 | case DeclarationName::CXXOperatorName: |
| 793 | Key.Data = Name.getCXXOverloadedOperator(); |
| 794 | break; |
| 795 | case DeclarationName::CXXLiteralOperatorName: |
| 796 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 797 | break; |
| 798 | case DeclarationName::CXXUsingDirective: |
| 799 | break; |
| 800 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 801 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 802 | return Key; |
| 803 | } |
| 804 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 805 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 806 | ASTContext *Context = Reader.getContext(); |
| 807 | switch (Key.Kind) { |
| 808 | case DeclarationName::Identifier: |
| 809 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 810 | |
| 811 | case DeclarationName::ObjCZeroArgSelector: |
| 812 | case DeclarationName::ObjCOneArgSelector: |
| 813 | case DeclarationName::ObjCMultiArgSelector: |
| 814 | return DeclarationName(Selector(Key.Data)); |
| 815 | |
| 816 | case DeclarationName::CXXConstructorName: |
| 817 | return Context->DeclarationNames.getCXXConstructorName( |
| 818 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 819 | |
| 820 | case DeclarationName::CXXDestructorName: |
| 821 | return Context->DeclarationNames.getCXXDestructorName( |
| 822 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 823 | |
| 824 | case DeclarationName::CXXConversionFunctionName: |
| 825 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 826 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 827 | |
| 828 | case DeclarationName::CXXOperatorName: |
| 829 | return Context->DeclarationNames.getCXXOperatorName( |
| 830 | (OverloadedOperatorKind)Key.Data); |
| 831 | |
| 832 | case DeclarationName::CXXLiteralOperatorName: |
| 833 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 834 | (IdentifierInfo*)Key.Data); |
| 835 | |
| 836 | case DeclarationName::CXXUsingDirective: |
| 837 | return DeclarationName::getUsingDirectiveName(); |
| 838 | } |
| 839 | |
| 840 | llvm_unreachable("Invalid Name Kind ?"); |
| 841 | } |
| 842 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 843 | static std::pair<unsigned, unsigned> |
| 844 | ReadKeyDataLength(const unsigned char*& d) { |
| 845 | using namespace clang::io; |
| 846 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 847 | unsigned DataLen = ReadUnalignedLE16(d); |
| 848 | return std::make_pair(KeyLen, DataLen); |
| 849 | } |
| 850 | |
| 851 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 852 | using namespace clang::io; |
| 853 | |
| 854 | DeclNameKey Key; |
| 855 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 856 | switch (Key.Kind) { |
| 857 | case DeclarationName::Identifier: |
| 858 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 859 | break; |
| 860 | case DeclarationName::ObjCZeroArgSelector: |
| 861 | case DeclarationName::ObjCOneArgSelector: |
| 862 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 863 | Key.Data = |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 864 | (uint64_t)Reader.DecodeSelector(ReadUnalignedLE32(d)).getAsOpaquePtr(); |
| 865 | break; |
| 866 | case DeclarationName::CXXConstructorName: |
| 867 | case DeclarationName::CXXDestructorName: |
| 868 | case DeclarationName::CXXConversionFunctionName: |
| 869 | Key.Data = ReadUnalignedLE32(d); // TypeID |
| 870 | break; |
| 871 | case DeclarationName::CXXOperatorName: |
| 872 | Key.Data = *d++; // OverloadedOperatorKind |
| 873 | break; |
| 874 | case DeclarationName::CXXLiteralOperatorName: |
| 875 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 876 | break; |
| 877 | case DeclarationName::CXXUsingDirective: |
| 878 | break; |
| 879 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 880 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 881 | return Key; |
| 882 | } |
| 883 | |
| 884 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 885 | unsigned DataLen) { |
| 886 | using namespace clang::io; |
| 887 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 888 | DeclID *Start = (DeclID *)d; |
| 889 | return std::make_pair(Start, Start + NumDecls); |
| 890 | } |
| 891 | }; |
| 892 | |
| 893 | } // end anonymous namespace |
| 894 | |
| 895 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 896 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 897 | ASTDeclContextNameLookupTable; |
| 898 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 899 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 900 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 901 | DeclContextInfo &Info) { |
| 902 | SavedStreamPosition SavedPosition(Cursor); |
| 903 | // First the lexical decls. |
| 904 | if (Offsets.first != 0) { |
| 905 | Cursor.JumpToBit(Offsets.first); |
| 906 | |
| 907 | RecordData Record; |
| 908 | const char *Blob; |
| 909 | unsigned BlobLen; |
| 910 | unsigned Code = Cursor.ReadCode(); |
| 911 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 912 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 913 | Error("Expected lexical block"); |
| 914 | return true; |
| 915 | } |
| 916 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 917 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 918 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 919 | } else { |
| 920 | Info.LexicalDecls = 0; |
| 921 | Info.NumLexicalDecls = 0; |
| 922 | } |
| 923 | |
| 924 | // Now the lookup table. |
| 925 | if (Offsets.second != 0) { |
| 926 | Cursor.JumpToBit(Offsets.second); |
| 927 | |
| 928 | RecordData Record; |
| 929 | const char *Blob; |
| 930 | unsigned BlobLen; |
| 931 | unsigned Code = Cursor.ReadCode(); |
| 932 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 933 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 934 | Error("Expected visible lookup table block"); |
| 935 | return true; |
| 936 | } |
| 937 | Info.NameLookupTableData |
| 938 | = ASTDeclContextNameLookupTable::Create( |
| 939 | (const unsigned char *)Blob + Record[0], |
| 940 | (const unsigned char *)Blob, |
| 941 | ASTDeclContextNameLookupTrait(*this)); |
Sebastian Redl | 0ea8f7f | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 942 | } else { |
| 943 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | return false; |
| 947 | } |
| 948 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 949 | void ASTReader::Error(const char *Msg) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 950 | Diag(diag::err_fe_pch_malformed) << Msg; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 951 | } |
| 952 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 953 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 954 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 955 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 956 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 957 | ActualOriginalFileName, |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 958 | SuggestedPredefines); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 959 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 962 | //===----------------------------------------------------------------------===// |
| 963 | // Source Manager Deserialization |
| 964 | //===----------------------------------------------------------------------===// |
| 965 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 966 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 967 | /// \returns true if there was an error. |
| 968 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 969 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 970 | unsigned Idx = 0; |
| 971 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 972 | |
| 973 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 974 | std::map<int, int> FileIDs; |
| 975 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 976 | // Extract the file name |
| 977 | unsigned FilenameLen = Record[Idx++]; |
| 978 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 979 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 980 | MaybeAddSystemRootToFilename(Filename); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 981 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 982 | Filename.size()); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | // Parse the line entries |
| 986 | std::vector<LineEntry> Entries; |
| 987 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 988 | int FID = Record[Idx++]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 989 | |
| 990 | // Extract the line entries |
| 991 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 992 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 993 | Entries.clear(); |
| 994 | Entries.reserve(NumEntries); |
| 995 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 996 | unsigned FileOffset = Record[Idx++]; |
| 997 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 998 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 999 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1000 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1001 | unsigned IncludeOffset = Record[Idx++]; |
| 1002 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1003 | FileKind, IncludeOffset)); |
| 1004 | } |
| 1005 | LineTable.AddEntry(FID, Entries); |
| 1006 | } |
| 1007 | |
| 1008 | return false; |
| 1009 | } |
| 1010 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1011 | namespace { |
| 1012 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1013 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1014 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1015 | const ino_t ino; |
| 1016 | const dev_t dev; |
| 1017 | const mode_t mode; |
| 1018 | const time_t mtime; |
| 1019 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1020 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1021 | 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] | 1022 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1023 | }; |
| 1024 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1025 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1026 | public: |
| 1027 | typedef const char *external_key_type; |
| 1028 | typedef const char *internal_key_type; |
| 1029 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1030 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1031 | |
| 1032 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1033 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1037 | |
| 1038 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1039 | return strcmp(a, b) == 0; |
| 1040 | } |
| 1041 | |
| 1042 | static std::pair<unsigned, unsigned> |
| 1043 | ReadKeyDataLength(const unsigned char*& d) { |
| 1044 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1045 | unsigned DataLen = (unsigned) *d++; |
| 1046 | return std::make_pair(KeyLen + 1, DataLen); |
| 1047 | } |
| 1048 | |
| 1049 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1050 | return (const char *)d; |
| 1051 | } |
| 1052 | |
| 1053 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1054 | unsigned /*DataLen*/) { |
| 1055 | using namespace clang::io; |
| 1056 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1057 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1058 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1059 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1060 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1061 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1062 | return data_type(ino, dev, mode, mtime, size); |
| 1063 | } |
| 1064 | }; |
| 1065 | |
| 1066 | /// \brief stat() cache for precompiled headers. |
| 1067 | /// |
| 1068 | /// This cache is very similar to the stat cache used by pretokenized |
| 1069 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1070 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1071 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1072 | CacheTy *Cache; |
| 1073 | |
| 1074 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1075 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1076 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1077 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1078 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1079 | Cache = CacheTy::Create(Buckets, Base); |
| 1080 | } |
| 1081 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1082 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1083 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1084 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1085 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1086 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1087 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1088 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1089 | // 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] | 1090 | if (I == Cache->end()) { |
| 1091 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1092 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1093 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1095 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1096 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1097 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1098 | StatBuf.st_ino = Data.ino; |
| 1099 | StatBuf.st_dev = Data.dev; |
| 1100 | StatBuf.st_mtime = Data.mtime; |
| 1101 | StatBuf.st_mode = Data.mode; |
| 1102 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1103 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1104 | } |
| 1105 | }; |
| 1106 | } // end anonymous namespace |
| 1107 | |
| 1108 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1109 | /// \brief Read a source manager block |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1110 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1111 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1112 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1113 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1114 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1115 | // Set the source-location entry cursor to the current position in |
| 1116 | // the stream. This cursor will be used to read the contents of the |
| 1117 | // source manager block initially, and then lazily read |
| 1118 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1119 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1120 | |
| 1121 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1122 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1123 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1124 | return Failure; |
| 1125 | } |
| 1126 | |
| 1127 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1128 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1129 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1130 | return Failure; |
| 1131 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1132 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1133 | RecordData Record; |
| 1134 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1135 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1136 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1137 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1138 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1139 | return Failure; |
| 1140 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1141 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1142 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1143 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1144 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1145 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1146 | SLocEntryCursor.ReadSubBlockID(); |
| 1147 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1148 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1149 | return Failure; |
| 1150 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1151 | continue; |
| 1152 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1153 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1154 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1155 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1156 | continue; |
| 1157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1158 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1159 | // Read a record. |
| 1160 | const char *BlobStart; |
| 1161 | unsigned BlobLen; |
| 1162 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1163 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1164 | default: // Default behavior: ignore. |
| 1165 | break; |
| 1166 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1167 | case SM_LINE_TABLE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1168 | if (ParseLineTable(F, Record)) |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1169 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1170 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1171 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1172 | case SM_SLOC_FILE_ENTRY: |
| 1173 | case SM_SLOC_BUFFER_ENTRY: |
| 1174 | case SM_SLOC_INSTANTIATION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1175 | // Once we hit one of the source location entries, we're done. |
| 1176 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | } |
| 1180 | |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1181 | /// \brief Get a cursor that's correctly positioned for reading the source |
| 1182 | /// location entry with the given ID. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1183 | ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1184 | assert(ID != 0 && ID <= TotalNumSLocEntries && |
| 1185 | "SLocCursorForID should only be called for real IDs."); |
| 1186 | |
| 1187 | ID -= 1; |
| 1188 | PerFileData *F = 0; |
| 1189 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1190 | F = Chain[N - I - 1]; |
| 1191 | if (ID < F->LocalNumSLocEntries) |
| 1192 | break; |
| 1193 | ID -= F->LocalNumSLocEntries; |
| 1194 | } |
| 1195 | assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); |
| 1196 | |
| 1197 | F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1198 | return F; |
Sebastian Redl | 190faf7 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1201 | /// \brief Read in the source location entry with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1202 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1203 | if (ID == 0) |
| 1204 | return Success; |
| 1205 | |
| 1206 | if (ID > TotalNumSLocEntries) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1207 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1208 | return Failure; |
| 1209 | } |
| 1210 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1211 | PerFileData *F = SLocCursorForID(ID); |
| 1212 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1213 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1214 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1215 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1216 | if (Code == llvm::bitc::END_BLOCK || |
| 1217 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1218 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1219 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1220 | return Failure; |
| 1221 | } |
| 1222 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1223 | RecordData Record; |
| 1224 | const char *BlobStart; |
| 1225 | unsigned BlobLen; |
| 1226 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1227 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1228 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1229 | return Failure; |
| 1230 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1231 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1232 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1233 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1234 | const FileEntry *File = FileMgr.getFile(Filename); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1235 | if (File == 0) { |
| 1236 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1237 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1238 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1239 | Error(ErrorStr.c_str()); |
| 1240 | return Failure; |
| 1241 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1243 | if (Record.size() < 10) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1244 | Error("source location entry is incorrect"); |
| 1245 | return Failure; |
| 1246 | } |
| 1247 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1248 | if (!DisableValidation && |
| 1249 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1250 | #if !defined(LLVM_ON_WIN32) |
| 1251 | // In our regression testing, the Windows file system seems to |
| 1252 | // have inconsistent modification times that sometimes |
| 1253 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1254 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1255 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1256 | )) { |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1257 | Diag(diag::err_fe_pch_file_modified) |
| 1258 | << Filename; |
| 1259 | return Failure; |
| 1260 | } |
| 1261 | |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1262 | FileID FID = SourceMgr.createFileID(File, ReadSourceLocation(*F, Record[1]), |
| 1263 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1264 | ID, Record[0]); |
| 1265 | if (Record[3]) |
| 1266 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1267 | .setHasLineDirectives(); |
| 1268 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 1269 | // Reconstruct header-search information for this file. |
| 1270 | HeaderFileInfo HFI; |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1271 | HFI.isImport = Record[6]; |
| 1272 | HFI.DirInfo = Record[7]; |
| 1273 | HFI.NumIncludes = Record[8]; |
| 1274 | HFI.ControllingMacroID = Record[9]; |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 1275 | if (Listener) |
| 1276 | Listener->ReadHeaderFileInfo(HFI, File->getUID()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1277 | break; |
| 1278 | } |
| 1279 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1280 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1281 | const char *Name = BlobStart; |
| 1282 | unsigned Offset = Record[0]; |
| 1283 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1284 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1285 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1286 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1287 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1288 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1289 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1290 | return Failure; |
| 1291 | } |
| 1292 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1293 | llvm::MemoryBuffer *Buffer |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1294 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1295 | Name); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1296 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1297 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1298 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1299 | PCHPredefinesBlock Block = { |
| 1300 | BufferID, |
| 1301 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1302 | }; |
| 1303 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1304 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1305 | |
| 1306 | break; |
| 1307 | } |
| 1308 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1309 | case SM_SLOC_INSTANTIATION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1310 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1311 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1312 | ReadSourceLocation(*F, Record[2]), |
| 1313 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1314 | Record[4], |
| 1315 | ID, |
| 1316 | Record[0]); |
| 1317 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1318 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | return Success; |
| 1322 | } |
| 1323 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1324 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1325 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1326 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1327 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1328 | unsigned BlockID) { |
| 1329 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1330 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1331 | return Failure; |
| 1332 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1334 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1335 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1336 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1337 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1338 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1339 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1340 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1341 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1342 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1343 | Cursor.ReadAbbrevRecord(); |
| 1344 | } |
| 1345 | } |
| 1346 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1347 | PreprocessedEntity *ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1348 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1349 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1350 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1351 | // Keep track of where we are in the stream, then jump back there |
| 1352 | // after reading this macro. |
| 1353 | SavedStreamPosition SavedPosition(Stream); |
| 1354 | |
| 1355 | Stream.JumpToBit(Offset); |
| 1356 | RecordData Record; |
| 1357 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1358 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1359 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1360 | while (true) { |
| 1361 | unsigned Code = Stream.ReadCode(); |
| 1362 | switch (Code) { |
| 1363 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1364 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1365 | |
| 1366 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1367 | // No known subblocks, always skip them. |
| 1368 | Stream.ReadSubBlockID(); |
| 1369 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1370 | Error("malformed block record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1371 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1372 | } |
| 1373 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1374 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1375 | case llvm::bitc::DEFINE_ABBREV: |
| 1376 | Stream.ReadAbbrevRecord(); |
| 1377 | continue; |
| 1378 | default: break; |
| 1379 | } |
| 1380 | |
| 1381 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1382 | const char *BlobStart = 0; |
| 1383 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1384 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1385 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1386 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1387 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1388 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1389 | case PP_MACRO_OBJECT_LIKE: |
| 1390 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1391 | // If we already have a macro, that means that we've hit the end |
| 1392 | // of the definition of the macro we were looking for. We're |
| 1393 | // done. |
| 1394 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1395 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1396 | |
| 1397 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1398 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1399 | Error("macro must have a name in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1400 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1401 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1402 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1403 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1404 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1405 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1406 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1407 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1408 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1409 | unsigned NextIndex = 3; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1410 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1411 | // Decode function-like macro info. |
| 1412 | bool isC99VarArgs = Record[3]; |
| 1413 | bool isGNUVarArgs = Record[4]; |
| 1414 | MacroArgs.clear(); |
| 1415 | unsigned NumArgs = Record[5]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1416 | NextIndex = 6 + NumArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1417 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1418 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1419 | |
| 1420 | // Install function-like macro info. |
| 1421 | MI->setIsFunctionLike(); |
| 1422 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1423 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1424 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1425 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1429 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1430 | |
| 1431 | // Remember that we saw this macro last so that we add the tokens that |
| 1432 | // form its body to it. |
| 1433 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1434 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1435 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1436 | // We have a macro definition. Load it now. |
| 1437 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1438 | getMacroDefinition(Record[NextIndex])); |
| 1439 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1440 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1441 | ++NumMacrosRead; |
| 1442 | break; |
| 1443 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1444 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1445 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1446 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1447 | // erroneous, just pretend we didn't see this. |
| 1448 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1449 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1450 | Token Tok; |
| 1451 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1452 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1453 | Tok.setLength(Record[1]); |
| 1454 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1455 | Tok.setIdentifierInfo(II); |
| 1456 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1457 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1458 | Macro->AddTokenToBody(Tok); |
| 1459 | break; |
| 1460 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1461 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1462 | case PP_MACRO_INSTANTIATION: { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1463 | // If we already have a macro, that means that we've hit the end |
| 1464 | // of the definition of the macro we were looking for. We're |
| 1465 | // done. |
| 1466 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1467 | return 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1468 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1469 | if (!PP->getPreprocessingRecord()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1470 | Error("missing preprocessing record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1471 | return 0; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1472 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1473 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1474 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1475 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1476 | return PE; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1477 | |
| 1478 | MacroInstantiation *MI |
| 1479 | = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1480 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1481 | ReadSourceLocation(F, Record[2])), |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1482 | getMacroDefinition(Record[4])); |
| 1483 | PPRec.SetPreallocatedEntity(Record[0], MI); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1484 | return MI; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1487 | case PP_MACRO_DEFINITION: { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1488 | // If we already have a macro, that means that we've hit the end |
| 1489 | // of the definition of the macro we were looking for. We're |
| 1490 | // done. |
| 1491 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1492 | return 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1493 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1494 | if (!PP->getPreprocessingRecord()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1495 | Error("missing preprocessing record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1496 | return 0; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1497 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1498 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1499 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1500 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1501 | return PE; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1502 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1503 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1504 | Error("out-of-bounds macro definition record"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1505 | return 0; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1508 | // 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] | 1509 | // still defined and associated with the identifier, |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1510 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1511 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1512 | MacroDefinition *MD |
| 1513 | = new (PPRec) MacroDefinition(II, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1514 | ReadSourceLocation(F, Record[5]), |
Douglas Gregor | b1a7d9a | 2010-10-01 20:33:34 +0000 | [diff] [blame] | 1515 | SourceRange( |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1516 | ReadSourceLocation(F, Record[2]), |
| 1517 | ReadSourceLocation(F, Record[3]))); |
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 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1520 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1521 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1522 | if (DeserializationListener) |
| 1523 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1524 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1525 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1526 | return MacroDefinitionsLoaded[Record[1] - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1527 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1528 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1529 | case PP_INCLUSION_DIRECTIVE: { |
| 1530 | // If we already have a macro, that means that we've hit the end |
| 1531 | // of the definition of the macro we were looking for. We're |
| 1532 | // done. |
| 1533 | if (Macro) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1534 | return 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1535 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1536 | if (!PP->getPreprocessingRecord()) { |
| 1537 | Error("missing preprocessing record in AST file"); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1538 | return 0; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1539 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1540 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1541 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1542 | if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) |
| 1543 | return PE; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1544 | |
| 1545 | const char *FullFileNameStart = BlobStart + Record[3]; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1546 | const FileEntry *File |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1547 | = PP->getFileManager().getFile(llvm::StringRef(FullFileNameStart, |
| 1548 | BlobLen - Record[3])); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1549 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1550 | // FIXME: Stable encoding |
| 1551 | InclusionDirective::InclusionKind Kind |
| 1552 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1553 | InclusionDirective *ID |
Douglas Gregor | 4ab829c | 2010-11-01 15:03:47 +0000 | [diff] [blame] | 1554 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1555 | llvm::StringRef(BlobStart, Record[3]), |
| 1556 | Record[4], |
| 1557 | File, |
| 1558 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1559 | ReadSourceLocation(F, Record[2]))); |
| 1560 | PPRec.SetPreallocatedEntity(Record[0], ID); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1561 | return ID; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1562 | } |
Sebastian Redl | b57a624 | 2010-09-27 22:18:47 +0000 | [diff] [blame] | 1563 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1564 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1565 | |
| 1566 | return 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1569 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F, |
| 1570 | uint64_t Offset) { |
| 1571 | // Note that this identifier has a macro definition. |
| 1572 | II->setHasMacroDefinition(true); |
| 1573 | |
| 1574 | // Adjust the offset based on our position in the chain. |
| 1575 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1576 | if (Chain[I] == &F) |
| 1577 | break; |
| 1578 | |
| 1579 | Offset += Chain[I]->SizeInBits; |
| 1580 | } |
| 1581 | |
| 1582 | UnreadMacroRecordOffsets[II] = Offset; |
| 1583 | } |
| 1584 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1585 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1586 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1587 | PerFileData &F = *Chain[N - I - 1]; |
| 1588 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1589 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1590 | // If there was no preprocessor block, skip this file. |
| 1591 | if (!MacroCursor.getBitStreamReader()) |
| 1592 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1593 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1594 | llvm::BitstreamCursor Cursor = MacroCursor; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1595 | Cursor.JumpToBit(F.MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1596 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1597 | RecordData Record; |
| 1598 | while (true) { |
Sebastian Redl | edadecc | 2010-09-28 02:55:49 +0000 | [diff] [blame] | 1599 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1600 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1601 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1602 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1603 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1604 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1605 | // No known subblocks, always skip them. |
| 1606 | Cursor.ReadSubBlockID(); |
| 1607 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1608 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1609 | return; |
| 1610 | } |
| 1611 | continue; |
| 1612 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1613 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1614 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1615 | Cursor.ReadAbbrevRecord(); |
| 1616 | continue; |
| 1617 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1618 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1619 | // Read a record. |
| 1620 | const char *BlobStart; |
| 1621 | unsigned BlobLen; |
| 1622 | Record.clear(); |
| 1623 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1624 | default: // Default behavior: ignore. |
| 1625 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1626 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1627 | case PP_MACRO_OBJECT_LIKE: |
| 1628 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1629 | DecodeIdentifierInfo(Record[0]); |
| 1630 | break; |
| 1631 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1632 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1633 | // Ignore tokens. |
| 1634 | break; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1635 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1636 | case PP_MACRO_INSTANTIATION: |
| 1637 | case PP_MACRO_DEFINITION: |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1638 | case PP_INCLUSION_DIRECTIVE: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1639 | // Read the macro record. |
Sebastian Redl | edadecc | 2010-09-28 02:55:49 +0000 | [diff] [blame] | 1640 | // 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] | 1641 | ReadMacroRecord(F, Offset); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1642 | break; |
| 1643 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1644 | } |
| 1645 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1646 | |
| 1647 | // Drain the unread macro-record offsets map. |
| 1648 | while (!UnreadMacroRecordOffsets.empty()) |
| 1649 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1650 | } |
| 1651 | |
| 1652 | void ASTReader::LoadMacroDefinition( |
| 1653 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1654 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
| 1655 | PerFileData *F = 0; |
| 1656 | uint64_t Offset = Pos->second; |
| 1657 | UnreadMacroRecordOffsets.erase(Pos); |
| 1658 | |
| 1659 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1660 | if (Offset < Chain[I]->SizeInBits) { |
| 1661 | F = Chain[I]; |
| 1662 | break; |
| 1663 | } |
| 1664 | |
| 1665 | Offset -= Chain[I]->SizeInBits; |
| 1666 | } |
| 1667 | if (!F) { |
| 1668 | Error("Malformed macro record offset"); |
| 1669 | return; |
| 1670 | } |
| 1671 | |
| 1672 | ReadMacroRecord(*F, Offset); |
| 1673 | } |
| 1674 | |
| 1675 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1676 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1677 | = UnreadMacroRecordOffsets.find(II); |
| 1678 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1681 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1682 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1683 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1684 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1685 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1686 | unsigned Index = ID - 1; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1687 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1688 | PerFileData &F = *Chain[N - I - 1]; |
| 1689 | if (Index < F.LocalNumMacroDefinitions) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1690 | ReadMacroRecord(F, F.MacroDefinitionOffsets[Index]); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1691 | break; |
| 1692 | } |
| 1693 | Index -= F.LocalNumMacroDefinitions; |
| 1694 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1695 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1698 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1701 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1702 | /// not an absolute path, add the system root to the beginning of the file |
| 1703 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1704 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1705 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1706 | if (!RelocatablePCH) |
| 1707 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1708 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1709 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1710 | return; |
| 1711 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1712 | if (isysroot == 0) { |
| 1713 | // If no system root was given, default to '/' |
| 1714 | Filename.insert(Filename.begin(), '/'); |
| 1715 | return; |
| 1716 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1717 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1718 | unsigned Length = strlen(isysroot); |
| 1719 | if (isysroot[Length - 1] != '/') |
| 1720 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1721 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1722 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1723 | } |
| 1724 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1725 | ASTReader::ASTReadResult |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1726 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1727 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1728 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1729 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1730 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1731 | return Failure; |
| 1732 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1733 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1734 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1735 | RecordData Record; |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1736 | bool First = true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1737 | while (!Stream.AtEndOfStream()) { |
| 1738 | unsigned Code = Stream.ReadCode(); |
| 1739 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1740 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1741 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1742 | return Failure; |
| 1743 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1744 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1745 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1749 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1750 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1751 | // We lazily load the decls block, but we want to set up the |
| 1752 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1753 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1754 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1755 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1756 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1757 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1758 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1759 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1760 | return Failure; |
| 1761 | } |
| 1762 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1763 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1764 | case DECL_UPDATES_BLOCK_ID: |
| 1765 | if (Stream.SkipBlock()) { |
| 1766 | Error("malformed block record in AST file"); |
| 1767 | return Failure; |
| 1768 | } |
| 1769 | break; |
| 1770 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1771 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1772 | F.MacroCursor = Stream; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1773 | if (PP) |
| 1774 | PP->setExternalSource(this); |
| 1775 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1776 | if (Stream.SkipBlock() || |
| 1777 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1778 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1779 | return Failure; |
| 1780 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1781 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1782 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1783 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1784 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1785 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1786 | case Success: |
| 1787 | break; |
| 1788 | |
| 1789 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1790 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1791 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1792 | |
| 1793 | case IgnorePCH: |
| 1794 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1795 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1796 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1797 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1798 | First = false; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1799 | continue; |
| 1800 | } |
| 1801 | |
| 1802 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1803 | Stream.ReadAbbrevRecord(); |
| 1804 | continue; |
| 1805 | } |
| 1806 | |
| 1807 | // Read and process a record. |
| 1808 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1809 | const char *BlobStart = 0; |
| 1810 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1811 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1812 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1813 | default: // Default behavior: ignore. |
| 1814 | break; |
| 1815 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1816 | case METADATA: { |
| 1817 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1818 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1819 | : diag::warn_pch_version_too_new); |
| 1820 | return IgnorePCH; |
| 1821 | } |
| 1822 | |
| 1823 | RelocatablePCH = Record[4]; |
| 1824 | if (Listener) { |
| 1825 | std::string TargetTriple(BlobStart, BlobLen); |
| 1826 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1827 | return IgnorePCH; |
| 1828 | } |
| 1829 | break; |
| 1830 | } |
| 1831 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1832 | case CHAINED_METADATA: { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1833 | if (!First) { |
| 1834 | Error("CHAINED_METADATA is not first record in block"); |
| 1835 | return Failure; |
| 1836 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1837 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1838 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1839 | : diag::warn_pch_version_too_new); |
| 1840 | return IgnorePCH; |
| 1841 | } |
| 1842 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 1843 | // Load the chained file, which is always a PCH file. |
| 1844 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1845 | case Failure: return Failure; |
| 1846 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1847 | case IgnorePCH: return IgnorePCH; |
| 1848 | case Success: break; |
| 1849 | } |
| 1850 | break; |
| 1851 | } |
| 1852 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1853 | case TYPE_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1854 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1855 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1856 | return Failure; |
| 1857 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1858 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1859 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1860 | break; |
| 1861 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1862 | case DECL_OFFSET: |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1863 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1864 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1865 | return Failure; |
| 1866 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1867 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 1868 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1869 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1870 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1871 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1872 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 1873 | /* No visible information */ 0, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 1874 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 1875 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1876 | }; |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 1877 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 1878 | .push_back(Info); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1879 | break; |
| 1880 | } |
| 1881 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1882 | case UPDATE_VISIBLE: { |
| 1883 | serialization::DeclID ID = Record[0]; |
| 1884 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 1885 | (const unsigned char *)BlobStart + Record[1], |
| 1886 | (const unsigned char *)BlobStart, |
| 1887 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 1888 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1889 | DeclContextInfo Info = { |
| 1890 | Table, /* No lexical inforamtion */ 0, 0 |
| 1891 | }; |
| 1892 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 1893 | } else |
| 1894 | PendingVisibleUpdates[ID].push_back(Table); |
| 1895 | break; |
| 1896 | } |
| 1897 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1898 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1899 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 1900 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1901 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1902 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 1903 | Latest > FirstLatestDeclIDs[First]) && |
| 1904 | "The new latest is supposed to come after the previous latest"); |
| 1905 | FirstLatestDeclIDs[First] = Latest; |
| 1906 | } |
| 1907 | break; |
| 1908 | } |
| 1909 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1910 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1911 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1912 | return IgnorePCH; |
| 1913 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1914 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1915 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1916 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1917 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1918 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1919 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1920 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 1921 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1922 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1923 | if (PP) |
| 1924 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1925 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1926 | break; |
| 1927 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1928 | case IDENTIFIER_OFFSET: |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1929 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1930 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1931 | return Failure; |
| 1932 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1933 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1934 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1935 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1936 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1937 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1938 | // Optimization for the first block. |
| 1939 | if (ExternalDefinitions.empty()) |
| 1940 | ExternalDefinitions.swap(Record); |
| 1941 | else |
| 1942 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 1943 | Record.begin(), Record.end()); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1944 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1945 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1946 | case SPECIAL_TYPES: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1947 | // Optimization for the first block |
| 1948 | if (SpecialTypes.empty()) |
| 1949 | SpecialTypes.swap(Record); |
| 1950 | else |
| 1951 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1952 | break; |
| 1953 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1954 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1955 | TotalNumStatements += Record[0]; |
| 1956 | TotalNumMacros += Record[1]; |
| 1957 | TotalLexicalDeclContexts += Record[2]; |
| 1958 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1959 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1960 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1961 | case TENTATIVE_DEFINITIONS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1962 | // Optimization for the first block. |
| 1963 | if (TentativeDefinitions.empty()) |
| 1964 | TentativeDefinitions.swap(Record); |
| 1965 | else |
| 1966 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 1967 | Record.begin(), Record.end()); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 1968 | break; |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1969 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1970 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1971 | // Optimization for the first block. |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 1972 | if (UnusedFileScopedDecls.empty()) |
| 1973 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1974 | else |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 1975 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 1976 | Record.begin(), Record.end()); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 1977 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1978 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1979 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 1980 | // Later blocks overwrite earlier ones. |
| 1981 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 1982 | break; |
| 1983 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1984 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1985 | // Optimization for the first block. |
| 1986 | if (LocallyScopedExternalDecls.empty()) |
| 1987 | LocallyScopedExternalDecls.swap(Record); |
| 1988 | else |
| 1989 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 1990 | Record.begin(), Record.end()); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1991 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1992 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1993 | case SELECTOR_OFFSETS: |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 1994 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1995 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1996 | break; |
| 1997 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1998 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1999 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2000 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2001 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2002 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2003 | F.SelectorLookupTableData + Record[0], |
| 2004 | F.SelectorLookupTableData, |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2005 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2006 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2007 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2008 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2009 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2010 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2011 | break; |
| 2012 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2013 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2014 | if (!Record.empty() && Listener) |
| 2015 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2016 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2017 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2018 | case SOURCE_LOCATION_OFFSETS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2019 | F.SLocOffsets = (const uint32_t *)BlobStart; |
| 2020 | F.LocalNumSLocEntries = Record[0]; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2021 | F.LocalSLocSize = Record[1]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2022 | break; |
| 2023 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2024 | case SOURCE_LOCATION_PRELOADS: |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2025 | if (PreloadSLocEntries.empty()) |
| 2026 | PreloadSLocEntries.swap(Record); |
| 2027 | else |
| 2028 | PreloadSLocEntries.insert(PreloadSLocEntries.end(), |
| 2029 | Record.begin(), Record.end()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2030 | break; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2031 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2032 | case STAT_CACHE: { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2033 | ASTStatCache *MyStatCache = |
| 2034 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2035 | (const unsigned char *)BlobStart, |
| 2036 | NumStatHits, NumStatMisses); |
| 2037 | FileMgr.addStatCache(MyStatCache); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2038 | F.StatCache = MyStatCache; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2039 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2040 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2041 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2042 | case EXT_VECTOR_DECLS: |
Sebastian Redl | a9f2368 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 2043 | // Optimization for the first block. |
| 2044 | if (ExtVectorDecls.empty()) |
| 2045 | ExtVectorDecls.swap(Record); |
| 2046 | else |
| 2047 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 2048 | Record.begin(), Record.end()); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2049 | break; |
| 2050 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2051 | case VTABLE_USES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2052 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2053 | VTableUses.swap(Record); |
| 2054 | break; |
| 2055 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2056 | case DYNAMIC_CLASSES: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2057 | // Optimization for the first block. |
| 2058 | if (DynamicClasses.empty()) |
| 2059 | DynamicClasses.swap(Record); |
| 2060 | else |
| 2061 | DynamicClasses.insert(DynamicClasses.end(), |
| 2062 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2063 | break; |
| 2064 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2065 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2066 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2067 | break; |
| 2068 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2069 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2070 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2071 | SemaDeclRefs.swap(Record); |
| 2072 | break; |
| 2073 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2074 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2075 | // 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] | 2076 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2077 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2078 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2079 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2080 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2081 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2082 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2083 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2084 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 2085 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2086 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2087 | return IgnorePCH; |
| 2088 | } |
| 2089 | break; |
| 2090 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2091 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2092 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2093 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2094 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2095 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2096 | break; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2097 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2098 | case DECL_UPDATE_OFFSETS: { |
| 2099 | if (Record.size() % 2 != 0) { |
| 2100 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2101 | return Failure; |
| 2102 | } |
| 2103 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
| 2104 | DeclUpdateOffsets[static_cast<DeclID>(Record[I])] |
| 2105 | .push_back(std::make_pair(&F, Record[I+1])); |
| 2106 | break; |
| 2107 | } |
| 2108 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2109 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2110 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2111 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2112 | return Failure; |
| 2113 | } |
| 2114 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2115 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2116 | std::make_pair(&F, Record[I+1]); |
| 2117 | break; |
| 2118 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2119 | |
| 2120 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2121 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2122 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2123 | return Failure; |
| 2124 | } |
| 2125 | |
| 2126 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2127 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
| 2128 | break; |
| 2129 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2130 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2131 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2132 | if (Record.size() % 2 != 0) { |
| 2133 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2134 | return Failure; |
| 2135 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2136 | if (PragmaDiagMappings.empty()) |
| 2137 | PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2138 | else |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2139 | PragmaDiagMappings.insert(PragmaDiagMappings.end(), |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2140 | Record.begin(), Record.end()); |
| 2141 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2142 | } |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2143 | First = false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2144 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2145 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2146 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2149 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2150 | ASTFileType Type) { |
| 2151 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2152 | case Failure: return Failure; |
| 2153 | case IgnorePCH: return IgnorePCH; |
| 2154 | case Success: break; |
| 2155 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2156 | |
| 2157 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2158 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2159 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2160 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2161 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2162 | TotalNumSelectors = 0; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2163 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2164 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2165 | NextSLocOffset += Chain[I]->LocalSLocSize; |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2166 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2167 | TotalNumTypes += Chain[I]->LocalNumTypes; |
| 2168 | TotalNumDecls += Chain[I]->LocalNumDecls; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2169 | TotalNumPreallocatedPreprocessingEntities += |
| 2170 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2171 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2172 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2173 | } |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2174 | SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset); |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2175 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2176 | TypesLoaded.resize(TotalNumTypes); |
| 2177 | DeclsLoaded.resize(TotalNumDecls); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2178 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2179 | if (PP) { |
| 2180 | if (TotalNumIdentifiers > 0) |
| 2181 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2182 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2183 | if (!PP->getPreprocessingRecord()) |
| 2184 | PP->createPreprocessingRecord(); |
| 2185 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2186 | TotalNumPreallocatedPreprocessingEntities); |
| 2187 | } |
| 2188 | } |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2189 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2190 | // Preload SLocEntries. |
| 2191 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2192 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2193 | if (Result != Success) |
| 2194 | return Result; |
| 2195 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2196 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2197 | // Check the predefines buffers. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2198 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2199 | return IgnorePCH; |
| 2200 | |
| 2201 | if (PP) { |
| 2202 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2203 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2204 | // loaded into the IdentifierTable before we intercepted the |
| 2205 | // creation of identifiers. Iterate through the list of known |
| 2206 | // identifiers and determine whether we have to establish |
| 2207 | // preprocessor definitions or top-level identifier declaration |
| 2208 | // chains for those identifiers. |
| 2209 | // |
| 2210 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2211 | // since de-serializing declarations or macro definitions can add |
| 2212 | // new entries into the identifier table, invalidating the |
| 2213 | // iterators. |
| 2214 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2215 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2216 | IdEnd = PP->getIdentifierTable().end(); |
| 2217 | Id != IdEnd; ++Id) |
| 2218 | Identifiers.push_back(Id->second); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2219 | // We need to search the tables in all files. |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2220 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2221 | ASTIdentifierLookupTable *IdTable |
| 2222 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2223 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2224 | // ones. |
| 2225 | if (!IdTable) |
| 2226 | continue; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2227 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2228 | IdentifierInfo *II = Identifiers[I]; |
| 2229 | // 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] | 2230 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2231 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2232 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2233 | if (Pos == IdTable->end()) |
| 2234 | continue; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2235 | |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2236 | // Dereferencing the iterator has the effect of populating the |
| 2237 | // IdentifierInfo node with the various declarations it needs. |
| 2238 | (void)*Pos; |
| 2239 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | if (Context) |
| 2244 | InitializeContext(*Context); |
| 2245 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2246 | if (DeserializationListener) |
| 2247 | DeserializationListener->ReaderInitialized(this); |
| 2248 | |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2249 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2250 | // the source manager to the file source file from which the preamble was |
| 2251 | // built. This is the only valid way to use a precompiled preamble. |
| 2252 | if (Type == Preamble) { |
| 2253 | SourceLocation Loc |
| 2254 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2255 | if (Loc.isValid()) { |
| 2256 | std::pair<FileID, unsigned> Decomposed = SourceMgr.getDecomposedLoc(Loc); |
| 2257 | SourceMgr.SetPreambleFileID(Decomposed.first); |
| 2258 | } |
| 2259 | } |
| 2260 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2261 | return Success; |
| 2262 | } |
| 2263 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2264 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2265 | ASTFileType Type) { |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2266 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2267 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2268 | PerFileData &F = *Chain.back(); |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2269 | if (Prev) |
| 2270 | Prev->NextInSource = &F; |
| 2271 | else |
| 2272 | FirstInSource = &F; |
| 2273 | F.Loaders.push_back(Prev); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2274 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2275 | // Set the AST file name. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2276 | F.FileName = FileName; |
| 2277 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2278 | // Open the AST file. |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2279 | // |
| 2280 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2281 | std::string ErrStr; |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 2282 | llvm::error_code ec; |
| 2283 | if (FileName == "-") { |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 2284 | ec = llvm::MemoryBuffer::getSTDIN(F.Buffer); |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 2285 | if (ec) |
| 2286 | ErrStr = ec.message(); |
| 2287 | } else |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2288 | F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr)); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2289 | if (!F.Buffer) { |
| 2290 | Error(ErrStr.c_str()); |
| 2291 | return IgnorePCH; |
| 2292 | } |
| 2293 | |
| 2294 | // Initialize the stream |
| 2295 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2296 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2297 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2298 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2299 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2300 | |
| 2301 | // Sniff for the signature. |
| 2302 | if (Stream.Read(8) != 'C' || |
| 2303 | Stream.Read(8) != 'P' || |
| 2304 | Stream.Read(8) != 'C' || |
| 2305 | Stream.Read(8) != 'H') { |
| 2306 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2307 | return Failure; |
| 2308 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2309 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2310 | while (!Stream.AtEndOfStream()) { |
| 2311 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2312 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2313 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2314 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2315 | return Failure; |
| 2316 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2317 | |
| 2318 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2319 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2320 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2321 | switch (BlockID) { |
| 2322 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2323 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2324 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2325 | return Failure; |
| 2326 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2327 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2328 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2329 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2330 | case Success: |
| 2331 | break; |
| 2332 | |
| 2333 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2334 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2335 | |
| 2336 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2337 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2338 | // AST block, skipping subblocks, to see if there are other |
| 2339 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2340 | |
| 2341 | // Clear out any preallocated source location entries, so that |
| 2342 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2343 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2344 | |
| 2345 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2346 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2347 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2348 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2349 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2350 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2351 | break; |
| 2352 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2353 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2354 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2355 | return Failure; |
| 2356 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2357 | break; |
| 2358 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2359 | } |
| 2360 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2361 | return Success; |
| 2362 | } |
| 2363 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2364 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2365 | PP = &pp; |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2366 | |
| 2367 | unsigned TotalNum = 0; |
| 2368 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2369 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2370 | if (TotalNum) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2371 | if (!PP->getPreprocessingRecord()) |
| 2372 | PP->createPreprocessingRecord(); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2373 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2374 | } |
| 2375 | } |
| 2376 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2377 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2378 | Context = &Ctx; |
| 2379 | assert(Context && "Passed null context!"); |
| 2380 | |
| 2381 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2382 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2383 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2384 | PP->setExternalSource(this); |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2385 | |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2386 | // If we have an update block for the TU waiting, we have to add it before |
| 2387 | // deserializing the decl. |
| 2388 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2389 | if (DCU != DeclContextOffsets.end()) { |
| 2390 | // Insertion could invalidate map, so grab vector. |
| 2391 | DeclContextInfos T; |
| 2392 | T.swap(DCU->second); |
| 2393 | DeclContextOffsets.erase(DCU); |
| 2394 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2395 | } |
| 2396 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2397 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2398 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2399 | |
| 2400 | // Load the special types. |
| 2401 | Context->setBuiltinVaListType( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2402 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2403 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2404 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2405 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2406 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2407 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2408 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2409 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2410 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2411 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2412 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2413 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2414 | if (unsigned FastEnum |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2415 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2416 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2417 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2418 | QualType FileType = GetType(File); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2419 | if (FileType.isNull()) { |
| 2420 | Error("FILE type is NULL"); |
| 2421 | return; |
| 2422 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2423 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2424 | Context->setFILEDecl(Typedef->getDecl()); |
| 2425 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2426 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2427 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2428 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2429 | return; |
| 2430 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2431 | Context->setFILEDecl(Tag->getDecl()); |
| 2432 | } |
| 2433 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2434 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2435 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2436 | if (Jmp_bufType.isNull()) { |
| 2437 | Error("jmp_bug type is NULL"); |
| 2438 | return; |
| 2439 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2440 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2441 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2442 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2443 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2444 | if (!Tag) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2445 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2446 | return; |
| 2447 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2448 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2449 | } |
| 2450 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2451 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2452 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2453 | if (Sigjmp_bufType.isNull()) { |
| 2454 | Error("sigjmp_buf type is NULL"); |
| 2455 | return; |
| 2456 | } |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2457 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2458 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2459 | else { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2460 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2461 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2462 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2463 | } |
| 2464 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2465 | if (unsigned ObjCIdRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2466 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2467 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2468 | if (unsigned ObjCClassRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2469 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2470 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2471 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2472 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2473 | if (unsigned String |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2474 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2475 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2476 | if (unsigned ObjCSelRedef |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2477 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2478 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2479 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2480 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2481 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2482 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2483 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2484 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2485 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2486 | } |
| 2487 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2488 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2489 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2490 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2491 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2492 | FileManager &FileMgr, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2493 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2494 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2495 | std::string ErrStr; |
| 2496 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2497 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2498 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2499 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2500 | return std::string(); |
| 2501 | } |
| 2502 | |
| 2503 | // Initialize the stream |
| 2504 | llvm::BitstreamReader StreamFile; |
| 2505 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2506 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2507 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2508 | Stream.init(StreamFile); |
| 2509 | |
| 2510 | // Sniff for the signature. |
| 2511 | if (Stream.Read(8) != 'C' || |
| 2512 | Stream.Read(8) != 'P' || |
| 2513 | Stream.Read(8) != 'C' || |
| 2514 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2515 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2516 | return std::string(); |
| 2517 | } |
| 2518 | |
| 2519 | RecordData Record; |
| 2520 | while (!Stream.AtEndOfStream()) { |
| 2521 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2522 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2523 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2524 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2525 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2526 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2527 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2528 | case AST_BLOCK_ID: |
| 2529 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2530 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2531 | return std::string(); |
| 2532 | } |
| 2533 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2534 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2535 | default: |
| 2536 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2537 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2538 | return std::string(); |
| 2539 | } |
| 2540 | break; |
| 2541 | } |
| 2542 | continue; |
| 2543 | } |
| 2544 | |
| 2545 | if (Code == llvm::bitc::END_BLOCK) { |
| 2546 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2547 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2548 | return std::string(); |
| 2549 | } |
| 2550 | continue; |
| 2551 | } |
| 2552 | |
| 2553 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2554 | Stream.ReadAbbrevRecord(); |
| 2555 | continue; |
| 2556 | } |
| 2557 | |
| 2558 | Record.clear(); |
| 2559 | const char *BlobStart = 0; |
| 2560 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2561 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2562 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2563 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2564 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2565 | |
| 2566 | return std::string(); |
| 2567 | } |
| 2568 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2569 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2570 | /// structure. |
| 2571 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2572 | /// This routine parses the language options from the AST file and then gives |
| 2573 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2574 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2575 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2576 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2577 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2578 | if (Listener) { |
| 2579 | LangOptions LangOpts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2580 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2581 | #define PARSE_LANGOPT(Option) \ |
| 2582 | LangOpts.Option = Record[Idx]; \ |
| 2583 | ++Idx |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2584 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2585 | unsigned Idx = 0; |
| 2586 | PARSE_LANGOPT(Trigraphs); |
| 2587 | PARSE_LANGOPT(BCPLComment); |
| 2588 | PARSE_LANGOPT(DollarIdents); |
| 2589 | PARSE_LANGOPT(AsmPreprocessor); |
| 2590 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2591 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2592 | PARSE_LANGOPT(ImplicitInt); |
| 2593 | PARSE_LANGOPT(Digraphs); |
| 2594 | PARSE_LANGOPT(HexFloats); |
| 2595 | PARSE_LANGOPT(C99); |
| 2596 | PARSE_LANGOPT(Microsoft); |
| 2597 | PARSE_LANGOPT(CPlusPlus); |
| 2598 | PARSE_LANGOPT(CPlusPlus0x); |
| 2599 | PARSE_LANGOPT(CXXOperatorNames); |
| 2600 | PARSE_LANGOPT(ObjC1); |
| 2601 | PARSE_LANGOPT(ObjC2); |
| 2602 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 2603 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 2604 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 2605 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 2606 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2607 | PARSE_LANGOPT(PascalStrings); |
| 2608 | PARSE_LANGOPT(WritableStrings); |
| 2609 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2610 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2611 | PARSE_LANGOPT(Exceptions); |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 2612 | PARSE_LANGOPT(SjLjExceptions); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2613 | PARSE_LANGOPT(NeXTRuntime); |
| 2614 | PARSE_LANGOPT(Freestanding); |
| 2615 | PARSE_LANGOPT(NoBuiltin); |
| 2616 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 2617 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2618 | PARSE_LANGOPT(Blocks); |
| 2619 | PARSE_LANGOPT(EmitAllDecls); |
| 2620 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2621 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 2622 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2623 | PARSE_LANGOPT(HeinousExtensions); |
| 2624 | PARSE_LANGOPT(Optimize); |
| 2625 | PARSE_LANGOPT(OptimizeSize); |
| 2626 | PARSE_LANGOPT(Static); |
| 2627 | PARSE_LANGOPT(PICLevel); |
| 2628 | PARSE_LANGOPT(GNUInline); |
| 2629 | PARSE_LANGOPT(NoInline); |
| 2630 | PARSE_LANGOPT(AccessControl); |
| 2631 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2632 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | b1bdced | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 2633 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2634 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2635 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 2636 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2637 | Record[Idx++]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2638 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2639 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 2640 | PARSE_LANGOPT(CUDA); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2641 | PARSE_LANGOPT(CatchUndefined); |
| 2642 | // FIXME: Missing ElideConstructors?! |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2643 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2644 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2645 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2646 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2647 | |
| 2648 | return false; |
| 2649 | } |
| 2650 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2651 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2652 | ReadDefinedMacros(); |
| 2653 | } |
| 2654 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2655 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(uint64_t Offset) { |
| 2656 | PerFileData *F = 0; |
| 2657 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2658 | if (Offset < Chain[I]->SizeInBits) { |
| 2659 | F = Chain[I]; |
| 2660 | break; |
| 2661 | } |
| 2662 | |
| 2663 | Offset -= Chain[I]->SizeInBits; |
| 2664 | } |
| 2665 | |
| 2666 | if (!F) { |
| 2667 | Error("Malformed preprocessed entity offset"); |
| 2668 | return 0; |
| 2669 | } |
| 2670 | |
| 2671 | return ReadMacroRecord(*F, Offset); |
| 2672 | } |
| 2673 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2674 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2675 | unsigned Idx = 0; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2676 | while (Idx < PragmaDiagMappings.size()) { |
| 2677 | SourceLocation |
| 2678 | Loc = SourceLocation::getFromRawEncoding(PragmaDiagMappings[Idx++]); |
| 2679 | while (1) { |
| 2680 | assert(Idx < PragmaDiagMappings.size() && |
| 2681 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 2682 | if (Idx >= PragmaDiagMappings.size()) |
| 2683 | break; // Something is messed up but at least avoid infinite loop in |
| 2684 | // release build. |
| 2685 | unsigned DiagID = PragmaDiagMappings[Idx++]; |
| 2686 | if (DiagID == (unsigned)-1) |
| 2687 | break; // no more diag/map pairs for this location. |
| 2688 | diag::Mapping Map = (diag::Mapping)PragmaDiagMappings[Idx++]; |
| 2689 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 2690 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2691 | } |
| 2692 | } |
| 2693 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2694 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2695 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2696 | PerFileData *F = 0; |
| 2697 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2698 | F = Chain[N - I - 1]; |
| 2699 | if (Index < F->LocalNumTypes) |
| 2700 | break; |
| 2701 | Index -= F->LocalNumTypes; |
| 2702 | } |
| 2703 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2704 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2708 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2709 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 2710 | /// routine actually reads the record corresponding to the type at the given |
| 2711 | /// location. It is a helper routine for GetType, which deals with reading type |
| 2712 | /// IDs. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2713 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2714 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2715 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2716 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2717 | // Keep track of where we are in the stream, then jump back there |
| 2718 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2719 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2720 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 2721 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 2722 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2723 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 2724 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2725 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2726 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2727 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2728 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2729 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 2730 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2731 | if (Record.size() != 2) { |
| 2732 | Error("Incorrect encoding of extended qualifier type"); |
| 2733 | return QualType(); |
| 2734 | } |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2735 | QualType Base = GetType(Record[0]); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2736 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 2737 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2738 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2739 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2740 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2741 | if (Record.size() != 1) { |
| 2742 | Error("Incorrect encoding of complex type"); |
| 2743 | return QualType(); |
| 2744 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2745 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2746 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2747 | } |
| 2748 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2749 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2750 | if (Record.size() != 1) { |
| 2751 | Error("Incorrect encoding of pointer type"); |
| 2752 | return QualType(); |
| 2753 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2754 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2755 | return Context->getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2756 | } |
| 2757 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2758 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2759 | if (Record.size() != 1) { |
| 2760 | Error("Incorrect encoding of block pointer type"); |
| 2761 | return QualType(); |
| 2762 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2763 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2764 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2765 | } |
| 2766 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2767 | case TYPE_LVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2768 | if (Record.size() != 1) { |
| 2769 | Error("Incorrect encoding of lvalue reference type"); |
| 2770 | return QualType(); |
| 2771 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2772 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2773 | return Context->getLValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2774 | } |
| 2775 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2776 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2777 | if (Record.size() != 1) { |
| 2778 | Error("Incorrect encoding of rvalue reference type"); |
| 2779 | return QualType(); |
| 2780 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2781 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2782 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2783 | } |
| 2784 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2785 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 2786 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2787 | Error("Incorrect encoding of member pointer type"); |
| 2788 | return QualType(); |
| 2789 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2790 | QualType PointeeType = GetType(Record[0]); |
| 2791 | QualType ClassType = GetType(Record[1]); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 2792 | if (PointeeType.isNull() || ClassType.isNull()) |
| 2793 | return QualType(); |
| 2794 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2795 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2796 | } |
| 2797 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2798 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2799 | QualType ElementType = GetType(Record[0]); |
| 2800 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2801 | unsigned IndexTypeQuals = Record[2]; |
| 2802 | unsigned Idx = 3; |
| 2803 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 2804 | return Context->getConstantArrayType(ElementType, Size, |
| 2805 | ASM, IndexTypeQuals); |
| 2806 | } |
| 2807 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2808 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2809 | QualType ElementType = GetType(Record[0]); |
| 2810 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2811 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2812 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2813 | } |
| 2814 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2815 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2816 | QualType ElementType = GetType(Record[0]); |
| 2817 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2818 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2819 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 2820 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 2821 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 2822 | ASM, IndexTypeQuals, |
| 2823 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2824 | } |
| 2825 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2826 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2827 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2828 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2829 | return QualType(); |
| 2830 | } |
| 2831 | |
| 2832 | QualType ElementType = GetType(Record[0]); |
| 2833 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 2834 | unsigned VecKind = Record[2]; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2835 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 2836 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2839 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2840 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2841 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2842 | return QualType(); |
| 2843 | } |
| 2844 | |
| 2845 | QualType ElementType = GetType(Record[0]); |
| 2846 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2847 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2848 | } |
| 2849 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2850 | case TYPE_FUNCTION_NO_PROTO: { |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2851 | if (Record.size() != 4) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 2852 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2853 | return QualType(); |
| 2854 | } |
| 2855 | QualType ResultType = GetType(Record[0]); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2856 | FunctionType::ExtInfo Info(Record[1], Record[2], (CallingConv)Record[3]); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 2857 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2858 | } |
| 2859 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2860 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2861 | QualType ResultType = GetType(Record[0]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 2862 | |
| 2863 | FunctionProtoType::ExtProtoInfo EPI; |
| 2864 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
| 2865 | /*regparm*/ Record[2], |
| 2866 | static_cast<CallingConv>(Record[3])); |
| 2867 | |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2868 | unsigned Idx = 4; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2869 | unsigned NumParams = Record[Idx++]; |
| 2870 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 2871 | for (unsigned I = 0; I != NumParams; ++I) |
| 2872 | ParamTypes.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 2873 | |
| 2874 | EPI.Variadic = Record[Idx++]; |
| 2875 | EPI.TypeQuals = Record[Idx++]; |
| 2876 | EPI.HasExceptionSpec = Record[Idx++]; |
| 2877 | EPI.HasAnyExceptionSpec = Record[Idx++]; |
| 2878 | EPI.NumExceptions = Record[Idx++]; |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 2879 | llvm::SmallVector<QualType, 2> Exceptions; |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 2880 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 2881 | Exceptions.push_back(GetType(Record[Idx++])); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 2882 | EPI.Exceptions = Exceptions.data(); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 2883 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 2884 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2885 | } |
| 2886 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2887 | case TYPE_UNRESOLVED_USING: |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2888 | return Context->getTypeDeclType( |
| 2889 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 2890 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2891 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2892 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2893 | Error("incorrect encoding of typedef type"); |
| 2894 | return QualType(); |
| 2895 | } |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2896 | TypedefDecl *Decl = cast<TypedefDecl>(GetDecl(Record[0])); |
| 2897 | QualType Canonical = GetType(Record[1]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 2898 | if (!Canonical.isNull()) |
| 2899 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2900 | return Context->getTypedefType(Decl, Canonical); |
| 2901 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2902 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2903 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2904 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2905 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2906 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2907 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2908 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2909 | return QualType(); |
| 2910 | } |
| 2911 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2912 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2913 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2914 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2915 | case TYPE_DECLTYPE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2916 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 2917 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2918 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2919 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2920 | Error("incorrect encoding of record type"); |
| 2921 | return QualType(); |
| 2922 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2923 | bool IsDependent = Record[0]; |
| 2924 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame^] | 2925 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2926 | return T; |
| 2927 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2928 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2929 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2930 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2931 | Error("incorrect encoding of enum type"); |
| 2932 | return QualType(); |
| 2933 | } |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2934 | bool IsDependent = Record[0]; |
| 2935 | QualType T = Context->getEnumType(cast<EnumDecl>(GetDecl(Record[1]))); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame^] | 2936 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2937 | return T; |
| 2938 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2939 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 2940 | case TYPE_ATTRIBUTED: { |
| 2941 | if (Record.size() != 3) { |
| 2942 | Error("incorrect encoding of attributed type"); |
| 2943 | return QualType(); |
| 2944 | } |
| 2945 | QualType modifiedType = GetType(Record[0]); |
| 2946 | QualType equivalentType = GetType(Record[1]); |
| 2947 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 2948 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 2949 | } |
| 2950 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 2951 | case TYPE_PAREN: { |
| 2952 | if (Record.size() != 1) { |
| 2953 | Error("incorrect encoding of paren type"); |
| 2954 | return QualType(); |
| 2955 | } |
| 2956 | QualType InnerType = GetType(Record[0]); |
| 2957 | return Context->getParenType(InnerType); |
| 2958 | } |
| 2959 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 2960 | case TYPE_PACK_EXPANSION: { |
| 2961 | if (Record.size() != 1) { |
| 2962 | Error("incorrect encoding of pack expansion type"); |
| 2963 | return QualType(); |
| 2964 | } |
| 2965 | QualType Pattern = GetType(Record[0]); |
| 2966 | if (Pattern.isNull()) |
| 2967 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2968 | llvm::Optional<unsigned> NumExpansions; |
| 2969 | if (Record[1]) |
| 2970 | NumExpansions = Record[1] - 1; |
| 2971 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 2972 | } |
| 2973 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2974 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 2975 | unsigned Idx = 0; |
| 2976 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 2977 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 2978 | QualType NamedType = GetType(Record[Idx++]); |
| 2979 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2980 | } |
| 2981 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2982 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2983 | unsigned Idx = 0; |
| 2984 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2985 | return Context->getObjCInterfaceType(ItfD); |
| 2986 | } |
| 2987 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2988 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2989 | unsigned Idx = 0; |
| 2990 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2991 | unsigned NumProtos = Record[Idx++]; |
| 2992 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 2993 | for (unsigned I = 0; I != NumProtos; ++I) |
| 2994 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2995 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2996 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2997 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2998 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 2999 | unsigned Idx = 0; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3000 | QualType Pointee = GetType(Record[Idx++]); |
| 3001 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3002 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3003 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3004 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3005 | unsigned Idx = 0; |
| 3006 | QualType Parm = GetType(Record[Idx++]); |
| 3007 | QualType Replacement = GetType(Record[Idx++]); |
| 3008 | return |
| 3009 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3010 | Replacement); |
| 3011 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3012 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3013 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3014 | unsigned Idx = 0; |
| 3015 | QualType Parm = GetType(Record[Idx++]); |
| 3016 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3017 | return Context->getSubstTemplateTypeParmPackType( |
| 3018 | cast<TemplateTypeParmType>(Parm), |
| 3019 | ArgPack); |
| 3020 | } |
| 3021 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3022 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3023 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 3024 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3025 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3026 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3027 | return |
| 3028 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3029 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3030 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3031 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3032 | unsigned Idx = 0; |
| 3033 | unsigned Depth = Record[Idx++]; |
| 3034 | unsigned Index = Record[Idx++]; |
| 3035 | bool Pack = Record[Idx++]; |
| 3036 | IdentifierInfo *Name = GetIdentifierInfo(Record, Idx); |
| 3037 | return Context->getTemplateTypeParmType(Depth, Index, Pack, Name); |
| 3038 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3039 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3040 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3041 | unsigned Idx = 0; |
| 3042 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3043 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3044 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3045 | QualType Canon = GetType(Record[Idx++]); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3046 | if (!Canon.isNull()) |
| 3047 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3048 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3049 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3050 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3051 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3052 | unsigned Idx = 0; |
| 3053 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 3054 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3055 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
| 3056 | unsigned NumArgs = Record[Idx++]; |
| 3057 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 3058 | Args.reserve(NumArgs); |
| 3059 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3060 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3061 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3062 | Args.size(), Args.data()); |
| 3063 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3064 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3065 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3066 | unsigned Idx = 0; |
| 3067 | |
| 3068 | // ArrayType |
| 3069 | QualType ElementType = GetType(Record[Idx++]); |
| 3070 | ArrayType::ArraySizeModifier ASM |
| 3071 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3072 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3073 | |
| 3074 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3075 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3076 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3077 | |
| 3078 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3079 | IndexTypeQuals, Brackets); |
| 3080 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3081 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3082 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3083 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3084 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3085 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3086 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3087 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3088 | QualType Canon = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3089 | QualType T; |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3090 | if (Canon.isNull()) |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3091 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3092 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3093 | else |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3094 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
| 3095 | Args.size(), Canon); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame^] | 3096 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3097 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3098 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3099 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3100 | // Suppress a GCC warning |
| 3101 | return QualType(); |
| 3102 | } |
| 3103 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3104 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3105 | ASTReader &Reader; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3106 | ASTReader::PerFileData &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3107 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3108 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3109 | unsigned &Idx; |
| 3110 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3111 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3112 | unsigned &I) { |
| 3113 | return Reader.ReadSourceLocation(F, R, I); |
| 3114 | } |
| 3115 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3116 | public: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3117 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3118 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3119 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3120 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3121 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3122 | // We want compile-time assurance that we've enumerated all of |
| 3123 | // these, so unfortunately we have to declare them first, then |
| 3124 | // define them out-of-line. |
| 3125 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3126 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3127 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3128 | #include "clang/AST/TypeLocNodes.def" |
| 3129 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3130 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3131 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3132 | }; |
| 3133 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3134 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3135 | // nothing to do |
| 3136 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3137 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3138 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3139 | if (TL.needsExtraLocalData()) { |
| 3140 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3141 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3142 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3143 | TL.setModeAttr(Record[Idx++]); |
| 3144 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3145 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3146 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3147 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3148 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3149 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3150 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3151 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3152 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3153 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3154 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3155 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3156 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3157 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3158 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3159 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3160 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3161 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3162 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3163 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3164 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3165 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3166 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3167 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3168 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3169 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3170 | TL.setSizeExpr(0); |
| 3171 | } |
| 3172 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3173 | VisitArrayTypeLoc(TL); |
| 3174 | } |
| 3175 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3176 | VisitArrayTypeLoc(TL); |
| 3177 | } |
| 3178 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3179 | VisitArrayTypeLoc(TL); |
| 3180 | } |
| 3181 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3182 | DependentSizedArrayTypeLoc TL) { |
| 3183 | VisitArrayTypeLoc(TL); |
| 3184 | } |
| 3185 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3186 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3187 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3188 | } |
| 3189 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3190 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3191 | } |
| 3192 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3193 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3194 | } |
| 3195 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3196 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3197 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3198 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3199 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | 86acc2a | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 3200 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3201 | } |
| 3202 | } |
| 3203 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3204 | VisitFunctionTypeLoc(TL); |
| 3205 | } |
| 3206 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3207 | VisitFunctionTypeLoc(TL); |
| 3208 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3209 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3210 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3211 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3212 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3213 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3214 | } |
| 3215 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3216 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3217 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3218 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3219 | } |
| 3220 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3221 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3222 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3223 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3224 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3225 | } |
| 3226 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3227 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3228 | } |
| 3229 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3230 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3231 | } |
| 3232 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3233 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3234 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3235 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3236 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3237 | if (TL.hasAttrOperand()) { |
| 3238 | SourceRange range; |
| 3239 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3240 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3241 | TL.setAttrOperandParensRange(range); |
| 3242 | } |
| 3243 | if (TL.hasAttrExprOperand()) { |
| 3244 | if (Record[Idx++]) |
| 3245 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3246 | else |
| 3247 | TL.setAttrExprOperand(0); |
| 3248 | } else if (TL.hasAttrEnumOperand()) |
| 3249 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3250 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3251 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3252 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3253 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3254 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3255 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3256 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3257 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3258 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3259 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3260 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3261 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3262 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3263 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3264 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3265 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3266 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3267 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3268 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3269 | Reader.GetTemplateArgumentLocInfo(F, |
| 3270 | TL.getTypePtr()->getArg(i).getKind(), |
| 3271 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3272 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3273 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3274 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3275 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3276 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3277 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3278 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3279 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3280 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3281 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3282 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3283 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3284 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3285 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3286 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3287 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3288 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3289 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3290 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3291 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3292 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3293 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3294 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3295 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3296 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3297 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3298 | Reader.GetTemplateArgumentLocInfo(F, |
| 3299 | TL.getTypePtr()->getArg(I).getKind(), |
| 3300 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3301 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3302 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3303 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3304 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3305 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3306 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3307 | } |
| 3308 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3309 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3310 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3311 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3312 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3313 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3314 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3315 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3316 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3317 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3318 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3319 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3320 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3321 | unsigned &Idx) { |
| 3322 | QualType InfoTy = GetType(Record[Idx++]); |
| 3323 | if (InfoTy.isNull()) |
| 3324 | return 0; |
| 3325 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3326 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3327 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3328 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3329 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3330 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3331 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3332 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3333 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3334 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3335 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3336 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3337 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3338 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3339 | switch ((PredefinedTypeIDs)Index) { |
| 3340 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3341 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3342 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3343 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3344 | case PREDEF_TYPE_CHAR_U_ID: |
| 3345 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3346 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3347 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3348 | break; |
| 3349 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3350 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3351 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3352 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3353 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3354 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3355 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3356 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3357 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3358 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3359 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3360 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3361 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3362 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3363 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3364 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3365 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3366 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
| 3367 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
| 3368 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3369 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3370 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3371 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3372 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3373 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3377 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3378 | } |
| 3379 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3380 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3381 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3382 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3383 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3384 | if (TypesLoaded[Index].isNull()) |
| 3385 | return QualType(); |
| 3386 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3387 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3388 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3389 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3390 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3391 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3392 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3393 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3394 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3395 | } |
| 3396 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3397 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3398 | return MakeTypeID(T, |
| 3399 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3400 | } |
| 3401 | |
| 3402 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3403 | if (T.isNull()) |
| 3404 | return TypeIdx(); |
| 3405 | assert(!T.getLocalFastQualifiers()); |
| 3406 | |
| 3407 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3408 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3409 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3410 | // If the type didn't come from the AST file use a specially marked index |
| 3411 | // so that any hash/key comparison fail since no such index is stored |
| 3412 | // in a AST file. |
| 3413 | if (I == TypeIdxs.end()) |
| 3414 | return TypeIdx(-1); |
| 3415 | return I->second; |
| 3416 | } |
| 3417 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3418 | unsigned ASTReader::getTotalNumCXXBaseSpecifiers() const { |
| 3419 | unsigned Result = 0; |
| 3420 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 3421 | Result += Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3422 | |
| 3423 | return Result; |
| 3424 | } |
| 3425 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3426 | TemplateArgumentLocInfo |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3427 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3428 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3429 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3430 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3431 | switch (Kind) { |
| 3432 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3433 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3434 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3435 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3436 | case TemplateArgument::Template: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3437 | SourceRange QualifierRange = ReadSourceRange(F, Record, Index); |
| 3438 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3439 | return TemplateArgumentLocInfo(QualifierRange, TemplateNameLoc, |
| 3440 | SourceLocation()); |
| 3441 | } |
| 3442 | case TemplateArgument::TemplateExpansion: { |
| 3443 | SourceRange QualifierRange = ReadSourceRange(F, Record, Index); |
| 3444 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3445 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
| 3446 | return TemplateArgumentLocInfo(QualifierRange, TemplateNameLoc, |
| 3447 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3448 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3449 | case TemplateArgument::Null: |
| 3450 | case TemplateArgument::Integral: |
| 3451 | case TemplateArgument::Declaration: |
| 3452 | case TemplateArgument::Pack: |
| 3453 | return TemplateArgumentLocInfo(); |
| 3454 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3455 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3456 | return TemplateArgumentLocInfo(); |
| 3457 | } |
| 3458 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3459 | TemplateArgumentLoc |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3460 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3461 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3462 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3463 | |
| 3464 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3465 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3466 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3467 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3468 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3469 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3470 | } |
| 3471 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3472 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3473 | return GetDecl(ID); |
| 3474 | } |
| 3475 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3476 | uint64_t |
| 3477 | ASTReader::GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID) { |
| 3478 | if (ID == 0) |
| 3479 | return 0; |
| 3480 | |
| 3481 | --ID; |
| 3482 | uint64_t Offset = 0; |
| 3483 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3484 | if (ID < Chain[I]->LocalNumCXXBaseSpecifiers) |
| 3485 | return Offset + Chain[I]->CXXBaseSpecifiersOffsets[ID]; |
| 3486 | |
| 3487 | ID -= Chain[I]->LocalNumCXXBaseSpecifiers; |
| 3488 | Offset += Chain[I]->SizeInBits; |
| 3489 | } |
| 3490 | |
| 3491 | assert(false && "CXXBaseSpecifiers not found"); |
| 3492 | return 0; |
| 3493 | } |
| 3494 | |
| 3495 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 3496 | // Figure out which AST file contains this offset. |
| 3497 | PerFileData *F = 0; |
| 3498 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3499 | if (Offset < Chain[I]->SizeInBits) { |
| 3500 | F = Chain[I]; |
| 3501 | break; |
| 3502 | } |
| 3503 | |
| 3504 | Offset -= Chain[I]->SizeInBits; |
| 3505 | } |
| 3506 | |
| 3507 | if (!F) { |
| 3508 | Error("Malformed AST file: C++ base specifiers at impossible offset"); |
| 3509 | return 0; |
| 3510 | } |
| 3511 | |
| 3512 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3513 | SavedStreamPosition SavedPosition(Cursor); |
| 3514 | Cursor.JumpToBit(Offset); |
| 3515 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3516 | RecordData Record; |
| 3517 | unsigned Code = Cursor.ReadCode(); |
| 3518 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 3519 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 3520 | Error("Malformed AST file: missing C++ base specifiers"); |
| 3521 | return 0; |
| 3522 | } |
| 3523 | |
| 3524 | unsigned Idx = 0; |
| 3525 | unsigned NumBases = Record[Idx++]; |
| 3526 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 3527 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 3528 | for (unsigned I = 0; I != NumBases; ++I) |
| 3529 | Bases[I] = ReadCXXBaseSpecifier(*F, Record, Idx); |
| 3530 | return Bases; |
| 3531 | } |
| 3532 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3533 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3534 | if (!DeclsLoaded[0]) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 3535 | ReadDeclRecord(0, 1); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3536 | if (DeserializationListener) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3537 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3538 | } |
Argyrios Kyrtzidis | 8871a44 | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 3539 | |
| 3540 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 3541 | } |
| 3542 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3543 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3544 | if (ID == 0) |
| 3545 | return 0; |
| 3546 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3547 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3548 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3549 | return 0; |
| 3550 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3551 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3552 | unsigned Index = ID - 1; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3553 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3554 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3555 | if (DeserializationListener) |
| 3556 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3557 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3558 | |
| 3559 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3560 | } |
| 3561 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3562 | /// \brief Resolve the offset of a statement into a statement. |
| 3563 | /// |
| 3564 | /// This operation will read a new statement from the external |
| 3565 | /// source each time it is called, and is meant to be used via a |
| 3566 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3567 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 3568 | // Switch case IDs are per Decl. |
| 3569 | ClearSwitchCaseIDs(); |
| 3570 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3571 | // Offset here is a global offset across the entire chain. |
| 3572 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3573 | PerFileData &F = *Chain[N - I - 1]; |
| 3574 | if (Offset < F.SizeInBits) { |
| 3575 | // Since we know that this statement is part of a decl, make sure to use |
| 3576 | // the decl cursor to read it. |
| 3577 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3578 | return ReadStmtFromStream(F); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3579 | } |
| 3580 | Offset -= F.SizeInBits; |
| 3581 | } |
| 3582 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 3583 | } |
| 3584 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3585 | bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3586 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3587 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3588 | assert(DC->hasExternalLexicalStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3589 | "DeclContext has no lexical decls in storage"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3590 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3591 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 3592 | // at least. |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3593 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 3594 | // so make a copy of the vector. |
| 3595 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3596 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3597 | I != E; ++I) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3598 | // IDs can be 0 if this context doesn't contain declarations. |
| 3599 | if (!I->LexicalDecls) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3600 | continue; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3601 | |
| 3602 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3603 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 3604 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 3605 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 3606 | continue; |
| 3607 | |
| 3608 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | 4a9eb26 | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3609 | assert(D && "Null decl in lexical decls"); |
| 3610 | Decls.push_back(D); |
| 3611 | } |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3612 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3613 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3614 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3615 | return false; |
| 3616 | } |
| 3617 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3618 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3619 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3620 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3621 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3622 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3623 | if (!Name) |
| 3624 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 3625 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3626 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3627 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 8b12273 | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 3628 | // 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] | 3629 | // and namespaces. For any given name, the last available results replace |
| 3630 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3631 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3632 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3633 | I != E; ++I) { |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3634 | if (!I->NameLookupTableData) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3635 | continue; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3636 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3637 | ASTDeclContextNameLookupTable *LookupTable = |
| 3638 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3639 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 3640 | if (Pos == LookupTable->end()) |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3641 | continue; |
| 3642 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3643 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 3644 | for (; Data.first != Data.second; ++Data.first) |
| 3645 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3646 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3647 | } |
| 3648 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3649 | ++NumVisibleDeclContextsRead; |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3650 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3651 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3652 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3653 | } |
| 3654 | |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 3655 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 3656 | assert(DC->hasExternalVisibleStorage() && |
| 3657 | "DeclContext has no visible decls in storage"); |
| 3658 | |
| 3659 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 3660 | // There might be visible decls in multiple parts of the chain, for the TU |
| 3661 | // and namespaces. |
| 3662 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 3663 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3664 | I != E; ++I) { |
| 3665 | if (!I->NameLookupTableData) |
| 3666 | continue; |
| 3667 | |
| 3668 | ASTDeclContextNameLookupTable *LookupTable = |
| 3669 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3670 | for (ASTDeclContextNameLookupTable::item_iterator |
| 3671 | ItemI = LookupTable->item_begin(), |
| 3672 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 3673 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 3674 | = *ItemI; |
| 3675 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 3676 | Decls.clear(); |
| 3677 | for (; Data.first != Data.second; ++Data.first) |
| 3678 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 3679 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 3680 | } |
| 3681 | } |
| 3682 | } |
| 3683 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3684 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3685 | assert(Consumer); |
| 3686 | while (!InterestingDecls.empty()) { |
| 3687 | DeclGroupRef DG(InterestingDecls.front()); |
| 3688 | InterestingDecls.pop_front(); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3689 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3690 | } |
| 3691 | } |
| 3692 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3693 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 3694 | this->Consumer = Consumer; |
| 3695 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3696 | if (!Consumer) |
| 3697 | return; |
| 3698 | |
| 3699 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3700 | // Force deserialization of this decl, which will cause it to be queued for |
| 3701 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 3702 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3703 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 3704 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3705 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3706 | } |
| 3707 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3708 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3709 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3710 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3711 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3712 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3713 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3714 | unsigned NumDeclsLoaded |
| 3715 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 3716 | (Decl *)0); |
| 3717 | unsigned NumIdentifiersLoaded |
| 3718 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 3719 | IdentifiersLoaded.end(), |
| 3720 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3721 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3722 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 3723 | SelectorsLoaded.end(), |
| 3724 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 3725 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3726 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 3727 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 3728 | if (TotalNumSLocEntries) |
| 3729 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 3730 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 3731 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3732 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3733 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3734 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 3735 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 3736 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3737 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3738 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 3739 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3740 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3741 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3742 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 3743 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3744 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3745 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3746 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 3747 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3748 | if (TotalNumStatements) |
| 3749 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 3750 | NumStatementsRead, TotalNumStatements, |
| 3751 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 3752 | if (TotalNumMacros) |
| 3753 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 3754 | NumMacrosRead, TotalNumMacros, |
| 3755 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 3756 | if (TotalLexicalDeclContexts) |
| 3757 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 3758 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 3759 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 3760 | * 100)); |
| 3761 | if (TotalVisibleDeclContexts) |
| 3762 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 3763 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 3764 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 3765 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3766 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3767 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3768 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 3769 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3770 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3771 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3772 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3773 | std::fprintf(stderr, "\n"); |
| 3774 | } |
| 3775 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3776 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3777 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3778 | S.ExternalSource = this; |
| 3779 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 3780 | // Makes sure any declarations that were deserialized "too early" |
| 3781 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3782 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 3783 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 3784 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3785 | |
| 3786 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3787 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 3788 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3789 | |
| 3790 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 3791 | // them to Sema's list of tentative definitions. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3792 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 3793 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 3794 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3795 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 3796 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3797 | // If there were any unused file scoped decls, deserialize them and add to |
| 3798 | // Sema's list of unused file scoped decls. |
| 3799 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 3800 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 3801 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 3802 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3803 | |
| 3804 | // If there were any locally-scoped external declarations, |
| 3805 | // deserialize them and add them to Sema's table of locally-scoped |
| 3806 | // external declarations. |
| 3807 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 3808 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 3809 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 3810 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3811 | |
| 3812 | // If there were any ext_vector type declarations, deserialize them |
| 3813 | // and add them to Sema's vector of such declarations. |
| 3814 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 3815 | SemaObj->ExtVectorDecls.push_back( |
| 3816 | cast<TypedefDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3817 | |
| 3818 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 3819 | // Can we cut them down before writing them ? |
| 3820 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3821 | // If there were any dynamic classes declarations, deserialize them |
| 3822 | // and add them to Sema's vector of such declarations. |
| 3823 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 3824 | SemaObj->DynamicClasses.push_back( |
| 3825 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3826 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3827 | // Load the offsets of the declarations that Sema references. |
| 3828 | // They will be lazily deserialized when needed. |
| 3829 | if (!SemaDeclRefs.empty()) { |
| 3830 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 3831 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 3832 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 3833 | } |
| 3834 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3835 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 3836 | |
| 3837 | // If there are @selector references added them to its pool. This is for |
| 3838 | // implementation of -Wselector. |
| 3839 | if (!F->ReferencedSelectorsData.empty()) { |
| 3840 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 3841 | unsigned I = 0; |
| 3842 | while (I < DataSize) { |
| 3843 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 3844 | SourceLocation SelLoc = ReadSourceLocation( |
| 3845 | *F, F->ReferencedSelectorsData, I); |
| 3846 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 3847 | } |
| 3848 | } |
| 3849 | |
| 3850 | // If there were any pending implicit instantiations, deserialize them |
| 3851 | // and add them to Sema's queue of such instantiations. |
| 3852 | assert(F->PendingInstantiations.size() % 2 == 0 && |
| 3853 | "Expected pairs of entries"); |
| 3854 | for (unsigned Idx = 0, N = F->PendingInstantiations.size(); Idx < N;) { |
| 3855 | ValueDecl *D=cast<ValueDecl>(GetDecl(F->PendingInstantiations[Idx++])); |
| 3856 | SourceLocation Loc = ReadSourceLocation(*F, F->PendingInstantiations,Idx); |
| 3857 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 3858 | } |
| 3859 | } |
| 3860 | |
| 3861 | // The two special data sets below always come from the most recent PCH, |
| 3862 | // which is at the front of the chain. |
| 3863 | PerFileData &F = *Chain.front(); |
| 3864 | |
| 3865 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 3866 | // Sema's list of weak undeclared identifiers. |
| 3867 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 3868 | unsigned Idx = 0; |
| 3869 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 3870 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 3871 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 3872 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 3873 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 3874 | Sema::WeakInfo WI(AliasId, Loc); |
| 3875 | WI.setUsed(Used); |
| 3876 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 3877 | } |
| 3878 | } |
| 3879 | |
| 3880 | // If there were any VTable uses, deserialize the information and add it |
| 3881 | // to Sema's vector and map of VTable uses. |
| 3882 | if (!VTableUses.empty()) { |
| 3883 | unsigned Idx = 0; |
| 3884 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 3885 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 3886 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 3887 | bool DefinitionRequired = VTableUses[Idx++]; |
| 3888 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 3889 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3890 | } |
| 3891 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3892 | } |
| 3893 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3894 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3895 | // Try to find this name within our on-disk hash tables. We start with the |
| 3896 | // 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] | 3897 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3898 | ASTIdentifierLookupTable *IdTable |
| 3899 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3900 | if (!IdTable) |
| 3901 | continue; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3902 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3903 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3904 | if (Pos == IdTable->end()) |
| 3905 | continue; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3906 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3907 | // Dereferencing the iterator has the effect of building the |
| 3908 | // IdentifierInfo node and populating it with the various |
| 3909 | // declarations it needs. |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3910 | return *Pos; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3911 | } |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3912 | return 0; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3913 | } |
| 3914 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 3915 | namespace clang { |
| 3916 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 3917 | /// identifiers stored within a set of AST files. |
| 3918 | class ASTIdentifierIterator : public IdentifierIterator { |
| 3919 | /// \brief The AST reader whose identifiers are being enumerated. |
| 3920 | const ASTReader &Reader; |
| 3921 | |
| 3922 | /// \brief The current index into the chain of AST files stored in |
| 3923 | /// the AST reader. |
| 3924 | unsigned Index; |
| 3925 | |
| 3926 | /// \brief The current position within the identifier lookup table |
| 3927 | /// of the current AST file. |
| 3928 | ASTIdentifierLookupTable::key_iterator Current; |
| 3929 | |
| 3930 | /// \brief The end position within the identifier lookup table of |
| 3931 | /// the current AST file. |
| 3932 | ASTIdentifierLookupTable::key_iterator End; |
| 3933 | |
| 3934 | public: |
| 3935 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 3936 | |
| 3937 | virtual llvm::StringRef Next(); |
| 3938 | }; |
| 3939 | } |
| 3940 | |
| 3941 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 3942 | : Reader(Reader), Index(Reader.Chain.size() - 1) { |
| 3943 | ASTIdentifierLookupTable *IdTable |
| 3944 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 3945 | Current = IdTable->key_begin(); |
| 3946 | End = IdTable->key_end(); |
| 3947 | } |
| 3948 | |
| 3949 | llvm::StringRef ASTIdentifierIterator::Next() { |
| 3950 | while (Current == End) { |
| 3951 | // If we have exhausted all of our AST files, we're done. |
| 3952 | if (Index == 0) |
| 3953 | return llvm::StringRef(); |
| 3954 | |
| 3955 | --Index; |
| 3956 | ASTIdentifierLookupTable *IdTable |
| 3957 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 3958 | Current = IdTable->key_begin(); |
| 3959 | End = IdTable->key_end(); |
| 3960 | } |
| 3961 | |
| 3962 | // We have any identifiers remaining in the current AST file; return |
| 3963 | // the next one. |
| 3964 | std::pair<const char*, unsigned> Key = *Current; |
| 3965 | ++Current; |
| 3966 | return llvm::StringRef(Key.first, Key.second); |
| 3967 | } |
| 3968 | |
| 3969 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 3970 | return new ASTIdentifierIterator(*this); |
| 3971 | } |
| 3972 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3973 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3974 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3975 | // Find this selector in a hash table. We want to find the most recent entry. |
| 3976 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3977 | PerFileData &F = *Chain[I]; |
| 3978 | if (!F.SelectorLookupTable) |
| 3979 | continue; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3980 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3981 | ASTSelectorLookupTable *PoolTable |
| 3982 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 3983 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3984 | if (Pos != PoolTable->end()) { |
| 3985 | ++NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3986 | // FIXME: Not quite happy with the statistics here. We probably should |
| 3987 | // disable this tracking when called via LoadSelector. |
| 3988 | // Also, should entries without methods count as misses? |
| 3989 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3990 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3991 | if (DeserializationListener) |
| 3992 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 3993 | return std::make_pair(Data.Instance, Data.Factory); |
| 3994 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3995 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3996 | |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3997 | ++NumMethodPoolMisses; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3998 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3999 | } |
| 4000 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4001 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4002 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4003 | ReadMethodPool(Sel); |
| 4004 | } |
| 4005 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4006 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4007 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4008 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4009 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4010 | if (DeserializationListener) |
| 4011 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4012 | } |
| 4013 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4014 | /// \brief Set the globally-visible declarations associated with the given |
| 4015 | /// identifier. |
| 4016 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4017 | /// 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] | 4018 | /// 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] | 4019 | /// them. |
| 4020 | /// |
| 4021 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4022 | /// declarations. |
| 4023 | /// |
| 4024 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4025 | /// visible at global scope. |
| 4026 | /// |
| 4027 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4028 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4029 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4030 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4031 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4032 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 4033 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4034 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4035 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4036 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4037 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4038 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4039 | return; |
| 4040 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4041 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4042 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4043 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4044 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4045 | if (SemaObj->TUScope) { |
| 4046 | // Introduce this declaration into the translation-unit scope |
| 4047 | // and add it to the declaration chain for this identifier, so |
| 4048 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4049 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4050 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4051 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4052 | } else { |
| 4053 | // Queue this declaration so that it will be added to the |
| 4054 | // translation unit scope and identifier's declaration chain |
| 4055 | // once a Sema object is known. |
| 4056 | PreloadedDecls.push_back(D); |
| 4057 | } |
| 4058 | } |
| 4059 | } |
| 4060 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4061 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4062 | if (ID == 0) |
| 4063 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4064 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4065 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4066 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4067 | return 0; |
| 4068 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4069 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4070 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4071 | ID -= 1; |
| 4072 | if (!IdentifiersLoaded[ID]) { |
| 4073 | unsigned Index = ID; |
| 4074 | const char *Str = 0; |
| 4075 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4076 | PerFileData *F = Chain[N - I - 1]; |
| 4077 | if (Index < F->LocalNumIdentifiers) { |
| 4078 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 4079 | Str = F->IdentifierTableData + Offset; |
| 4080 | break; |
| 4081 | } |
| 4082 | Index -= F->LocalNumIdentifiers; |
| 4083 | } |
| 4084 | assert(Str && "Broken Chain"); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4085 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4086 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4087 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4088 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4089 | // unsigned integers. This is important to avoid integer overflow when |
| 4090 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4091 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4092 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4093 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4094 | IdentifiersLoaded[ID] |
Kovarththanan Rajaratnam | 811f426 | 2010-03-12 10:32:27 +0000 | [diff] [blame] | 4095 | = &PP->getIdentifierTable().get(Str, StrLen); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4096 | if (DeserializationListener) |
| 4097 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4098 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4099 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4100 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4101 | } |
| 4102 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4103 | void ASTReader::ReadSLocEntry(unsigned ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4104 | ReadSLocEntryRecord(ID); |
| 4105 | } |
| 4106 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4107 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4108 | if (ID == 0) |
| 4109 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4110 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4111 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4112 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4113 | return Selector(); |
| 4114 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4115 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4116 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4117 | // Load this selector from the selector table. |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4118 | unsigned Idx = ID - 1; |
| 4119 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 4120 | PerFileData &F = *Chain[N - I - 1]; |
| 4121 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4122 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4123 | SelectorsLoaded[ID - 1] = |
| 4124 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 4125 | if (DeserializationListener) |
| 4126 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 4127 | break; |
| 4128 | } |
| 4129 | Idx -= F.LocalNumSelectors; |
| 4130 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4131 | } |
| 4132 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4133 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4134 | } |
| 4135 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4136 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4137 | return DecodeSelector(ID); |
| 4138 | } |
| 4139 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4140 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4141 | // ID 0 (the null selector) is considered an external selector. |
| 4142 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4143 | } |
| 4144 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4145 | DeclarationName |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4146 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4147 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4148 | switch (Kind) { |
| 4149 | case DeclarationName::Identifier: |
| 4150 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 4151 | |
| 4152 | case DeclarationName::ObjCZeroArgSelector: |
| 4153 | case DeclarationName::ObjCOneArgSelector: |
| 4154 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 4155 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4156 | |
| 4157 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4158 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4159 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4160 | |
| 4161 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4162 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4163 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4164 | |
| 4165 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4166 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 4167 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4168 | |
| 4169 | case DeclarationName::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4170 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4171 | (OverloadedOperatorKind)Record[Idx++]); |
| 4172 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4173 | case DeclarationName::CXXLiteralOperatorName: |
| 4174 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 4175 | GetIdentifierInfo(Record, Idx)); |
| 4176 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4177 | case DeclarationName::CXXUsingDirective: |
| 4178 | return DeclarationName::getUsingDirectiveName(); |
| 4179 | } |
| 4180 | |
| 4181 | // Required to silence GCC warning |
| 4182 | return DeclarationName(); |
| 4183 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4184 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4185 | void ASTReader::ReadDeclarationNameLoc(PerFileData &F, |
| 4186 | DeclarationNameLoc &DNLoc, |
| 4187 | DeclarationName Name, |
| 4188 | const RecordData &Record, unsigned &Idx) { |
| 4189 | switch (Name.getNameKind()) { |
| 4190 | case DeclarationName::CXXConstructorName: |
| 4191 | case DeclarationName::CXXDestructorName: |
| 4192 | case DeclarationName::CXXConversionFunctionName: |
| 4193 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4194 | break; |
| 4195 | |
| 4196 | case DeclarationName::CXXOperatorName: |
| 4197 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4198 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4199 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4200 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4201 | break; |
| 4202 | |
| 4203 | case DeclarationName::CXXLiteralOperatorName: |
| 4204 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4205 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4206 | break; |
| 4207 | |
| 4208 | case DeclarationName::Identifier: |
| 4209 | case DeclarationName::ObjCZeroArgSelector: |
| 4210 | case DeclarationName::ObjCOneArgSelector: |
| 4211 | case DeclarationName::ObjCMultiArgSelector: |
| 4212 | case DeclarationName::CXXUsingDirective: |
| 4213 | break; |
| 4214 | } |
| 4215 | } |
| 4216 | |
| 4217 | void ASTReader::ReadDeclarationNameInfo(PerFileData &F, |
| 4218 | DeclarationNameInfo &NameInfo, |
| 4219 | const RecordData &Record, unsigned &Idx) { |
| 4220 | NameInfo.setName(ReadDeclarationName(Record, Idx)); |
| 4221 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4222 | DeclarationNameLoc DNLoc; |
| 4223 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4224 | NameInfo.setInfo(DNLoc); |
| 4225 | } |
| 4226 | |
| 4227 | void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info, |
| 4228 | const RecordData &Record, unsigned &Idx) { |
| 4229 | Info.NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4230 | Info.NNSRange = ReadSourceRange(F, Record, Idx); |
| 4231 | unsigned NumTPLists = Record[Idx++]; |
| 4232 | Info.NumTemplParamLists = NumTPLists; |
| 4233 | if (NumTPLists) { |
| 4234 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 4235 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4236 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4237 | } |
| 4238 | } |
| 4239 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4240 | TemplateName |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4241 | ASTReader::ReadTemplateName(PerFileData &F, const RecordData &Record, |
| 4242 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4243 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4244 | switch (Kind) { |
| 4245 | case TemplateName::Template: |
| 4246 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 4247 | |
| 4248 | case TemplateName::OverloadedTemplate: { |
| 4249 | unsigned size = Record[Idx++]; |
| 4250 | UnresolvedSet<8> Decls; |
| 4251 | while (size--) |
| 4252 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 4253 | |
| 4254 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 4255 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4256 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4257 | case TemplateName::QualifiedTemplate: { |
| 4258 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4259 | bool hasTemplKeyword = Record[Idx++]; |
| 4260 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 4261 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 4262 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4263 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4264 | case TemplateName::DependentTemplate: { |
| 4265 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 4266 | if (Record[Idx++]) // isIdentifier |
| 4267 | return Context->getDependentTemplateName(NNS, |
| 4268 | GetIdentifierInfo(Record, Idx)); |
| 4269 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4270 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4271 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4272 | |
| 4273 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4274 | TemplateTemplateParmDecl *Param |
| 4275 | = cast_or_null<TemplateTemplateParmDecl>(GetDecl(Record[Idx++])); |
| 4276 | if (!Param) |
| 4277 | return TemplateName(); |
| 4278 | |
| 4279 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 4280 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 4281 | return TemplateName(); |
| 4282 | |
| 4283 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 4284 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4285 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4286 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4287 | assert(0 && "Unhandled template name kind!"); |
| 4288 | return TemplateName(); |
| 4289 | } |
| 4290 | |
| 4291 | TemplateArgument |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4292 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4293 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4294 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 4295 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4296 | case TemplateArgument::Null: |
| 4297 | return TemplateArgument(); |
| 4298 | case TemplateArgument::Type: |
| 4299 | return TemplateArgument(GetType(Record[Idx++])); |
| 4300 | case TemplateArgument::Declaration: |
| 4301 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4302 | case TemplateArgument::Integral: { |
| 4303 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 4304 | QualType T = GetType(Record[Idx++]); |
| 4305 | return TemplateArgument(Value, T); |
| 4306 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4307 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4308 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4309 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4310 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4311 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 4312 | if (unsigned NumExpansions = Record[Idx++]) |
| 4313 | NumTemplateExpansions = NumExpansions - 1; |
| 4314 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4315 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4316 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4317 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4318 | case TemplateArgument::Pack: { |
| 4319 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4320 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 4321 | for (unsigned I = 0; I != NumArgs; ++I) |
| 4322 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 4323 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4324 | } |
| 4325 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4326 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4327 | assert(0 && "Unhandled template argument kind!"); |
| 4328 | return TemplateArgument(); |
| 4329 | } |
| 4330 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4331 | TemplateParameterList * |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4332 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 4333 | const RecordData &Record, unsigned &Idx) { |
| 4334 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 4335 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 4336 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4337 | |
| 4338 | unsigned NumParams = Record[Idx++]; |
| 4339 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 4340 | Params.reserve(NumParams); |
| 4341 | while (NumParams--) |
| 4342 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4343 | |
| 4344 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4345 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 4346 | Params.data(), Params.size(), RAngleLoc); |
| 4347 | return TemplateParams; |
| 4348 | } |
| 4349 | |
| 4350 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4351 | ASTReader:: |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4352 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4353 | PerFileData &F, const RecordData &Record, |
| 4354 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4355 | unsigned NumTemplateArgs = Record[Idx++]; |
| 4356 | TemplArgs.reserve(NumTemplateArgs); |
| 4357 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4358 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4359 | } |
| 4360 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4361 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4362 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4363 | const RecordData &Record, unsigned &Idx) { |
| 4364 | unsigned NumDecls = Record[Idx++]; |
| 4365 | while (NumDecls--) { |
| 4366 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 4367 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 4368 | Set.addDecl(D, AS); |
| 4369 | } |
| 4370 | } |
| 4371 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4372 | CXXBaseSpecifier |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4373 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4374 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4375 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 4376 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 4377 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4378 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4379 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4380 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
| 4381 | return CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, TInfo, |
| 4382 | EllipsisLoc); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4383 | } |
| 4384 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4385 | std::pair<CXXCtorInitializer **, unsigned> |
| 4386 | ASTReader::ReadCXXCtorInitializers(PerFileData &F, const RecordData &Record, |
| 4387 | unsigned &Idx) { |
| 4388 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4389 | unsigned NumInitializers = Record[Idx++]; |
| 4390 | if (NumInitializers) { |
| 4391 | ASTContext &C = *getContext(); |
| 4392 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4393 | CtorInitializers |
| 4394 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4395 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 4396 | TypeSourceInfo *BaseClassInfo = 0; |
| 4397 | bool IsBaseVirtual = false; |
| 4398 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4399 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4400 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4401 | bool IsBaseInitializer = Record[Idx++]; |
| 4402 | if (IsBaseInitializer) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4403 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4404 | IsBaseVirtual = Record[Idx++]; |
| 4405 | } else { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4406 | bool IsIndirectMemberInitializer = Record[Idx++]; |
| 4407 | if (IsIndirectMemberInitializer) |
| 4408 | IndirectMember = cast<IndirectFieldDecl>(GetDecl(Record[Idx++])); |
| 4409 | else |
| 4410 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4411 | } |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 4412 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4413 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4414 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 4415 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4416 | bool IsWritten = Record[Idx++]; |
| 4417 | unsigned SourceOrderOrNumArrayIndices; |
| 4418 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 4419 | if (IsWritten) { |
| 4420 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4421 | } else { |
| 4422 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4423 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 4424 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 4425 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 4426 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4427 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4428 | CXXCtorInitializer *BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4429 | if (IsBaseInitializer) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4430 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 4431 | LParenLoc, Init, RParenLoc, |
| 4432 | MemberOrEllipsisLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4433 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4434 | if (Member) |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4435 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 4436 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4437 | else |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4438 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 4439 | MemberOrEllipsisLoc, LParenLoc, |
| 4440 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4441 | } else { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4442 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 4443 | LParenLoc, Init, RParenLoc, |
| 4444 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4445 | } |
| 4446 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 4447 | if (IsWritten) |
| 4448 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4449 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4450 | } |
| 4451 | } |
| 4452 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4453 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4454 | } |
| 4455 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4456 | NestedNameSpecifier * |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4457 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4458 | unsigned N = Record[Idx++]; |
| 4459 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 4460 | for (unsigned I = 0; I != N; ++I) { |
| 4461 | NestedNameSpecifier::SpecifierKind Kind |
| 4462 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4463 | switch (Kind) { |
| 4464 | case NestedNameSpecifier::Identifier: { |
| 4465 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 4466 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 4467 | break; |
| 4468 | } |
| 4469 | |
| 4470 | case NestedNameSpecifier::Namespace: { |
| 4471 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 4472 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 4473 | break; |
| 4474 | } |
| 4475 | |
| 4476 | case NestedNameSpecifier::TypeSpec: |
| 4477 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame^] | 4478 | const Type *T = GetType(Record[Idx++]).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 4479 | if (!T) |
| 4480 | return 0; |
| 4481 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4482 | bool Template = Record[Idx++]; |
| 4483 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 4484 | break; |
| 4485 | } |
| 4486 | |
| 4487 | case NestedNameSpecifier::Global: { |
| 4488 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4489 | // No associated value, and there can't be a prefix. |
| 4490 | break; |
| 4491 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4492 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 4493 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4494 | } |
| 4495 | return NNS; |
| 4496 | } |
| 4497 | |
| 4498 | SourceRange |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4499 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 4500 | unsigned &Idx) { |
| 4501 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 4502 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 4503 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4504 | } |
| 4505 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4506 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4507 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4508 | unsigned BitWidth = Record[Idx++]; |
| 4509 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 4510 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 4511 | Idx += NumWords; |
| 4512 | return Result; |
| 4513 | } |
| 4514 | |
| 4515 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4516 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4517 | bool isUnsigned = Record[Idx++]; |
| 4518 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 4519 | } |
| 4520 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4521 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4522 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4523 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 4524 | } |
| 4525 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4526 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4527 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4528 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 4529 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4530 | Idx += Len; |
| 4531 | return Result; |
| 4532 | } |
| 4533 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4534 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4535 | unsigned &Idx) { |
| 4536 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 4537 | return CXXTemporary::Create(*Context, Decl); |
| 4538 | } |
| 4539 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4540 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 4541 | return Diag(SourceLocation(), DiagID); |
| 4542 | } |
| 4543 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4544 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4545 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4546 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4547 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4548 | /// \brief Retrieve the identifier table associated with the |
| 4549 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4550 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4551 | assert(PP && "Forgot to set Preprocessor ?"); |
| 4552 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4553 | } |
| 4554 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4555 | /// \brief Record that the given ID maps to the given switch-case |
| 4556 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4557 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4558 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 4559 | SwitchCaseStmts[ID] = SC; |
| 4560 | } |
| 4561 | |
| 4562 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4563 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4564 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 4565 | return SwitchCaseStmts[ID]; |
| 4566 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4567 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4568 | void ASTReader::ClearSwitchCaseIDs() { |
| 4569 | SwitchCaseStmts.clear(); |
| 4570 | } |
| 4571 | |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4572 | /// \brief Record that the given label statement has been |
| 4573 | /// deserialized and has the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4574 | void ASTReader::RecordLabelStmt(LabelStmt *S, unsigned ID) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4575 | assert(LabelStmts.find(ID) == LabelStmts.end() && |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4576 | "Deserialized label twice"); |
| 4577 | LabelStmts[ID] = S; |
| 4578 | |
| 4579 | // If we've already seen any goto statements that point to this |
| 4580 | // label, resolve them now. |
| 4581 | typedef std::multimap<unsigned, GotoStmt *>::iterator GotoIter; |
| 4582 | std::pair<GotoIter, GotoIter> Gotos = UnresolvedGotoStmts.equal_range(ID); |
| 4583 | for (GotoIter Goto = Gotos.first; Goto != Gotos.second; ++Goto) |
| 4584 | Goto->second->setLabel(S); |
| 4585 | UnresolvedGotoStmts.erase(Gotos.first, Gotos.second); |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4586 | |
| 4587 | // If we've already seen any address-label statements that point to |
| 4588 | // this label, resolve them now. |
| 4589 | typedef std::multimap<unsigned, AddrLabelExpr *>::iterator AddrLabelIter; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4590 | std::pair<AddrLabelIter, AddrLabelIter> AddrLabels |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4591 | = UnresolvedAddrLabelExprs.equal_range(ID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4592 | for (AddrLabelIter AddrLabel = AddrLabels.first; |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4593 | AddrLabel != AddrLabels.second; ++AddrLabel) |
| 4594 | AddrLabel->second->setLabel(S); |
| 4595 | UnresolvedAddrLabelExprs.erase(AddrLabels.first, AddrLabels.second); |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4596 | } |
| 4597 | |
| 4598 | /// \brief Set the label of the given statement to the label |
| 4599 | /// identified by ID. |
| 4600 | /// |
| 4601 | /// Depending on the order in which the label and other statements |
| 4602 | /// referencing that label occur, this operation may complete |
| 4603 | /// immediately (updating the statement) or it may queue the |
| 4604 | /// statement to be back-patched later. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4605 | void ASTReader::SetLabelOf(GotoStmt *S, unsigned ID) { |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4606 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 4607 | if (Label != LabelStmts.end()) { |
| 4608 | // We've already seen this label, so set the label of the goto and |
| 4609 | // we're done. |
| 4610 | S->setLabel(Label->second); |
| 4611 | } else { |
| 4612 | // We haven't seen this label yet, so add this goto to the set of |
| 4613 | // unresolved goto statements. |
| 4614 | UnresolvedGotoStmts.insert(std::make_pair(ID, S)); |
| 4615 | } |
| 4616 | } |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4617 | |
| 4618 | /// \brief Set the label of the given expression to the label |
| 4619 | /// identified by ID. |
| 4620 | /// |
| 4621 | /// Depending on the order in which the label and other statements |
| 4622 | /// referencing that label occur, this operation may complete |
| 4623 | /// immediately (updating the statement) or it may queue the |
| 4624 | /// statement to be back-patched later. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4625 | void ASTReader::SetLabelOf(AddrLabelExpr *S, unsigned ID) { |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4626 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 4627 | if (Label != LabelStmts.end()) { |
| 4628 | // We've already seen this label, so set the label of the |
| 4629 | // label-address expression and we're done. |
| 4630 | S->setLabel(Label->second); |
| 4631 | } else { |
| 4632 | // We haven't seen this label yet, so add this label-address |
| 4633 | // expression to the set of unresolved label-address expressions. |
| 4634 | UnresolvedAddrLabelExprs.insert(std::make_pair(ID, S)); |
| 4635 | } |
| 4636 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4637 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4638 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4639 | assert(NumCurrentElementsDeserializing && |
| 4640 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 4641 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4642 | // If any identifiers with corresponding top-level declarations have |
| 4643 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4644 | while (!PendingIdentifierInfos.empty()) { |
| 4645 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 4646 | PendingIdentifierInfos.front().DeclIDs, true); |
| 4647 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4648 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4649 | |
| 4650 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 4651 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4652 | if (Consumer) |
| 4653 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 4654 | |
| 4655 | assert(PendingForwardRefs.size() == 0 && |
| 4656 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4657 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4658 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4659 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4660 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4661 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
| 4662 | const char *isysroot, bool DisableValidation) |
| 4663 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 4664 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 4665 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
| 4666 | Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), |
| 4667 | NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4668 | TotalNumSLocEntries(0), NextSLocOffset(0), NumStatementsRead(0), |
| 4669 | TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), |
| 4670 | NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4671 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4672 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4673 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
| 4674 | RelocatablePCH = false; |
| 4675 | } |
| 4676 | |
| 4677 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 4678 | Diagnostic &Diags, const char *isysroot, |
| 4679 | bool DisableValidation) |
| 4680 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
| 4681 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), |
| 4682 | isysroot(isysroot), DisableValidation(DisableValidation), NumStatHits(0), |
| 4683 | NumStatMisses(0), NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Sebastian Redl | 8db9fae | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4684 | NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0), |
| 4685 | NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), |
| 4686 | NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
| 4687 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4688 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4689 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4690 | RelocatablePCH = false; |
| 4691 | } |
| 4692 | |
| 4693 | ASTReader::~ASTReader() { |
| 4694 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 4695 | delete Chain[e - i - 1]; |
| 4696 | // Delete all visible decl lookup tables |
| 4697 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 4698 | E = DeclContextOffsets.end(); |
| 4699 | I != E; ++I) { |
| 4700 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 4701 | J != F; ++J) { |
| 4702 | if (J->NameLookupTableData) |
| 4703 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 4704 | J->NameLookupTableData); |
| 4705 | } |
| 4706 | } |
| 4707 | for (DeclContextVisibleUpdatesPending::iterator |
| 4708 | I = PendingVisibleUpdates.begin(), |
| 4709 | E = PendingVisibleUpdates.end(); |
| 4710 | I != E; ++I) { |
| 4711 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 4712 | F = I->second.end(); |
| 4713 | J != F; ++J) |
| 4714 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 4715 | } |
| 4716 | } |
| 4717 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 4718 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
| 4719 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0), |
Sebastian Redl | 301c9b0 | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 4720 | LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), |
| 4721 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
| 4722 | MacroDefinitionOffsets(0), LocalNumSelectors(0), SelectorOffsets(0), |
| 4723 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4724 | DeclOffsets(0), LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
| 4725 | LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | a866e65 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 4726 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4727 | {} |
| 4728 | |
| 4729 | ASTReader::PerFileData::~PerFileData() { |
| 4730 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
| 4731 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 4732 | } |
| 4733 | |