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