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