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