blob: 386462443efade74cd25739f20f93dc924465961 [file] [log] [blame]
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001//===--- 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 Lattner92ba5ff2009-04-27 05:14:47 +000013
Douglas Gregoref84c4b2009-04-09 22:27:44 +000014#include "clang/Frontend/PCHReader.h"
Douglas Gregor55abb232009-04-10 20:39:37 +000015#include "clang/Frontend/FrontendDiagnostic.h"
Daniel Dunbar732ef8a2009-11-11 23:58:53 +000016#include "clang/Frontend/Utils.h"
Douglas Gregora868bbd2009-04-21 22:25:48 +000017#include "../Sema/Sema.h" // FIXME: move Sema headers elsewhere
Douglas Gregor1a0d0b92009-04-14 00:24:19 +000018#include "clang/AST/ASTConsumer.h"
Douglas Gregoref84c4b2009-04-09 22:27:44 +000019#include "clang/AST/ASTContext.h"
Douglas Gregorfeb84b02009-04-14 21:18:50 +000020#include "clang/AST/Expr.h"
Douglas Gregoref84c4b2009-04-09 22:27:44 +000021#include "clang/AST/Type.h"
John McCall8f115c62009-10-16 21:56:05 +000022#include "clang/AST/TypeLocVisitor.h"
Chris Lattner34321bc2009-04-10 21:41:48 +000023#include "clang/Lex/MacroInfo.h"
Douglas Gregoraae92242010-03-19 21:51:54 +000024#include "clang/Lex/PreprocessingRecord.h"
Douglas Gregora7f71a92009-04-10 03:52:48 +000025#include "clang/Lex/Preprocessor.h"
Steve Naroff3fa455a2009-04-24 20:03:17 +000026#include "clang/Lex/HeaderSearch.h"
Douglas Gregora868bbd2009-04-21 22:25:48 +000027#include "clang/Basic/OnDiskHashTable.h"
Douglas Gregora7f71a92009-04-10 03:52:48 +000028#include "clang/Basic/SourceManager.h"
Douglas Gregor4c7626e2009-04-13 16:31:14 +000029#include "clang/Basic/SourceManagerInternals.h"
Douglas Gregora7f71a92009-04-10 03:52:48 +000030#include "clang/Basic/FileManager.h"
Douglas Gregorbfbde532009-04-10 21:16:55 +000031#include "clang/Basic/TargetInfo.h"
Douglas Gregord54f3a12009-10-05 21:07:28 +000032#include "clang/Basic/Version.h"
Daniel Dunbarf8502d52009-10-17 23:52:28 +000033#include "llvm/ADT/StringExtras.h"
Douglas Gregoref84c4b2009-04-09 22:27:44 +000034#include "llvm/Bitcode/BitstreamReader.h"
Douglas Gregoref84c4b2009-04-09 22:27:44 +000035#include "llvm/Support/MemoryBuffer.h"
John McCall0ad16662009-10-29 08:12:44 +000036#include "llvm/Support/ErrorHandling.h"
Daniel Dunbarf2ce9a22009-11-18 19:50:41 +000037#include "llvm/System/Path.h"
Douglas Gregoref84c4b2009-04-09 22:27:44 +000038#include <algorithm>
Douglas Gregorc379c072009-04-28 18:58:38 +000039#include <iterator>
Douglas Gregoref84c4b2009-04-09 22:27:44 +000040#include <cstdio>
Douglas Gregorc5046832009-04-27 18:38:38 +000041#include <sys/stat.h>
Douglas Gregoref84c4b2009-04-09 22:27:44 +000042using namespace clang;
43
44//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +000045// PCH reader validator implementation
46//===----------------------------------------------------------------------===//
47
48PCHReaderListener::~PCHReaderListener() {}
49
50bool
51PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) {
52 const LangOptions &PPLangOpts = PP.getLangOptions();
53#define PARSE_LANGOPT_BENIGN(Option)
54#define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \
55 if (PPLangOpts.Option != LangOpts.Option) { \
56 Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \
57 return true; \
58 }
59
60 PARSE_LANGOPT_BENIGN(Trigraphs);
61 PARSE_LANGOPT_BENIGN(BCPLComment);
62 PARSE_LANGOPT_BENIGN(DollarIdents);
63 PARSE_LANGOPT_BENIGN(AsmPreprocessor);
64 PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions);
Chandler Carruthe03aa552010-04-17 20:17:31 +000065 PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +000066 PARSE_LANGOPT_BENIGN(ImplicitInt);
67 PARSE_LANGOPT_BENIGN(Digraphs);
68 PARSE_LANGOPT_BENIGN(HexFloats);
69 PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99);
70 PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions);
71 PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus);
72 PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x);
73 PARSE_LANGOPT_BENIGN(CXXOperatorName);
74 PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c);
75 PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2);
76 PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi);
Fariborz Jahanian45878032010-02-09 19:31:38 +000077 PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2);
Fariborz Jahanian62c56022010-04-22 21:01:59 +000078 PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings,
79 diag::warn_pch_no_constant_cfstrings);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +000080 PARSE_LANGOPT_BENIGN(PascalStrings);
81 PARSE_LANGOPT_BENIGN(WritableStrings);
Mike Stump11289f42009-09-09 15:08:12 +000082 PARSE_LANGOPT_IMPORTANT(LaxVectorConversions,
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +000083 diag::warn_pch_lax_vector_conversions);
Nate Begeman9d905792009-06-25 22:57:40 +000084 PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +000085 PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions);
Daniel Dunbar925152c2010-02-10 18:48:44 +000086 PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +000087 PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime);
88 PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding);
89 PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins);
Mike Stump11289f42009-09-09 15:08:12 +000090 PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics,
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +000091 diag::warn_pch_thread_safe_statics);
Daniel Dunbara77eaeb2009-09-03 04:54:28 +000092 PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +000093 PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks);
94 PARSE_LANGOPT_BENIGN(EmitAllDecls);
95 PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno);
Chris Lattner51924e512010-06-26 21:25:03 +000096 PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior());
Mike Stump11289f42009-09-09 15:08:12 +000097 PARSE_LANGOPT_IMPORTANT(HeinousExtensions,
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +000098 diag::warn_pch_heinous_extensions);
99 // FIXME: Most of the options below are benign if the macro wasn't
100 // used. Unfortunately, this means that a PCH compiled without
101 // optimization can't be used with optimization turned on, even
102 // though the only thing that changes is whether __OPTIMIZE__ was
103 // defined... but if __OPTIMIZE__ never showed up in the header, it
104 // doesn't matter. We could consider making this some special kind
105 // of check.
106 PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize);
107 PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size);
108 PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static);
109 PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level);
110 PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline);
111 PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline);
112 PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control);
113 PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed);
John Thompsoned4e2952009-11-05 20:14:16 +0000114 PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000115 if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) {
Mike Stump11289f42009-09-09 15:08:12 +0000116 Reader.Diag(diag::warn_pch_gc_mode)
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000117 << LangOpts.getGCMode() << PPLangOpts.getGCMode();
118 return true;
119 }
120 PARSE_LANGOPT_BENIGN(getVisibilityMode());
Daniel Dunbar143021e2009-09-21 04:16:19 +0000121 PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(),
122 diag::warn_pch_stack_protector);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000123 PARSE_LANGOPT_BENIGN(InstantiationDepth);
Nate Begeman9d905792009-06-25 22:57:40 +0000124 PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl);
Mike Stumpd9546382009-12-12 01:27:46 +0000125 PARSE_LANGOPT_BENIGN(CatchUndefined);
Daniel Dunbar143021e2009-09-21 04:16:19 +0000126 PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors);
Kovarththanan Rajaratnam39f2fbd12010-03-07 19:10:13 +0000127#undef PARSE_LANGOPT_IMPORTANT
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000128#undef PARSE_LANGOPT_BENIGN
129
130 return false;
131}
132
Daniel Dunbar20a682d2009-11-11 00:52:11 +0000133bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) {
134 if (Triple == PP.getTargetInfo().getTriple().str())
135 return false;
136
137 Reader.Diag(diag::warn_pch_target_triple)
138 << Triple << PP.getTargetInfo().getTriple().str();
139 return true;
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000140}
141
Daniel Dunbar20a682d2009-11-11 00:52:11 +0000142bool PCHValidator::ReadPredefinesBuffer(llvm::StringRef PCHPredef,
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000143 FileID PCHBufferID,
Daniel Dunbar000c4ff2009-11-11 05:29:04 +0000144 llvm::StringRef OriginalFileName,
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000145 std::string &SuggestedPredefines) {
Daniel Dunbar732ef8a2009-11-11 23:58:53 +0000146 // We are in the context of an implicit include, so the predefines buffer will
147 // have a #include entry for the PCH file itself (as normalized by the
148 // preprocessor initialization). Find it and skip over it in the checking
149 // below.
Daniel Dunbar000c4ff2009-11-11 05:29:04 +0000150 llvm::SmallString<256> PCHInclude;
151 PCHInclude += "#include \"";
Daniel Dunbar732ef8a2009-11-11 23:58:53 +0000152 PCHInclude += NormalizeDashIncludePath(OriginalFileName);
Daniel Dunbar000c4ff2009-11-11 05:29:04 +0000153 PCHInclude += "\"\n";
154 std::pair<llvm::StringRef,llvm::StringRef> Split =
155 llvm::StringRef(PP.getPredefines()).split(PCHInclude.str());
156 llvm::StringRef Left = Split.first, Right = Split.second;
Ted Kremenek1ff615c2010-03-18 00:56:54 +0000157 if (Left == PP.getPredefines()) {
158 Error("Missing PCH include entry!");
159 return true;
160 }
Daniel Dunbar000c4ff2009-11-11 05:29:04 +0000161
162 // If the predefines is equal to the joined left and right halves, we're done!
163 if (Left.size() + Right.size() == PCHPredef.size() &&
164 PCHPredef.startswith(Left) && PCHPredef.endswith(Right))
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000165 return false;
166
167 SourceManager &SourceMgr = PP.getSourceManager();
Mike Stump11289f42009-09-09 15:08:12 +0000168
Daniel Dunbar8665c7e2009-11-11 03:45:59 +0000169 // The predefines buffers are different. Determine what the differences are,
170 // and whether they require us to reject the PCH file.
Daniel Dunbar045f917e2009-11-13 16:46:11 +0000171 llvm::SmallVector<llvm::StringRef, 8> PCHLines;
172 PCHPredef.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
173
174 llvm::SmallVector<llvm::StringRef, 8> CmdLineLines;
175 Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
176 Right.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000177
Daniel Dunbar499baed2009-11-11 05:26:28 +0000178 // Sort both sets of predefined buffer lines, since we allow some extra
179 // definitions and they may appear at any point in the output.
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000180 std::sort(CmdLineLines.begin(), CmdLineLines.end());
181 std::sort(PCHLines.begin(), PCHLines.end());
182
Daniel Dunbar499baed2009-11-11 05:26:28 +0000183 // Determine which predefines that were used to build the PCH file are missing
184 // from the command line.
185 std::vector<llvm::StringRef> MissingPredefines;
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000186 std::set_difference(PCHLines.begin(), PCHLines.end(),
187 CmdLineLines.begin(), CmdLineLines.end(),
188 std::back_inserter(MissingPredefines));
189
190 bool MissingDefines = false;
191 bool ConflictingDefines = false;
192 for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) {
Daniel Dunbar499baed2009-11-11 05:26:28 +0000193 llvm::StringRef Missing = MissingPredefines[I];
194 if (!Missing.startswith("#define ")) {
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000195 Reader.Diag(diag::warn_pch_compiler_options_mismatch);
196 return true;
197 }
Mike Stump11289f42009-09-09 15:08:12 +0000198
Daniel Dunbar8665c7e2009-11-11 03:45:59 +0000199 // This is a macro definition. Determine the name of the macro we're
200 // defining.
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000201 std::string::size_type StartOfMacroName = strlen("#define ");
Mike Stump11289f42009-09-09 15:08:12 +0000202 std::string::size_type EndOfMacroName
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000203 = Missing.find_first_of("( \n\r", StartOfMacroName);
204 assert(EndOfMacroName != std::string::npos &&
205 "Couldn't find the end of the macro name");
Daniel Dunbar499baed2009-11-11 05:26:28 +0000206 llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000207
Daniel Dunbar8665c7e2009-11-11 03:45:59 +0000208 // Determine whether this macro was given a different definition on the
209 // command line.
Daniel Dunbar499baed2009-11-11 05:26:28 +0000210 std::string MacroDefStart = "#define " + MacroName.str();
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000211 std::string::size_type MacroDefLen = MacroDefStart.size();
Daniel Dunbar045f917e2009-11-13 16:46:11 +0000212 llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000213 = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(),
214 MacroDefStart);
215 for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) {
Daniel Dunbar8665c7e2009-11-11 03:45:59 +0000216 if (!ConflictPos->startswith(MacroDefStart)) {
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000217 // Different macro; we're done.
218 ConflictPos = CmdLineLines.end();
Mike Stump11289f42009-09-09 15:08:12 +0000219 break;
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000220 }
Mike Stump11289f42009-09-09 15:08:12 +0000221
222 assert(ConflictPos->size() > MacroDefLen &&
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000223 "Invalid #define in predefines buffer?");
Mike Stump11289f42009-09-09 15:08:12 +0000224 if ((*ConflictPos)[MacroDefLen] != ' ' &&
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000225 (*ConflictPos)[MacroDefLen] != '(')
226 continue; // Longer macro name; keep trying.
Mike Stump11289f42009-09-09 15:08:12 +0000227
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000228 // We found a conflicting macro definition.
229 break;
230 }
Mike Stump11289f42009-09-09 15:08:12 +0000231
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000232 if (ConflictPos != CmdLineLines.end()) {
233 Reader.Diag(diag::warn_cmdline_conflicting_macro_def)
234 << MacroName;
235
236 // Show the definition of this macro within the PCH file.
Daniel Dunbar499baed2009-11-11 05:26:28 +0000237 llvm::StringRef::size_type Offset = PCHPredef.find(Missing);
238 assert(Offset != llvm::StringRef::npos && "Unable to find macro!");
239 SourceLocation PCHMissingLoc = SourceMgr.getLocForStartOfFile(PCHBufferID)
240 .getFileLocWithOffset(Offset);
241 Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName;
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000242
243 ConflictingDefines = true;
244 continue;
245 }
Mike Stump11289f42009-09-09 15:08:12 +0000246
Daniel Dunbar8665c7e2009-11-11 03:45:59 +0000247 // If the macro doesn't conflict, then we'll just pick up the macro
248 // definition from the PCH file. Warn the user that they made a mistake.
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000249 if (ConflictingDefines)
250 continue; // Don't complain if there are already conflicting defs
Mike Stump11289f42009-09-09 15:08:12 +0000251
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000252 if (!MissingDefines) {
253 Reader.Diag(diag::warn_cmdline_missing_macro_defs);
254 MissingDefines = true;
255 }
256
257 // Show the definition of this macro within the PCH file.
Daniel Dunbar499baed2009-11-11 05:26:28 +0000258 llvm::StringRef::size_type Offset = PCHPredef.find(Missing);
259 assert(Offset != llvm::StringRef::npos && "Unable to find macro!");
260 SourceLocation PCHMissingLoc = SourceMgr.getLocForStartOfFile(PCHBufferID)
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000261 .getFileLocWithOffset(Offset);
262 Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch);
263 }
Mike Stump11289f42009-09-09 15:08:12 +0000264
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000265 if (ConflictingDefines)
266 return true;
Mike Stump11289f42009-09-09 15:08:12 +0000267
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000268 // Determine what predefines were introduced based on command-line
269 // parameters that were not present when building the PCH
270 // file. Extra #defines are okay, so long as the identifiers being
271 // defined were not used within the precompiled header.
Daniel Dunbar499baed2009-11-11 05:26:28 +0000272 std::vector<llvm::StringRef> ExtraPredefines;
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000273 std::set_difference(CmdLineLines.begin(), CmdLineLines.end(),
274 PCHLines.begin(), PCHLines.end(),
Mike Stump11289f42009-09-09 15:08:12 +0000275 std::back_inserter(ExtraPredefines));
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000276 for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) {
Daniel Dunbar499baed2009-11-11 05:26:28 +0000277 llvm::StringRef &Extra = ExtraPredefines[I];
278 if (!Extra.startswith("#define ")) {
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000279 Reader.Diag(diag::warn_pch_compiler_options_mismatch);
280 return true;
281 }
282
283 // This is an extra macro definition. Determine the name of the
284 // macro we're defining.
285 std::string::size_type StartOfMacroName = strlen("#define ");
Mike Stump11289f42009-09-09 15:08:12 +0000286 std::string::size_type EndOfMacroName
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000287 = Extra.find_first_of("( \n\r", StartOfMacroName);
288 assert(EndOfMacroName != std::string::npos &&
289 "Couldn't find the end of the macro name");
Daniel Dunbar499baed2009-11-11 05:26:28 +0000290 llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000291
292 // Check whether this name was used somewhere in the PCH file. If
293 // so, defining it as a macro could change behavior, so we reject
294 // the PCH file.
Daniel Dunbar499baed2009-11-11 05:26:28 +0000295 if (IdentifierInfo *II = Reader.get(MacroName)) {
Daniel Dunbar045c92f2009-11-11 00:52:00 +0000296 Reader.Diag(diag::warn_macro_name_used_in_pch) << II;
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000297 return true;
298 }
299
300 // Add this definition to the suggested predefines buffer.
301 SuggestedPredefines += Extra;
302 SuggestedPredefines += '\n';
303 }
304
305 // If we get here, it's because the predefines buffer had compatible
306 // contents. Accept the PCH file.
307 return false;
308}
309
Douglas Gregor5712ebc2010-03-16 16:35:32 +0000310void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI,
311 unsigned ID) {
312 PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID);
313 ++NumHeaderInfos;
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000314}
315
316void PCHValidator::ReadCounter(unsigned Value) {
317 PP.setCounterValue(Value);
318}
319
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000320//===----------------------------------------------------------------------===//
Douglas Gregora868bbd2009-04-21 22:25:48 +0000321// PCH reader implementation
322//===----------------------------------------------------------------------===//
323
Mike Stump11289f42009-09-09 15:08:12 +0000324PCHReader::PCHReader(Preprocessor &PP, ASTContext *Context,
325 const char *isysroot)
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000326 : Listener(new PCHValidator(PP, *this)), SourceMgr(PP.getSourceManager()),
327 FileMgr(PP.getFileManager()), Diags(PP.getDiagnostics()),
Douglas Gregord2eb58a2009-10-16 18:18:30 +0000328 SemaObj(0), PP(&PP), Context(Context), StatCache(0), Consumer(0),
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000329 IdentifierTableData(0), IdentifierLookupTable(0),
330 IdentifierOffsets(0),
331 MethodPoolLookupTable(0), MethodPoolLookupTableData(0),
332 TotalSelectorsInMethodPool(0), SelectorOffsets(0),
Douglas Gregoraae92242010-03-19 21:51:54 +0000333 TotalNumSelectors(0), MacroDefinitionOffsets(0),
Douglas Gregor9507d462010-03-19 22:13:20 +0000334 NumPreallocatedPreprocessingEntities(0),
Douglas Gregoraae92242010-03-19 21:51:54 +0000335 isysroot(isysroot), NumStatHits(0), NumStatMisses(0),
Mike Stump11289f42009-09-09 15:08:12 +0000336 NumSLocEntriesRead(0), NumStatementsRead(0),
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000337 NumMacrosRead(0), NumMethodPoolSelectorsRead(0), NumMethodPoolMisses(0),
Douglas Gregor0086a5a2009-07-07 00:12:59 +0000338 NumLexicalDeclContextsRead(0), NumVisibleDeclContextsRead(0),
Mike Stump11289f42009-09-09 15:08:12 +0000339 CurrentlyLoadingTypeOrDecl(0) {
Douglas Gregor0086a5a2009-07-07 00:12:59 +0000340 RelocatablePCH = false;
341}
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000342
343PCHReader::PCHReader(SourceManager &SourceMgr, FileManager &FileMgr,
Mike Stump11289f42009-09-09 15:08:12 +0000344 Diagnostic &Diags, const char *isysroot)
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000345 : SourceMgr(SourceMgr), FileMgr(FileMgr), Diags(Diags),
Douglas Gregord2eb58a2009-10-16 18:18:30 +0000346 SemaObj(0), PP(0), Context(0), StatCache(0), Consumer(0),
Chris Lattner92ba5ff2009-04-27 05:14:47 +0000347 IdentifierTableData(0), IdentifierLookupTable(0),
348 IdentifierOffsets(0),
349 MethodPoolLookupTable(0), MethodPoolLookupTableData(0),
350 TotalSelectorsInMethodPool(0), SelectorOffsets(0),
Douglas Gregoraae92242010-03-19 21:51:54 +0000351 TotalNumSelectors(0), MacroDefinitionOffsets(0),
Douglas Gregor9507d462010-03-19 22:13:20 +0000352 NumPreallocatedPreprocessingEntities(0),
Douglas Gregoraae92242010-03-19 21:51:54 +0000353 isysroot(isysroot), NumStatHits(0), NumStatMisses(0),
Mike Stump11289f42009-09-09 15:08:12 +0000354 NumSLocEntriesRead(0), NumStatementsRead(0),
Douglas Gregor258ae542009-04-27 06:38:32 +0000355 NumMacrosRead(0), NumMethodPoolSelectorsRead(0), NumMethodPoolMisses(0),
Douglas Gregor1342e842009-07-06 18:54:52 +0000356 NumLexicalDeclContextsRead(0), NumVisibleDeclContextsRead(0),
Mike Stump11289f42009-09-09 15:08:12 +0000357 CurrentlyLoadingTypeOrDecl(0) {
Douglas Gregor0086a5a2009-07-07 00:12:59 +0000358 RelocatablePCH = false;
359}
Chris Lattner92ba5ff2009-04-27 05:14:47 +0000360
361PCHReader::~PCHReader() {}
362
Chris Lattner1de76db2009-04-27 05:58:23 +0000363Expr *PCHReader::ReadDeclExpr() {
364 return dyn_cast_or_null<Expr>(ReadStmt(DeclsCursor));
365}
366
367Expr *PCHReader::ReadTypeExpr() {
Douglas Gregor12bfa382009-10-17 00:13:19 +0000368 return dyn_cast_or_null<Expr>(ReadStmt(DeclsCursor));
Chris Lattner92ba5ff2009-04-27 05:14:47 +0000369}
370
371
Douglas Gregora868bbd2009-04-21 22:25:48 +0000372namespace {
Benjamin Kramer16634c22009-11-28 10:07:24 +0000373class PCHMethodPoolLookupTrait {
Douglas Gregorc78d3462009-04-24 21:10:55 +0000374 PCHReader &Reader;
375
376public:
377 typedef std::pair<ObjCMethodList, ObjCMethodList> data_type;
378
379 typedef Selector external_key_type;
380 typedef external_key_type internal_key_type;
381
382 explicit PCHMethodPoolLookupTrait(PCHReader &Reader) : Reader(Reader) { }
Mike Stump11289f42009-09-09 15:08:12 +0000383
Douglas Gregorc78d3462009-04-24 21:10:55 +0000384 static bool EqualKey(const internal_key_type& a,
385 const internal_key_type& b) {
386 return a == b;
387 }
Mike Stump11289f42009-09-09 15:08:12 +0000388
Douglas Gregorc78d3462009-04-24 21:10:55 +0000389 static unsigned ComputeHash(Selector Sel) {
390 unsigned N = Sel.getNumArgs();
391 if (N == 0)
392 ++N;
393 unsigned R = 5381;
394 for (unsigned I = 0; I != N; ++I)
395 if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I))
Daniel Dunbarf8502d52009-10-17 23:52:28 +0000396 R = llvm::HashString(II->getName(), R);
Douglas Gregorc78d3462009-04-24 21:10:55 +0000397 return R;
398 }
Mike Stump11289f42009-09-09 15:08:12 +0000399
Douglas Gregorc78d3462009-04-24 21:10:55 +0000400 // This hopefully will just get inlined and removed by the optimizer.
401 static const internal_key_type&
402 GetInternalKey(const external_key_type& x) { return x; }
Mike Stump11289f42009-09-09 15:08:12 +0000403
Douglas Gregorc78d3462009-04-24 21:10:55 +0000404 static std::pair<unsigned, unsigned>
405 ReadKeyDataLength(const unsigned char*& d) {
406 using namespace clang::io;
407 unsigned KeyLen = ReadUnalignedLE16(d);
408 unsigned DataLen = ReadUnalignedLE16(d);
409 return std::make_pair(KeyLen, DataLen);
410 }
Mike Stump11289f42009-09-09 15:08:12 +0000411
Douglas Gregor95c13f52009-04-25 17:48:32 +0000412 internal_key_type ReadKey(const unsigned char* d, unsigned) {
Douglas Gregorc78d3462009-04-24 21:10:55 +0000413 using namespace clang::io;
Chris Lattner8575daa2009-04-27 21:45:14 +0000414 SelectorTable &SelTable = Reader.getContext()->Selectors;
Douglas Gregorc78d3462009-04-24 21:10:55 +0000415 unsigned N = ReadUnalignedLE16(d);
Mike Stump11289f42009-09-09 15:08:12 +0000416 IdentifierInfo *FirstII
Douglas Gregorc78d3462009-04-24 21:10:55 +0000417 = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d));
418 if (N == 0)
419 return SelTable.getNullarySelector(FirstII);
420 else if (N == 1)
421 return SelTable.getUnarySelector(FirstII);
422
423 llvm::SmallVector<IdentifierInfo *, 16> Args;
424 Args.push_back(FirstII);
425 for (unsigned I = 1; I != N; ++I)
426 Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)));
427
Douglas Gregor038c3382009-05-22 22:45:36 +0000428 return SelTable.getSelector(N, Args.data());
Douglas Gregorc78d3462009-04-24 21:10:55 +0000429 }
Mike Stump11289f42009-09-09 15:08:12 +0000430
Douglas Gregorc78d3462009-04-24 21:10:55 +0000431 data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) {
432 using namespace clang::io;
433 unsigned NumInstanceMethods = ReadUnalignedLE16(d);
434 unsigned NumFactoryMethods = ReadUnalignedLE16(d);
435
436 data_type Result;
437
438 // Load instance methods
439 ObjCMethodList *Prev = 0;
440 for (unsigned I = 0; I != NumInstanceMethods; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +0000441 ObjCMethodDecl *Method
Douglas Gregorc78d3462009-04-24 21:10:55 +0000442 = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d)));
443 if (!Result.first.Method) {
444 // This is the first method, which is the easy case.
445 Result.first.Method = Method;
446 Prev = &Result.first;
447 continue;
448 }
449
Ted Kremenekda4abf12010-02-11 00:53:01 +0000450 ObjCMethodList *Mem =
451 Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>();
452 Prev->Next = new (Mem) ObjCMethodList(Method, 0);
Douglas Gregorc78d3462009-04-24 21:10:55 +0000453 Prev = Prev->Next;
454 }
455
456 // Load factory methods
457 Prev = 0;
458 for (unsigned I = 0; I != NumFactoryMethods; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +0000459 ObjCMethodDecl *Method
Douglas Gregorc78d3462009-04-24 21:10:55 +0000460 = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d)));
461 if (!Result.second.Method) {
462 // This is the first method, which is the easy case.
463 Result.second.Method = Method;
464 Prev = &Result.second;
465 continue;
466 }
467
Ted Kremenekda4abf12010-02-11 00:53:01 +0000468 ObjCMethodList *Mem =
469 Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>();
470 Prev->Next = new (Mem) ObjCMethodList(Method, 0);
Douglas Gregorc78d3462009-04-24 21:10:55 +0000471 Prev = Prev->Next;
472 }
473
474 return Result;
475 }
476};
Mike Stump11289f42009-09-09 15:08:12 +0000477
478} // end anonymous namespace
Douglas Gregorc78d3462009-04-24 21:10:55 +0000479
480/// \brief The on-disk hash table used for the global method pool.
Mike Stump11289f42009-09-09 15:08:12 +0000481typedef OnDiskChainedHashTable<PCHMethodPoolLookupTrait>
Douglas Gregorc78d3462009-04-24 21:10:55 +0000482 PCHMethodPoolLookupTable;
483
484namespace {
Benjamin Kramer16634c22009-11-28 10:07:24 +0000485class PCHIdentifierLookupTrait {
Douglas Gregora868bbd2009-04-21 22:25:48 +0000486 PCHReader &Reader;
487
488 // If we know the IdentifierInfo in advance, it is here and we will
489 // not build a new one. Used when deserializing information about an
490 // identifier that was constructed before the PCH file was read.
491 IdentifierInfo *KnownII;
492
493public:
494 typedef IdentifierInfo * data_type;
495
496 typedef const std::pair<const char*, unsigned> external_key_type;
497
498 typedef external_key_type internal_key_type;
499
Mike Stump11289f42009-09-09 15:08:12 +0000500 explicit PCHIdentifierLookupTrait(PCHReader &Reader, IdentifierInfo *II = 0)
Douglas Gregora868bbd2009-04-21 22:25:48 +0000501 : Reader(Reader), KnownII(II) { }
Mike Stump11289f42009-09-09 15:08:12 +0000502
Douglas Gregora868bbd2009-04-21 22:25:48 +0000503 static bool EqualKey(const internal_key_type& a,
504 const internal_key_type& b) {
505 return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0
506 : false;
507 }
Mike Stump11289f42009-09-09 15:08:12 +0000508
Douglas Gregora868bbd2009-04-21 22:25:48 +0000509 static unsigned ComputeHash(const internal_key_type& a) {
Daniel Dunbarf8502d52009-10-17 23:52:28 +0000510 return llvm::HashString(llvm::StringRef(a.first, a.second));
Douglas Gregora868bbd2009-04-21 22:25:48 +0000511 }
Mike Stump11289f42009-09-09 15:08:12 +0000512
Douglas Gregora868bbd2009-04-21 22:25:48 +0000513 // This hopefully will just get inlined and removed by the optimizer.
514 static const internal_key_type&
515 GetInternalKey(const external_key_type& x) { return x; }
Mike Stump11289f42009-09-09 15:08:12 +0000516
Douglas Gregora868bbd2009-04-21 22:25:48 +0000517 static std::pair<unsigned, unsigned>
518 ReadKeyDataLength(const unsigned char*& d) {
519 using namespace clang::io;
Douglas Gregor6b7bf5a2009-04-25 20:26:24 +0000520 unsigned DataLen = ReadUnalignedLE16(d);
Douglas Gregor5287b4e2009-04-25 21:04:17 +0000521 unsigned KeyLen = ReadUnalignedLE16(d);
Douglas Gregora868bbd2009-04-21 22:25:48 +0000522 return std::make_pair(KeyLen, DataLen);
523 }
Mike Stump11289f42009-09-09 15:08:12 +0000524
Douglas Gregora868bbd2009-04-21 22:25:48 +0000525 static std::pair<const char*, unsigned>
526 ReadKey(const unsigned char* d, unsigned n) {
527 assert(n >= 2 && d[n-1] == '\0');
528 return std::make_pair((const char*) d, n-1);
529 }
Mike Stump11289f42009-09-09 15:08:12 +0000530
531 IdentifierInfo *ReadData(const internal_key_type& k,
Douglas Gregora868bbd2009-04-21 22:25:48 +0000532 const unsigned char* d,
533 unsigned DataLen) {
534 using namespace clang::io;
Douglas Gregor1d583f22009-04-28 21:18:29 +0000535 pch::IdentID ID = ReadUnalignedLE32(d);
536 bool IsInteresting = ID & 0x01;
537
538 // Wipe out the "is interesting" bit.
539 ID = ID >> 1;
540
541 if (!IsInteresting) {
542 // For unintersting identifiers, just build the IdentifierInfo
543 // and associate it with the persistent ID.
544 IdentifierInfo *II = KnownII;
545 if (!II)
546 II = &Reader.getIdentifierTable().CreateIdentifierInfo(
547 k.first, k.first + k.second);
548 Reader.SetIdentifierInfo(ID, II);
549 return II;
550 }
551
Douglas Gregorb9256522009-04-28 21:32:13 +0000552 unsigned Bits = ReadUnalignedLE16(d);
Douglas Gregor4621c6a2009-04-22 18:49:13 +0000553 bool CPlusPlusOperatorKeyword = Bits & 0x01;
554 Bits >>= 1;
555 bool Poisoned = Bits & 0x01;
556 Bits >>= 1;
557 bool ExtensionToken = Bits & 0x01;
558 Bits >>= 1;
559 bool hasMacroDefinition = Bits & 0x01;
560 Bits >>= 1;
561 unsigned ObjCOrBuiltinID = Bits & 0x3FF;
562 Bits >>= 10;
Mike Stump11289f42009-09-09 15:08:12 +0000563
Douglas Gregor4621c6a2009-04-22 18:49:13 +0000564 assert(Bits == 0 && "Extra bits in the identifier?");
Douglas Gregorb9256522009-04-28 21:32:13 +0000565 DataLen -= 6;
Douglas Gregora868bbd2009-04-21 22:25:48 +0000566
567 // Build the IdentifierInfo itself and link the identifier ID with
568 // the new IdentifierInfo.
569 IdentifierInfo *II = KnownII;
570 if (!II)
Douglas Gregor6b7bf5a2009-04-25 20:26:24 +0000571 II = &Reader.getIdentifierTable().CreateIdentifierInfo(
572 k.first, k.first + k.second);
Douglas Gregora868bbd2009-04-21 22:25:48 +0000573 Reader.SetIdentifierInfo(ID, II);
574
Douglas Gregor4621c6a2009-04-22 18:49:13 +0000575 // Set or check the various bits in the IdentifierInfo structure.
576 // FIXME: Load token IDs lazily, too?
Douglas Gregor4621c6a2009-04-22 18:49:13 +0000577 II->setObjCOrBuiltinID(ObjCOrBuiltinID);
Mike Stump11289f42009-09-09 15:08:12 +0000578 assert(II->isExtensionToken() == ExtensionToken &&
Douglas Gregor4621c6a2009-04-22 18:49:13 +0000579 "Incorrect extension token flag");
580 (void)ExtensionToken;
581 II->setIsPoisoned(Poisoned);
582 assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword &&
583 "Incorrect C++ operator keyword flag");
584 (void)CPlusPlusOperatorKeyword;
585
Douglas Gregorc3366a52009-04-21 23:56:24 +0000586 // If this identifier is a macro, deserialize the macro
587 // definition.
588 if (hasMacroDefinition) {
Douglas Gregorb9256522009-04-28 21:32:13 +0000589 uint32_t Offset = ReadUnalignedLE32(d);
Douglas Gregorc3366a52009-04-21 23:56:24 +0000590 Reader.ReadMacroRecord(Offset);
Douglas Gregorb9256522009-04-28 21:32:13 +0000591 DataLen -= 4;
Douglas Gregorc3366a52009-04-21 23:56:24 +0000592 }
Douglas Gregora868bbd2009-04-21 22:25:48 +0000593
594 // Read all of the declarations visible at global scope with this
595 // name.
Chris Lattner1d728882009-04-27 22:17:41 +0000596 if (Reader.getContext() == 0) return II;
Douglas Gregor1342e842009-07-06 18:54:52 +0000597 if (DataLen > 0) {
598 llvm::SmallVector<uint32_t, 4> DeclIDs;
599 for (; DataLen > 0; DataLen -= 4)
600 DeclIDs.push_back(ReadUnalignedLE32(d));
601 Reader.SetGloballyVisibleDecls(II, DeclIDs);
Douglas Gregora868bbd2009-04-21 22:25:48 +0000602 }
Mike Stump11289f42009-09-09 15:08:12 +0000603
Douglas Gregora868bbd2009-04-21 22:25:48 +0000604 return II;
605 }
606};
Mike Stump11289f42009-09-09 15:08:12 +0000607
608} // end anonymous namespace
Douglas Gregora868bbd2009-04-21 22:25:48 +0000609
610/// \brief The on-disk hash table used to contain information about
611/// all of the identifiers in the program.
Mike Stump11289f42009-09-09 15:08:12 +0000612typedef OnDiskChainedHashTable<PCHIdentifierLookupTrait>
Douglas Gregora868bbd2009-04-21 22:25:48 +0000613 PCHIdentifierLookupTable;
614
Ted Kremenek1ff615c2010-03-18 00:56:54 +0000615void PCHReader::Error(const char *Msg) {
616 Diag(diag::err_fe_pch_malformed) << Msg;
Douglas Gregoref84c4b2009-04-09 22:27:44 +0000617}
618
Douglas Gregor92863e42009-04-10 23:10:45 +0000619/// \brief Check the contents of the predefines buffer against the
620/// contents of the predefines buffer used to build the PCH file.
621///
622/// The contents of the two predefines buffers should be the same. If
623/// not, then some command-line option changed the preprocessor state
624/// and we must reject the PCH file.
625///
626/// \param PCHPredef The start of the predefines buffer in the PCH
627/// file.
628///
629/// \param PCHPredefLen The length of the predefines buffer in the PCH
630/// file.
631///
632/// \param PCHBufferID The FileID for the PCH predefines buffer.
633///
634/// \returns true if there was a mismatch (in which case the PCH file
635/// should be ignored), or false otherwise.
Daniel Dunbar20a682d2009-11-11 00:52:11 +0000636bool PCHReader::CheckPredefinesBuffer(llvm::StringRef PCHPredef,
Douglas Gregor92863e42009-04-10 23:10:45 +0000637 FileID PCHBufferID) {
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000638 if (Listener)
Daniel Dunbar20a682d2009-11-11 00:52:11 +0000639 return Listener->ReadPredefinesBuffer(PCHPredef, PCHBufferID,
Daniel Dunbar000c4ff2009-11-11 05:29:04 +0000640 ActualOriginalFileName,
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +0000641 SuggestedPredefines);
Douglas Gregorc379c072009-04-28 18:58:38 +0000642 return false;
Douglas Gregor92863e42009-04-10 23:10:45 +0000643}
644
Douglas Gregorc5046832009-04-27 18:38:38 +0000645//===----------------------------------------------------------------------===//
646// Source Manager Deserialization
647//===----------------------------------------------------------------------===//
648
Douglas Gregor4c7626e2009-04-13 16:31:14 +0000649/// \brief Read the line table in the source manager block.
650/// \returns true if ther was an error.
Douglas Gregor0086a5a2009-07-07 00:12:59 +0000651bool PCHReader::ParseLineTable(llvm::SmallVectorImpl<uint64_t> &Record) {
Douglas Gregor4c7626e2009-04-13 16:31:14 +0000652 unsigned Idx = 0;
653 LineTableInfo &LineTable = SourceMgr.getLineTable();
654
655 // Parse the file names
Douglas Gregora8854652009-04-13 17:12:42 +0000656 std::map<int, int> FileIDs;
657 for (int I = 0, N = Record[Idx++]; I != N; ++I) {
Douglas Gregor4c7626e2009-04-13 16:31:14 +0000658 // Extract the file name
659 unsigned FilenameLen = Record[Idx++];
660 std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen);
661 Idx += FilenameLen;
Douglas Gregor0086a5a2009-07-07 00:12:59 +0000662 MaybeAddSystemRootToFilename(Filename);
Mike Stump11289f42009-09-09 15:08:12 +0000663 FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(),
Douglas Gregora8854652009-04-13 17:12:42 +0000664 Filename.size());
Douglas Gregor4c7626e2009-04-13 16:31:14 +0000665 }
666
667 // Parse the line entries
668 std::vector<LineEntry> Entries;
669 while (Idx < Record.size()) {
Douglas Gregora8854652009-04-13 17:12:42 +0000670 int FID = FileIDs[Record[Idx++]];
Douglas Gregor4c7626e2009-04-13 16:31:14 +0000671
672 // Extract the line entries
673 unsigned NumEntries = Record[Idx++];
674 Entries.clear();
675 Entries.reserve(NumEntries);
676 for (unsigned I = 0; I != NumEntries; ++I) {
677 unsigned FileOffset = Record[Idx++];
678 unsigned LineNo = Record[Idx++];
679 int FilenameID = Record[Idx++];
Mike Stump11289f42009-09-09 15:08:12 +0000680 SrcMgr::CharacteristicKind FileKind
Douglas Gregor4c7626e2009-04-13 16:31:14 +0000681 = (SrcMgr::CharacteristicKind)Record[Idx++];
682 unsigned IncludeOffset = Record[Idx++];
683 Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID,
684 FileKind, IncludeOffset));
685 }
686 LineTable.AddEntry(FID, Entries);
687 }
688
689 return false;
690}
691
Douglas Gregorc5046832009-04-27 18:38:38 +0000692namespace {
693
Benjamin Kramer16634c22009-11-28 10:07:24 +0000694class PCHStatData {
Douglas Gregorc5046832009-04-27 18:38:38 +0000695public:
696 const bool hasStat;
697 const ino_t ino;
698 const dev_t dev;
699 const mode_t mode;
700 const time_t mtime;
701 const off_t size;
Mike Stump11289f42009-09-09 15:08:12 +0000702
Douglas Gregorc5046832009-04-27 18:38:38 +0000703 PCHStatData(ino_t i, dev_t d, mode_t mo, time_t m, off_t s)
Mike Stump11289f42009-09-09 15:08:12 +0000704 : hasStat(true), ino(i), dev(d), mode(mo), mtime(m), size(s) {}
705
Douglas Gregorc5046832009-04-27 18:38:38 +0000706 PCHStatData()
707 : hasStat(false), ino(0), dev(0), mode(0), mtime(0), size(0) {}
708};
709
Benjamin Kramer16634c22009-11-28 10:07:24 +0000710class PCHStatLookupTrait {
Douglas Gregorc5046832009-04-27 18:38:38 +0000711 public:
712 typedef const char *external_key_type;
713 typedef const char *internal_key_type;
714
715 typedef PCHStatData data_type;
716
717 static unsigned ComputeHash(const char *path) {
Daniel Dunbarf8502d52009-10-17 23:52:28 +0000718 return llvm::HashString(path);
Douglas Gregorc5046832009-04-27 18:38:38 +0000719 }
720
721 static internal_key_type GetInternalKey(const char *path) { return path; }
722
723 static bool EqualKey(internal_key_type a, internal_key_type b) {
724 return strcmp(a, b) == 0;
725 }
726
727 static std::pair<unsigned, unsigned>
728 ReadKeyDataLength(const unsigned char*& d) {
729 unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d);
730 unsigned DataLen = (unsigned) *d++;
731 return std::make_pair(KeyLen + 1, DataLen);
732 }
733
734 static internal_key_type ReadKey(const unsigned char *d, unsigned) {
735 return (const char *)d;
736 }
737
738 static data_type ReadData(const internal_key_type, const unsigned char *d,
739 unsigned /*DataLen*/) {
740 using namespace clang::io;
741
742 if (*d++ == 1)
743 return data_type();
744
745 ino_t ino = (ino_t) ReadUnalignedLE32(d);
746 dev_t dev = (dev_t) ReadUnalignedLE32(d);
747 mode_t mode = (mode_t) ReadUnalignedLE16(d);
Mike Stump11289f42009-09-09 15:08:12 +0000748 time_t mtime = (time_t) ReadUnalignedLE64(d);
Douglas Gregorc5046832009-04-27 18:38:38 +0000749 off_t size = (off_t) ReadUnalignedLE64(d);
750 return data_type(ino, dev, mode, mtime, size);
751 }
752};
753
754/// \brief stat() cache for precompiled headers.
755///
756/// This cache is very similar to the stat cache used by pretokenized
757/// headers.
Benjamin Kramer16634c22009-11-28 10:07:24 +0000758class PCHStatCache : public StatSysCallCache {
Douglas Gregorc5046832009-04-27 18:38:38 +0000759 typedef OnDiskChainedHashTable<PCHStatLookupTrait> CacheTy;
760 CacheTy *Cache;
761
762 unsigned &NumStatHits, &NumStatMisses;
Mike Stump11289f42009-09-09 15:08:12 +0000763public:
Douglas Gregorc5046832009-04-27 18:38:38 +0000764 PCHStatCache(const unsigned char *Buckets,
765 const unsigned char *Base,
766 unsigned &NumStatHits,
Mike Stump11289f42009-09-09 15:08:12 +0000767 unsigned &NumStatMisses)
Douglas Gregorc5046832009-04-27 18:38:38 +0000768 : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) {
769 Cache = CacheTy::Create(Buckets, Base);
770 }
771
772 ~PCHStatCache() { delete Cache; }
Mike Stump11289f42009-09-09 15:08:12 +0000773
Douglas Gregorc5046832009-04-27 18:38:38 +0000774 int stat(const char *path, struct stat *buf) {
775 // Do the lookup for the file's data in the PCH file.
776 CacheTy::iterator I = Cache->find(path);
777
778 // If we don't get a hit in the PCH file just forward to 'stat'.
779 if (I == Cache->end()) {
780 ++NumStatMisses;
Douglas Gregord2eb58a2009-10-16 18:18:30 +0000781 return StatSysCallCache::stat(path, buf);
Douglas Gregorc5046832009-04-27 18:38:38 +0000782 }
Mike Stump11289f42009-09-09 15:08:12 +0000783
Douglas Gregorc5046832009-04-27 18:38:38 +0000784 ++NumStatHits;
785 PCHStatData Data = *I;
Mike Stump11289f42009-09-09 15:08:12 +0000786
Douglas Gregorc5046832009-04-27 18:38:38 +0000787 if (!Data.hasStat)
788 return 1;
789
790 buf->st_ino = Data.ino;
791 buf->st_dev = Data.dev;
792 buf->st_mtime = Data.mtime;
793 buf->st_mode = Data.mode;
794 buf->st_size = Data.size;
795 return 0;
796 }
797};
798} // end anonymous namespace
799
800
Douglas Gregora7f71a92009-04-10 03:52:48 +0000801/// \brief Read the source manager block
Douglas Gregor92863e42009-04-10 23:10:45 +0000802PCHReader::PCHReadResult PCHReader::ReadSourceManagerBlock() {
Douglas Gregora7f71a92009-04-10 03:52:48 +0000803 using namespace SrcMgr;
Douglas Gregor258ae542009-04-27 06:38:32 +0000804
805 // Set the source-location entry cursor to the current position in
806 // the stream. This cursor will be used to read the contents of the
807 // source manager block initially, and then lazily read
808 // source-location entries as needed.
809 SLocEntryCursor = Stream;
810
811 // The stream itself is going to skip over the source manager block.
812 if (Stream.SkipBlock()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +0000813 Error("malformed block record in PCH file");
Douglas Gregor258ae542009-04-27 06:38:32 +0000814 return Failure;
815 }
816
817 // Enter the source manager block.
818 if (SLocEntryCursor.EnterSubBlock(pch::SOURCE_MANAGER_BLOCK_ID)) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +0000819 Error("malformed source manager block record in PCH file");
Douglas Gregor92863e42009-04-10 23:10:45 +0000820 return Failure;
821 }
Douglas Gregora7f71a92009-04-10 03:52:48 +0000822
Douglas Gregora7f71a92009-04-10 03:52:48 +0000823 RecordData Record;
824 while (true) {
Douglas Gregor258ae542009-04-27 06:38:32 +0000825 unsigned Code = SLocEntryCursor.ReadCode();
Douglas Gregora7f71a92009-04-10 03:52:48 +0000826 if (Code == llvm::bitc::END_BLOCK) {
Douglas Gregor258ae542009-04-27 06:38:32 +0000827 if (SLocEntryCursor.ReadBlockEnd()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +0000828 Error("error at end of Source Manager block in PCH file");
Douglas Gregor92863e42009-04-10 23:10:45 +0000829 return Failure;
830 }
Douglas Gregor92863e42009-04-10 23:10:45 +0000831 return Success;
Douglas Gregora7f71a92009-04-10 03:52:48 +0000832 }
Mike Stump11289f42009-09-09 15:08:12 +0000833
Douglas Gregora7f71a92009-04-10 03:52:48 +0000834 if (Code == llvm::bitc::ENTER_SUBBLOCK) {
835 // No known subblocks, always skip them.
Douglas Gregor258ae542009-04-27 06:38:32 +0000836 SLocEntryCursor.ReadSubBlockID();
837 if (SLocEntryCursor.SkipBlock()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +0000838 Error("malformed block record in PCH file");
Douglas Gregor92863e42009-04-10 23:10:45 +0000839 return Failure;
840 }
Douglas Gregora7f71a92009-04-10 03:52:48 +0000841 continue;
842 }
Mike Stump11289f42009-09-09 15:08:12 +0000843
Douglas Gregora7f71a92009-04-10 03:52:48 +0000844 if (Code == llvm::bitc::DEFINE_ABBREV) {
Douglas Gregor258ae542009-04-27 06:38:32 +0000845 SLocEntryCursor.ReadAbbrevRecord();
Douglas Gregora7f71a92009-04-10 03:52:48 +0000846 continue;
847 }
Mike Stump11289f42009-09-09 15:08:12 +0000848
Douglas Gregora7f71a92009-04-10 03:52:48 +0000849 // Read a record.
850 const char *BlobStart;
851 unsigned BlobLen;
852 Record.clear();
Douglas Gregor258ae542009-04-27 06:38:32 +0000853 switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) {
Douglas Gregora7f71a92009-04-10 03:52:48 +0000854 default: // Default behavior: ignore.
855 break;
856
Chris Lattner184e65d2009-04-14 23:22:57 +0000857 case pch::SM_LINE_TABLE:
Douglas Gregor0086a5a2009-07-07 00:12:59 +0000858 if (ParseLineTable(Record))
Douglas Gregor4c7626e2009-04-13 16:31:14 +0000859 return Failure;
Chris Lattner184e65d2009-04-14 23:22:57 +0000860 break;
Douglas Gregoreda6a892009-04-26 00:07:37 +0000861
Douglas Gregor258ae542009-04-27 06:38:32 +0000862 case pch::SM_SLOC_FILE_ENTRY:
863 case pch::SM_SLOC_BUFFER_ENTRY:
864 case pch::SM_SLOC_INSTANTIATION_ENTRY:
865 // Once we hit one of the source location entries, we're done.
866 return Success;
Douglas Gregora7f71a92009-04-10 03:52:48 +0000867 }
868 }
869}
870
Douglas Gregor258ae542009-04-27 06:38:32 +0000871/// \brief Read in the source location entry with the given ID.
872PCHReader::PCHReadResult PCHReader::ReadSLocEntryRecord(unsigned ID) {
873 if (ID == 0)
874 return Success;
875
876 if (ID > TotalNumSLocEntries) {
877 Error("source location entry ID out-of-range for PCH file");
878 return Failure;
879 }
880
881 ++NumSLocEntriesRead;
882 SLocEntryCursor.JumpToBit(SLocOffsets[ID - 1]);
883 unsigned Code = SLocEntryCursor.ReadCode();
884 if (Code == llvm::bitc::END_BLOCK ||
885 Code == llvm::bitc::ENTER_SUBBLOCK ||
886 Code == llvm::bitc::DEFINE_ABBREV) {
887 Error("incorrectly-formatted source location entry in PCH file");
888 return Failure;
889 }
890
Douglas Gregor258ae542009-04-27 06:38:32 +0000891 RecordData Record;
892 const char *BlobStart;
893 unsigned BlobLen;
894 switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) {
895 default:
896 Error("incorrectly-formatted source location entry in PCH file");
897 return Failure;
898
899 case pch::SM_SLOC_FILE_ENTRY: {
Douglas Gregor0086a5a2009-07-07 00:12:59 +0000900 std::string Filename(BlobStart, BlobStart + BlobLen);
901 MaybeAddSystemRootToFilename(Filename);
902 const FileEntry *File = FileMgr.getFile(Filename);
Chris Lattnerd20dc872009-06-15 04:35:16 +0000903 if (File == 0) {
904 std::string ErrorStr = "could not find file '";
Douglas Gregor0086a5a2009-07-07 00:12:59 +0000905 ErrorStr += Filename;
Chris Lattnerd20dc872009-06-15 04:35:16 +0000906 ErrorStr += "' referenced by PCH file";
907 Error(ErrorStr.c_str());
908 return Failure;
909 }
Mike Stump11289f42009-09-09 15:08:12 +0000910
Douglas Gregorb41ca8f2010-03-21 22:49:54 +0000911 if (Record.size() < 10) {
Ted Kremenekabb1ddd2010-03-18 21:23:05 +0000912 Error("source location entry is incorrect");
913 return Failure;
914 }
915
Douglas Gregor08288f22010-04-09 15:54:22 +0000916 if ((off_t)Record[4] != File->getSize()
917#if !defined(LLVM_ON_WIN32)
918 // In our regression testing, the Windows file system seems to
919 // have inconsistent modification times that sometimes
920 // erroneously trigger this error-handling path.
921 || (time_t)Record[5] != File->getModificationTime()
922#endif
923 ) {
Douglas Gregorb41ca8f2010-03-21 22:49:54 +0000924 Diag(diag::err_fe_pch_file_modified)
925 << Filename;
926 return Failure;
927 }
928
Douglas Gregor258ae542009-04-27 06:38:32 +0000929 FileID FID = SourceMgr.createFileID(File,
930 SourceLocation::getFromRawEncoding(Record[1]),
931 (SrcMgr::CharacteristicKind)Record[2],
932 ID, Record[0]);
933 if (Record[3])
934 const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile())
935 .setHasLineDirectives();
936
Douglas Gregor5712ebc2010-03-16 16:35:32 +0000937 // Reconstruct header-search information for this file.
938 HeaderFileInfo HFI;
Douglas Gregorb41ca8f2010-03-21 22:49:54 +0000939 HFI.isImport = Record[6];
940 HFI.DirInfo = Record[7];
941 HFI.NumIncludes = Record[8];
942 HFI.ControllingMacroID = Record[9];
Douglas Gregor5712ebc2010-03-16 16:35:32 +0000943 if (Listener)
944 Listener->ReadHeaderFileInfo(HFI, File->getUID());
Douglas Gregor258ae542009-04-27 06:38:32 +0000945 break;
946 }
947
948 case pch::SM_SLOC_BUFFER_ENTRY: {
949 const char *Name = BlobStart;
950 unsigned Offset = Record[0];
951 unsigned Code = SLocEntryCursor.ReadCode();
952 Record.clear();
Mike Stump11289f42009-09-09 15:08:12 +0000953 unsigned RecCode
Douglas Gregor258ae542009-04-27 06:38:32 +0000954 = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen);
Ted Kremenek1ff615c2010-03-18 00:56:54 +0000955
956 if (RecCode != pch::SM_SLOC_BUFFER_BLOB) {
957 Error("PCH record has invalid code");
958 return Failure;
959 }
960
Douglas Gregor258ae542009-04-27 06:38:32 +0000961 llvm::MemoryBuffer *Buffer
Chris Lattner58c79342010-04-05 22:42:27 +0000962 = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1),
963 Name);
Douglas Gregor258ae542009-04-27 06:38:32 +0000964 FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset);
Mike Stump11289f42009-09-09 15:08:12 +0000965
Douglas Gregore6648fb2009-04-28 20:33:11 +0000966 if (strcmp(Name, "<built-in>") == 0) {
967 PCHPredefinesBufferID = BufferID;
968 PCHPredefines = BlobStart;
969 PCHPredefinesLen = BlobLen - 1;
970 }
Douglas Gregor258ae542009-04-27 06:38:32 +0000971
972 break;
973 }
974
975 case pch::SM_SLOC_INSTANTIATION_ENTRY: {
Mike Stump11289f42009-09-09 15:08:12 +0000976 SourceLocation SpellingLoc
Douglas Gregor258ae542009-04-27 06:38:32 +0000977 = SourceLocation::getFromRawEncoding(Record[1]);
978 SourceMgr.createInstantiationLoc(SpellingLoc,
979 SourceLocation::getFromRawEncoding(Record[2]),
980 SourceLocation::getFromRawEncoding(Record[3]),
981 Record[4],
982 ID,
983 Record[0]);
984 break;
Mike Stump11289f42009-09-09 15:08:12 +0000985 }
Douglas Gregor258ae542009-04-27 06:38:32 +0000986 }
987
988 return Success;
989}
990
Chris Lattnere78a6be2009-04-27 01:05:14 +0000991/// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
992/// specified cursor. Read the abbreviations that are at the top of the block
993/// and then leave the cursor pointing into the block.
994bool PCHReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor,
995 unsigned BlockID) {
996 if (Cursor.EnterSubBlock(BlockID)) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +0000997 Error("malformed block record in PCH file");
Chris Lattnere78a6be2009-04-27 01:05:14 +0000998 return Failure;
999 }
Mike Stump11289f42009-09-09 15:08:12 +00001000
Chris Lattnere78a6be2009-04-27 01:05:14 +00001001 while (true) {
1002 unsigned Code = Cursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +00001003
Chris Lattnere78a6be2009-04-27 01:05:14 +00001004 // We expect all abbrevs to be at the start of the block.
1005 if (Code != llvm::bitc::DEFINE_ABBREV)
1006 return false;
1007 Cursor.ReadAbbrevRecord();
1008 }
1009}
1010
Douglas Gregorc3366a52009-04-21 23:56:24 +00001011void PCHReader::ReadMacroRecord(uint64_t Offset) {
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001012 assert(PP && "Forgot to set Preprocessor ?");
Mike Stump11289f42009-09-09 15:08:12 +00001013
Douglas Gregorc3366a52009-04-21 23:56:24 +00001014 // Keep track of where we are in the stream, then jump back there
1015 // after reading this macro.
1016 SavedStreamPosition SavedPosition(Stream);
1017
1018 Stream.JumpToBit(Offset);
1019 RecordData Record;
1020 llvm::SmallVector<IdentifierInfo*, 16> MacroArgs;
1021 MacroInfo *Macro = 0;
Mike Stump11289f42009-09-09 15:08:12 +00001022
Douglas Gregorc3366a52009-04-21 23:56:24 +00001023 while (true) {
1024 unsigned Code = Stream.ReadCode();
1025 switch (Code) {
1026 case llvm::bitc::END_BLOCK:
1027 return;
1028
1029 case llvm::bitc::ENTER_SUBBLOCK:
1030 // No known subblocks, always skip them.
1031 Stream.ReadSubBlockID();
1032 if (Stream.SkipBlock()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001033 Error("malformed block record in PCH file");
Douglas Gregorc3366a52009-04-21 23:56:24 +00001034 return;
1035 }
1036 continue;
Mike Stump11289f42009-09-09 15:08:12 +00001037
Douglas Gregorc3366a52009-04-21 23:56:24 +00001038 case llvm::bitc::DEFINE_ABBREV:
1039 Stream.ReadAbbrevRecord();
1040 continue;
1041 default: break;
1042 }
1043
1044 // Read a record.
1045 Record.clear();
1046 pch::PreprocessorRecordTypes RecType =
1047 (pch::PreprocessorRecordTypes)Stream.ReadRecord(Code, Record);
1048 switch (RecType) {
Douglas Gregorc3366a52009-04-21 23:56:24 +00001049 case pch::PP_MACRO_OBJECT_LIKE:
1050 case pch::PP_MACRO_FUNCTION_LIKE: {
1051 // If we already have a macro, that means that we've hit the end
1052 // of the definition of the macro we were looking for. We're
1053 // done.
1054 if (Macro)
1055 return;
1056
1057 IdentifierInfo *II = DecodeIdentifierInfo(Record[0]);
1058 if (II == 0) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001059 Error("macro must have a name in PCH file");
Douglas Gregorc3366a52009-04-21 23:56:24 +00001060 return;
1061 }
1062 SourceLocation Loc = SourceLocation::getFromRawEncoding(Record[1]);
1063 bool isUsed = Record[2];
Mike Stump11289f42009-09-09 15:08:12 +00001064
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001065 MacroInfo *MI = PP->AllocateMacroInfo(Loc);
Douglas Gregorc3366a52009-04-21 23:56:24 +00001066 MI->setIsUsed(isUsed);
Mike Stump11289f42009-09-09 15:08:12 +00001067
Douglas Gregoraae92242010-03-19 21:51:54 +00001068 unsigned NextIndex = 3;
Douglas Gregorc3366a52009-04-21 23:56:24 +00001069 if (RecType == pch::PP_MACRO_FUNCTION_LIKE) {
1070 // Decode function-like macro info.
1071 bool isC99VarArgs = Record[3];
1072 bool isGNUVarArgs = Record[4];
1073 MacroArgs.clear();
1074 unsigned NumArgs = Record[5];
Douglas Gregoraae92242010-03-19 21:51:54 +00001075 NextIndex = 6 + NumArgs;
Douglas Gregorc3366a52009-04-21 23:56:24 +00001076 for (unsigned i = 0; i != NumArgs; ++i)
1077 MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i]));
1078
1079 // Install function-like macro info.
1080 MI->setIsFunctionLike();
1081 if (isC99VarArgs) MI->setIsC99Varargs();
1082 if (isGNUVarArgs) MI->setIsGNUVarargs();
Douglas Gregor038c3382009-05-22 22:45:36 +00001083 MI->setArgumentList(MacroArgs.data(), MacroArgs.size(),
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001084 PP->getPreprocessorAllocator());
Douglas Gregorc3366a52009-04-21 23:56:24 +00001085 }
1086
1087 // Finally, install the macro.
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001088 PP->setMacroInfo(II, MI);
Douglas Gregorc3366a52009-04-21 23:56:24 +00001089
1090 // Remember that we saw this macro last so that we add the tokens that
1091 // form its body to it.
1092 Macro = MI;
Douglas Gregoraae92242010-03-19 21:51:54 +00001093
1094 if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) {
1095 // We have a macro definition. Load it now.
1096 PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro,
1097 getMacroDefinition(Record[NextIndex]));
1098 }
1099
Douglas Gregorc3366a52009-04-21 23:56:24 +00001100 ++NumMacrosRead;
1101 break;
1102 }
Mike Stump11289f42009-09-09 15:08:12 +00001103
Douglas Gregorc3366a52009-04-21 23:56:24 +00001104 case pch::PP_TOKEN: {
1105 // If we see a TOKEN before a PP_MACRO_*, then the file is
1106 // erroneous, just pretend we didn't see this.
1107 if (Macro == 0) break;
Mike Stump11289f42009-09-09 15:08:12 +00001108
Douglas Gregorc3366a52009-04-21 23:56:24 +00001109 Token Tok;
1110 Tok.startToken();
1111 Tok.setLocation(SourceLocation::getFromRawEncoding(Record[0]));
1112 Tok.setLength(Record[1]);
1113 if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2]))
1114 Tok.setIdentifierInfo(II);
1115 Tok.setKind((tok::TokenKind)Record[3]);
1116 Tok.setFlag((Token::TokenFlags)Record[4]);
1117 Macro->AddTokenToBody(Tok);
1118 break;
1119 }
Douglas Gregoraae92242010-03-19 21:51:54 +00001120
1121 case pch::PP_MACRO_INSTANTIATION: {
1122 // If we already have a macro, that means that we've hit the end
1123 // of the definition of the macro we were looking for. We're
1124 // done.
1125 if (Macro)
1126 return;
1127
1128 if (!PP->getPreprocessingRecord()) {
1129 Error("missing preprocessing record in PCH file");
1130 return;
1131 }
1132
1133 PreprocessingRecord &PPRec = *PP->getPreprocessingRecord();
1134 if (PPRec.getPreprocessedEntity(Record[0]))
1135 return;
1136
1137 MacroInstantiation *MI
1138 = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]),
1139 SourceRange(
1140 SourceLocation::getFromRawEncoding(Record[1]),
1141 SourceLocation::getFromRawEncoding(Record[2])),
1142 getMacroDefinition(Record[4]));
1143 PPRec.SetPreallocatedEntity(Record[0], MI);
1144 return;
1145 }
1146
1147 case pch::PP_MACRO_DEFINITION: {
1148 // If we already have a macro, that means that we've hit the end
1149 // of the definition of the macro we were looking for. We're
1150 // done.
1151 if (Macro)
1152 return;
1153
1154 if (!PP->getPreprocessingRecord()) {
1155 Error("missing preprocessing record in PCH file");
1156 return;
1157 }
1158
1159 PreprocessingRecord &PPRec = *PP->getPreprocessingRecord();
1160 if (PPRec.getPreprocessedEntity(Record[0]))
1161 return;
1162
1163 if (Record[1] >= MacroDefinitionsLoaded.size()) {
1164 Error("out-of-bounds macro definition record");
1165 return;
1166 }
1167
1168 MacroDefinition *MD
1169 = new (PPRec) MacroDefinition(DecodeIdentifierInfo(Record[4]),
1170 SourceLocation::getFromRawEncoding(Record[5]),
1171 SourceRange(
1172 SourceLocation::getFromRawEncoding(Record[2]),
1173 SourceLocation::getFromRawEncoding(Record[3])));
1174 PPRec.SetPreallocatedEntity(Record[0], MD);
1175 MacroDefinitionsLoaded[Record[1]] = MD;
1176 return;
1177 }
Steve Naroff3fa455a2009-04-24 20:03:17 +00001178 }
Douglas Gregorc3366a52009-04-21 23:56:24 +00001179 }
1180}
1181
Douglas Gregor9882a5a2010-01-04 19:18:44 +00001182void PCHReader::ReadDefinedMacros() {
1183 // If there was no preprocessor block, do nothing.
1184 if (!MacroCursor.getBitStreamReader())
1185 return;
Kovarththanan Rajaratnam39f2fbd12010-03-07 19:10:13 +00001186
Douglas Gregor9882a5a2010-01-04 19:18:44 +00001187 llvm::BitstreamCursor Cursor = MacroCursor;
1188 if (Cursor.EnterSubBlock(pch::PREPROCESSOR_BLOCK_ID)) {
1189 Error("malformed preprocessor block record in PCH file");
1190 return;
1191 }
Kovarththanan Rajaratnam39f2fbd12010-03-07 19:10:13 +00001192
Douglas Gregor9882a5a2010-01-04 19:18:44 +00001193 RecordData Record;
1194 while (true) {
1195 unsigned Code = Cursor.ReadCode();
1196 if (Code == llvm::bitc::END_BLOCK) {
1197 if (Cursor.ReadBlockEnd())
1198 Error("error at end of preprocessor block in PCH file");
1199 return;
1200 }
Kovarththanan Rajaratnam39f2fbd12010-03-07 19:10:13 +00001201
Douglas Gregor9882a5a2010-01-04 19:18:44 +00001202 if (Code == llvm::bitc::ENTER_SUBBLOCK) {
1203 // No known subblocks, always skip them.
1204 Cursor.ReadSubBlockID();
1205 if (Cursor.SkipBlock()) {
1206 Error("malformed block record in PCH file");
1207 return;
1208 }
1209 continue;
1210 }
Kovarththanan Rajaratnam39f2fbd12010-03-07 19:10:13 +00001211
Douglas Gregor9882a5a2010-01-04 19:18:44 +00001212 if (Code == llvm::bitc::DEFINE_ABBREV) {
1213 Cursor.ReadAbbrevRecord();
1214 continue;
1215 }
Kovarththanan Rajaratnam39f2fbd12010-03-07 19:10:13 +00001216
Douglas Gregor9882a5a2010-01-04 19:18:44 +00001217 // Read a record.
1218 const char *BlobStart;
1219 unsigned BlobLen;
1220 Record.clear();
1221 switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) {
1222 default: // Default behavior: ignore.
1223 break;
Kovarththanan Rajaratnam39f2fbd12010-03-07 19:10:13 +00001224
Douglas Gregor9882a5a2010-01-04 19:18:44 +00001225 case pch::PP_MACRO_OBJECT_LIKE:
1226 case pch::PP_MACRO_FUNCTION_LIKE:
Douglas Gregoraae92242010-03-19 21:51:54 +00001227 DecodeIdentifierInfo(Record[0]);
Douglas Gregor9882a5a2010-01-04 19:18:44 +00001228 break;
1229
1230 case pch::PP_TOKEN:
1231 // Ignore tokens.
1232 break;
Douglas Gregoraae92242010-03-19 21:51:54 +00001233
1234 case pch::PP_MACRO_INSTANTIATION:
1235 case pch::PP_MACRO_DEFINITION:
1236 // Read the macro record.
1237 ReadMacroRecord(Cursor.GetCurrentBitNo());
1238 break;
Douglas Gregor9882a5a2010-01-04 19:18:44 +00001239 }
1240 }
1241}
1242
Douglas Gregoraae92242010-03-19 21:51:54 +00001243MacroDefinition *PCHReader::getMacroDefinition(pch::IdentID ID) {
1244 if (ID == 0 || ID >= MacroDefinitionsLoaded.size())
1245 return 0;
1246
1247 if (!MacroDefinitionsLoaded[ID])
1248 ReadMacroRecord(MacroDefinitionOffsets[ID]);
1249
1250 return MacroDefinitionsLoaded[ID];
1251}
1252
Douglas Gregor0086a5a2009-07-07 00:12:59 +00001253/// \brief If we are loading a relocatable PCH file, and the filename is
1254/// not an absolute path, add the system root to the beginning of the file
1255/// name.
1256void PCHReader::MaybeAddSystemRootToFilename(std::string &Filename) {
1257 // If this is not a relocatable PCH file, there's nothing to do.
1258 if (!RelocatablePCH)
1259 return;
Mike Stump11289f42009-09-09 15:08:12 +00001260
Daniel Dunbarf2ce9a22009-11-18 19:50:41 +00001261 if (Filename.empty() || llvm::sys::Path(Filename).isAbsolute())
Douglas Gregor0086a5a2009-07-07 00:12:59 +00001262 return;
1263
Douglas Gregor0086a5a2009-07-07 00:12:59 +00001264 if (isysroot == 0) {
1265 // If no system root was given, default to '/'
1266 Filename.insert(Filename.begin(), '/');
1267 return;
1268 }
Mike Stump11289f42009-09-09 15:08:12 +00001269
Douglas Gregor0086a5a2009-07-07 00:12:59 +00001270 unsigned Length = strlen(isysroot);
1271 if (isysroot[Length - 1] != '/')
1272 Filename.insert(Filename.begin(), '/');
Mike Stump11289f42009-09-09 15:08:12 +00001273
Douglas Gregor0086a5a2009-07-07 00:12:59 +00001274 Filename.insert(Filename.begin(), isysroot, isysroot + Length);
1275}
1276
Mike Stump11289f42009-09-09 15:08:12 +00001277PCHReader::PCHReadResult
Douglas Gregoreda6a892009-04-26 00:07:37 +00001278PCHReader::ReadPCHBlock() {
Douglas Gregor55abb232009-04-10 20:39:37 +00001279 if (Stream.EnterSubBlock(pch::PCH_BLOCK_ID)) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001280 Error("malformed block record in PCH file");
Douglas Gregor55abb232009-04-10 20:39:37 +00001281 return Failure;
1282 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001283
1284 // Read all of the records and blocks for the PCH file.
Douglas Gregor1e9bf3b2009-04-10 17:25:41 +00001285 RecordData Record;
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001286 while (!Stream.AtEndOfStream()) {
1287 unsigned Code = Stream.ReadCode();
1288 if (Code == llvm::bitc::END_BLOCK) {
Douglas Gregor55abb232009-04-10 20:39:37 +00001289 if (Stream.ReadBlockEnd()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001290 Error("error at end of module block in PCH file");
Douglas Gregor55abb232009-04-10 20:39:37 +00001291 return Failure;
1292 }
Chris Lattnerc523d8e2009-04-11 21:15:38 +00001293
Douglas Gregor55abb232009-04-10 20:39:37 +00001294 return Success;
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001295 }
1296
1297 if (Code == llvm::bitc::ENTER_SUBBLOCK) {
1298 switch (Stream.ReadSubBlockID()) {
Douglas Gregor12bfa382009-10-17 00:13:19 +00001299 case pch::DECLTYPES_BLOCK_ID:
Chris Lattnere78a6be2009-04-27 01:05:14 +00001300 // We lazily load the decls block, but we want to set up the
1301 // DeclsCursor cursor to point into it. Clone our current bitcode
1302 // cursor to it, enter the block and read the abbrevs in that block.
1303 // With the main cursor, we just skip over it.
1304 DeclsCursor = Stream;
1305 if (Stream.SkipBlock() || // Skip with the main cursor.
1306 // Read the abbrevs.
Douglas Gregor12bfa382009-10-17 00:13:19 +00001307 ReadBlockAbbrevs(DeclsCursor, pch::DECLTYPES_BLOCK_ID)) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001308 Error("malformed block record in PCH file");
Chris Lattnere78a6be2009-04-27 01:05:14 +00001309 return Failure;
1310 }
1311 break;
Mike Stump11289f42009-09-09 15:08:12 +00001312
Chris Lattnerc523d8e2009-04-11 21:15:38 +00001313 case pch::PREPROCESSOR_BLOCK_ID:
Douglas Gregor9882a5a2010-01-04 19:18:44 +00001314 MacroCursor = Stream;
1315 if (PP)
1316 PP->setExternalSource(this);
1317
Chris Lattnerc523d8e2009-04-11 21:15:38 +00001318 if (Stream.SkipBlock()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001319 Error("malformed block record in PCH file");
Chris Lattnerc523d8e2009-04-11 21:15:38 +00001320 return Failure;
1321 }
1322 break;
Steve Naroff2ddea052009-04-23 10:39:46 +00001323
Douglas Gregora7f71a92009-04-10 03:52:48 +00001324 case pch::SOURCE_MANAGER_BLOCK_ID:
Douglas Gregor92863e42009-04-10 23:10:45 +00001325 switch (ReadSourceManagerBlock()) {
1326 case Success:
1327 break;
1328
1329 case Failure:
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001330 Error("malformed source manager block in PCH file");
Douglas Gregor55abb232009-04-10 20:39:37 +00001331 return Failure;
Douglas Gregor92863e42009-04-10 23:10:45 +00001332
1333 case IgnorePCH:
1334 return IgnorePCH;
Douglas Gregor55abb232009-04-10 20:39:37 +00001335 }
Douglas Gregora7f71a92009-04-10 03:52:48 +00001336 break;
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001337 }
Douglas Gregor1e9bf3b2009-04-10 17:25:41 +00001338 continue;
1339 }
1340
1341 if (Code == llvm::bitc::DEFINE_ABBREV) {
1342 Stream.ReadAbbrevRecord();
1343 continue;
1344 }
1345
1346 // Read and process a record.
1347 Record.clear();
Douglas Gregorbfbde532009-04-10 21:16:55 +00001348 const char *BlobStart = 0;
1349 unsigned BlobLen = 0;
Mike Stump11289f42009-09-09 15:08:12 +00001350 switch ((pch::PCHRecordTypes)Stream.ReadRecord(Code, Record,
Douglas Gregorbfbde532009-04-10 21:16:55 +00001351 &BlobStart, &BlobLen)) {
Douglas Gregor1e9bf3b2009-04-10 17:25:41 +00001352 default: // Default behavior: ignore.
1353 break;
1354
1355 case pch::TYPE_OFFSET:
Douglas Gregor745ed142009-04-25 18:35:21 +00001356 if (!TypesLoaded.empty()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001357 Error("duplicate TYPE_OFFSET record in PCH file");
Douglas Gregor55abb232009-04-10 20:39:37 +00001358 return Failure;
1359 }
Chris Lattnereeb05692009-04-27 18:24:17 +00001360 TypeOffsets = (const uint32_t *)BlobStart;
Douglas Gregor745ed142009-04-25 18:35:21 +00001361 TypesLoaded.resize(Record[0]);
Douglas Gregor1e9bf3b2009-04-10 17:25:41 +00001362 break;
1363
1364 case pch::DECL_OFFSET:
Douglas Gregor745ed142009-04-25 18:35:21 +00001365 if (!DeclsLoaded.empty()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001366 Error("duplicate DECL_OFFSET record in PCH file");
Douglas Gregor55abb232009-04-10 20:39:37 +00001367 return Failure;
1368 }
Chris Lattnereeb05692009-04-27 18:24:17 +00001369 DeclOffsets = (const uint32_t *)BlobStart;
Douglas Gregor745ed142009-04-25 18:35:21 +00001370 DeclsLoaded.resize(Record[0]);
Douglas Gregor1e9bf3b2009-04-10 17:25:41 +00001371 break;
Douglas Gregor55abb232009-04-10 20:39:37 +00001372
1373 case pch::LANGUAGE_OPTIONS:
1374 if (ParseLanguageOptions(Record))
1375 return IgnorePCH;
1376 break;
Douglas Gregorbfbde532009-04-10 21:16:55 +00001377
Douglas Gregor7b71e632009-04-27 22:23:34 +00001378 case pch::METADATA: {
1379 if (Record[0] != pch::VERSION_MAJOR) {
1380 Diag(Record[0] < pch::VERSION_MAJOR? diag::warn_pch_version_too_old
1381 : diag::warn_pch_version_too_new);
1382 return IgnorePCH;
1383 }
1384
Douglas Gregor0086a5a2009-07-07 00:12:59 +00001385 RelocatablePCH = Record[4];
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001386 if (Listener) {
1387 std::string TargetTriple(BlobStart, BlobLen);
1388 if (Listener->ReadTargetTriple(TargetTriple))
1389 return IgnorePCH;
Douglas Gregorbfbde532009-04-10 21:16:55 +00001390 }
1391 break;
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001392 }
Douglas Gregor3ed42cb2009-04-11 00:14:32 +00001393
1394 case pch::IDENTIFIER_TABLE:
Douglas Gregora868bbd2009-04-21 22:25:48 +00001395 IdentifierTableData = BlobStart;
Douglas Gregor0e149972009-04-25 19:10:14 +00001396 if (Record[0]) {
Mike Stump11289f42009-09-09 15:08:12 +00001397 IdentifierLookupTable
Douglas Gregor0e149972009-04-25 19:10:14 +00001398 = PCHIdentifierLookupTable::Create(
Douglas Gregora868bbd2009-04-21 22:25:48 +00001399 (const unsigned char *)IdentifierTableData + Record[0],
Mike Stump11289f42009-09-09 15:08:12 +00001400 (const unsigned char *)IdentifierTableData,
Douglas Gregora868bbd2009-04-21 22:25:48 +00001401 PCHIdentifierLookupTrait(*this));
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001402 if (PP)
1403 PP->getIdentifierTable().setExternalIdentifierLookup(this);
Douglas Gregor0e149972009-04-25 19:10:14 +00001404 }
Douglas Gregor3ed42cb2009-04-11 00:14:32 +00001405 break;
1406
1407 case pch::IDENTIFIER_OFFSET:
Douglas Gregor0e149972009-04-25 19:10:14 +00001408 if (!IdentifiersLoaded.empty()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001409 Error("duplicate IDENTIFIER_OFFSET record in PCH file");
Douglas Gregor3ed42cb2009-04-11 00:14:32 +00001410 return Failure;
1411 }
Douglas Gregor0e149972009-04-25 19:10:14 +00001412 IdentifierOffsets = (const uint32_t *)BlobStart;
1413 IdentifiersLoaded.resize(Record[0]);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001414 if (PP)
1415 PP->getHeaderSearchInfo().SetExternalLookup(this);
Douglas Gregor3ed42cb2009-04-11 00:14:32 +00001416 break;
Douglas Gregor1a0d0b92009-04-14 00:24:19 +00001417
1418 case pch::EXTERNAL_DEFINITIONS:
1419 if (!ExternalDefinitions.empty()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001420 Error("duplicate EXTERNAL_DEFINITIONS record in PCH file");
Douglas Gregor1a0d0b92009-04-14 00:24:19 +00001421 return Failure;
1422 }
1423 ExternalDefinitions.swap(Record);
1424 break;
Douglas Gregor08f01292009-04-17 22:13:46 +00001425
Douglas Gregor652d82a2009-04-18 05:55:16 +00001426 case pch::SPECIAL_TYPES:
1427 SpecialTypes.swap(Record);
1428 break;
1429
Douglas Gregor08f01292009-04-17 22:13:46 +00001430 case pch::STATISTICS:
1431 TotalNumStatements = Record[0];
Douglas Gregorc3366a52009-04-21 23:56:24 +00001432 TotalNumMacros = Record[1];
Douglas Gregora57c3ab2009-04-22 22:34:57 +00001433 TotalLexicalDeclContexts = Record[2];
1434 TotalVisibleDeclContexts = Record[3];
Douglas Gregor08f01292009-04-17 22:13:46 +00001435 break;
Douglas Gregor258ae542009-04-27 06:38:32 +00001436
Douglas Gregord4df8652009-04-22 22:02:47 +00001437 case pch::TENTATIVE_DEFINITIONS:
1438 if (!TentativeDefinitions.empty()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001439 Error("duplicate TENTATIVE_DEFINITIONS record in PCH file");
Douglas Gregord4df8652009-04-22 22:02:47 +00001440 return Failure;
1441 }
1442 TentativeDefinitions.swap(Record);
1443 break;
Douglas Gregoracfc76c2009-04-22 22:18:58 +00001444
Tanya Lattner90073802010-02-12 00:07:30 +00001445 case pch::UNUSED_STATIC_FUNCS:
1446 if (!UnusedStaticFuncs.empty()) {
1447 Error("duplicate UNUSED_STATIC_FUNCS record in PCH file");
1448 return Failure;
1449 }
1450 UnusedStaticFuncs.swap(Record);
1451 break;
Kovarththanan Rajaratnam39f2fbd12010-03-07 19:10:13 +00001452
Douglas Gregoracfc76c2009-04-22 22:18:58 +00001453 case pch::LOCALLY_SCOPED_EXTERNAL_DECLS:
1454 if (!LocallyScopedExternalDecls.empty()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001455 Error("duplicate LOCALLY_SCOPED_EXTERNAL_DECLS record in PCH file");
Douglas Gregoracfc76c2009-04-22 22:18:58 +00001456 return Failure;
1457 }
1458 LocallyScopedExternalDecls.swap(Record);
1459 break;
Douglas Gregorc78d3462009-04-24 21:10:55 +00001460
Douglas Gregor95c13f52009-04-25 17:48:32 +00001461 case pch::SELECTOR_OFFSETS:
1462 SelectorOffsets = (const uint32_t *)BlobStart;
1463 TotalNumSelectors = Record[0];
1464 SelectorsLoaded.resize(TotalNumSelectors);
1465 break;
1466
Douglas Gregorc78d3462009-04-24 21:10:55 +00001467 case pch::METHOD_POOL:
Douglas Gregor95c13f52009-04-25 17:48:32 +00001468 MethodPoolLookupTableData = (const unsigned char *)BlobStart;
1469 if (Record[0])
Mike Stump11289f42009-09-09 15:08:12 +00001470 MethodPoolLookupTable
Douglas Gregor95c13f52009-04-25 17:48:32 +00001471 = PCHMethodPoolLookupTable::Create(
1472 MethodPoolLookupTableData + Record[0],
Mike Stump11289f42009-09-09 15:08:12 +00001473 MethodPoolLookupTableData,
Douglas Gregorc78d3462009-04-24 21:10:55 +00001474 PCHMethodPoolLookupTrait(*this));
Douglas Gregor95c13f52009-04-25 17:48:32 +00001475 TotalSelectorsInMethodPool = Record[1];
Douglas Gregorc78d3462009-04-24 21:10:55 +00001476 break;
Douglas Gregoreda6a892009-04-26 00:07:37 +00001477
1478 case pch::PP_COUNTER_VALUE:
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001479 if (!Record.empty() && Listener)
1480 Listener->ReadCounter(Record[0]);
Douglas Gregoreda6a892009-04-26 00:07:37 +00001481 break;
Douglas Gregor258ae542009-04-27 06:38:32 +00001482
1483 case pch::SOURCE_LOCATION_OFFSETS:
Chris Lattner12d61d32009-04-27 19:01:47 +00001484 SLocOffsets = (const uint32_t *)BlobStart;
Douglas Gregor258ae542009-04-27 06:38:32 +00001485 TotalNumSLocEntries = Record[0];
Douglas Gregord54f3a12009-10-05 21:07:28 +00001486 SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, Record[1]);
Douglas Gregor258ae542009-04-27 06:38:32 +00001487 break;
1488
1489 case pch::SOURCE_LOCATION_PRELOADS:
1490 for (unsigned I = 0, N = Record.size(); I != N; ++I) {
1491 PCHReadResult Result = ReadSLocEntryRecord(Record[I]);
1492 if (Result != Success)
1493 return Result;
1494 }
1495 break;
Douglas Gregorc5046832009-04-27 18:38:38 +00001496
Douglas Gregord2eb58a2009-10-16 18:18:30 +00001497 case pch::STAT_CACHE: {
Kovarththanan Rajaratnam39f2fbd12010-03-07 19:10:13 +00001498 PCHStatCache *MyStatCache =
Douglas Gregord2eb58a2009-10-16 18:18:30 +00001499 new PCHStatCache((const unsigned char *)BlobStart + Record[0],
1500 (const unsigned char *)BlobStart,
1501 NumStatHits, NumStatMisses);
1502 FileMgr.addStatCache(MyStatCache);
1503 StatCache = MyStatCache;
Douglas Gregorc5046832009-04-27 18:38:38 +00001504 break;
Douglas Gregord2eb58a2009-10-16 18:18:30 +00001505 }
Kovarththanan Rajaratnam39f2fbd12010-03-07 19:10:13 +00001506
Douglas Gregor61cac2b2009-04-27 20:06:05 +00001507 case pch::EXT_VECTOR_DECLS:
1508 if (!ExtVectorDecls.empty()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001509 Error("duplicate EXT_VECTOR_DECLS record in PCH file");
Douglas Gregor61cac2b2009-04-27 20:06:05 +00001510 return Failure;
1511 }
1512 ExtVectorDecls.swap(Record);
1513 break;
1514
Douglas Gregor45fe0362009-05-12 01:31:05 +00001515 case pch::ORIGINAL_FILE_NAME:
Daniel Dunbar000c4ff2009-11-11 05:29:04 +00001516 ActualOriginalFileName.assign(BlobStart, BlobLen);
1517 OriginalFileName = ActualOriginalFileName;
Douglas Gregor0086a5a2009-07-07 00:12:59 +00001518 MaybeAddSystemRootToFilename(OriginalFileName);
Douglas Gregor45fe0362009-05-12 01:31:05 +00001519 break;
Mike Stump11289f42009-09-09 15:08:12 +00001520
Ted Kremenek17437132010-01-22 20:59:36 +00001521 case pch::VERSION_CONTROL_BRANCH_REVISION: {
Ted Kremenek8bd09292010-02-12 23:31:14 +00001522 const std::string &CurBranch = getClangFullRepositoryVersion();
Ted Kremenek2377a0e2010-01-22 20:55:35 +00001523 llvm::StringRef PCHBranch(BlobStart, BlobLen);
Ted Kremenek8bd09292010-02-12 23:31:14 +00001524 if (llvm::StringRef(CurBranch) != PCHBranch) {
Douglas Gregord54f3a12009-10-05 21:07:28 +00001525 Diag(diag::warn_pch_different_branch) << PCHBranch << CurBranch;
1526 return IgnorePCH;
1527 }
1528 break;
1529 }
Douglas Gregoraae92242010-03-19 21:51:54 +00001530
1531 case pch::MACRO_DEFINITION_OFFSETS:
1532 MacroDefinitionOffsets = (const uint32_t *)BlobStart;
1533 if (PP) {
1534 if (!PP->getPreprocessingRecord())
1535 PP->createPreprocessingRecord();
1536 PP->getPreprocessingRecord()->SetExternalSource(*this, Record[0]);
1537 } else {
1538 NumPreallocatedPreprocessingEntities = Record[0];
1539 }
1540
1541 MacroDefinitionsLoaded.resize(Record[1]);
1542 break;
Douglas Gregor3ed42cb2009-04-11 00:14:32 +00001543 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001544 }
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001545 Error("premature end of bitstream in PCH file");
Douglas Gregor55abb232009-04-10 20:39:37 +00001546 return Failure;
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001547}
1548
Douglas Gregor92863e42009-04-10 23:10:45 +00001549PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) {
Douglas Gregor55abb232009-04-10 20:39:37 +00001550 // Set the PCH file name.
1551 this->FileName = FileName;
1552
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001553 // Open the PCH file.
Daniel Dunbar2d925eb2009-09-22 05:38:01 +00001554 //
1555 // FIXME: This shouldn't be here, we should just take a raw_ostream.
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001556 std::string ErrStr;
Daniel Dunbar69914f42009-11-10 00:46:19 +00001557 Buffer.reset(llvm::MemoryBuffer::getFileOrSTDIN(FileName, &ErrStr));
Douglas Gregor92863e42009-04-10 23:10:45 +00001558 if (!Buffer) {
1559 Error(ErrStr.c_str());
1560 return IgnorePCH;
1561 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001562
1563 // Initialize the stream
Mike Stump11289f42009-09-09 15:08:12 +00001564 StreamFile.init((const unsigned char *)Buffer->getBufferStart(),
Chris Lattner9356ace2009-04-26 20:59:20 +00001565 (const unsigned char *)Buffer->getBufferEnd());
1566 Stream.init(StreamFile);
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001567
1568 // Sniff for the signature.
1569 if (Stream.Read(8) != 'C' ||
1570 Stream.Read(8) != 'P' ||
1571 Stream.Read(8) != 'C' ||
Douglas Gregor92863e42009-04-10 23:10:45 +00001572 Stream.Read(8) != 'H') {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001573 Diag(diag::err_not_a_pch_file) << FileName;
1574 return Failure;
Douglas Gregor92863e42009-04-10 23:10:45 +00001575 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001576
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001577 while (!Stream.AtEndOfStream()) {
1578 unsigned Code = Stream.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +00001579
Douglas Gregor92863e42009-04-10 23:10:45 +00001580 if (Code != llvm::bitc::ENTER_SUBBLOCK) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001581 Error("invalid record at top-level of PCH file");
Douglas Gregor92863e42009-04-10 23:10:45 +00001582 return Failure;
1583 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001584
1585 unsigned BlockID = Stream.ReadSubBlockID();
Douglas Gregora868bbd2009-04-21 22:25:48 +00001586
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001587 // We only know the PCH subblock ID.
1588 switch (BlockID) {
1589 case llvm::bitc::BLOCKINFO_BLOCK_ID:
Douglas Gregor92863e42009-04-10 23:10:45 +00001590 if (Stream.ReadBlockInfoBlock()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001591 Error("malformed BlockInfoBlock in PCH file");
Douglas Gregor92863e42009-04-10 23:10:45 +00001592 return Failure;
1593 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001594 break;
1595 case pch::PCH_BLOCK_ID:
Douglas Gregoreda6a892009-04-26 00:07:37 +00001596 switch (ReadPCHBlock()) {
Douglas Gregor55abb232009-04-10 20:39:37 +00001597 case Success:
1598 break;
1599
1600 case Failure:
Douglas Gregor92863e42009-04-10 23:10:45 +00001601 return Failure;
Douglas Gregor55abb232009-04-10 20:39:37 +00001602
1603 case IgnorePCH:
Douglas Gregorbfbde532009-04-10 21:16:55 +00001604 // FIXME: We could consider reading through to the end of this
1605 // PCH block, skipping subblocks, to see if there are other
1606 // PCH blocks elsewhere.
Douglas Gregor0bc12932009-04-27 21:28:04 +00001607
1608 // Clear out any preallocated source location entries, so that
1609 // the source manager does not try to resolve them later.
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001610 SourceMgr.ClearPreallocatedSLocEntries();
Douglas Gregor0bc12932009-04-27 21:28:04 +00001611
1612 // Remove the stat cache.
Douglas Gregord2eb58a2009-10-16 18:18:30 +00001613 if (StatCache)
1614 FileMgr.removeStatCache((PCHStatCache*)StatCache);
Douglas Gregor0bc12932009-04-27 21:28:04 +00001615
Douglas Gregor92863e42009-04-10 23:10:45 +00001616 return IgnorePCH;
Douglas Gregor55abb232009-04-10 20:39:37 +00001617 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001618 break;
1619 default:
Douglas Gregor92863e42009-04-10 23:10:45 +00001620 if (Stream.SkipBlock()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00001621 Error("malformed block record in PCH file");
Douglas Gregor92863e42009-04-10 23:10:45 +00001622 return Failure;
1623 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001624 break;
1625 }
Mike Stump11289f42009-09-09 15:08:12 +00001626 }
1627
Douglas Gregore6648fb2009-04-28 20:33:11 +00001628 // Check the predefines buffer.
Daniel Dunbar20a682d2009-11-11 00:52:11 +00001629 if (CheckPredefinesBuffer(llvm::StringRef(PCHPredefines, PCHPredefinesLen),
Douglas Gregore6648fb2009-04-28 20:33:11 +00001630 PCHPredefinesBufferID))
1631 return IgnorePCH;
Mike Stump11289f42009-09-09 15:08:12 +00001632
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001633 if (PP) {
Zhongxing Xu3f51f412009-07-18 09:26:51 +00001634 // Initialization of keywords and pragmas occurs before the
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001635 // PCH file is read, so there may be some identifiers that were
1636 // loaded into the IdentifierTable before we intercepted the
1637 // creation of identifiers. Iterate through the list of known
1638 // identifiers and determine whether we have to establish
1639 // preprocessor definitions or top-level identifier declaration
1640 // chains for those identifiers.
1641 //
1642 // We copy the IdentifierInfo pointers to a small vector first,
1643 // since de-serializing declarations or macro definitions can add
1644 // new entries into the identifier table, invalidating the
1645 // iterators.
1646 llvm::SmallVector<IdentifierInfo *, 128> Identifiers;
1647 for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(),
1648 IdEnd = PP->getIdentifierTable().end();
1649 Id != IdEnd; ++Id)
1650 Identifiers.push_back(Id->second);
Mike Stump11289f42009-09-09 15:08:12 +00001651 PCHIdentifierLookupTable *IdTable
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001652 = (PCHIdentifierLookupTable *)IdentifierLookupTable;
1653 for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) {
1654 IdentifierInfo *II = Identifiers[I];
1655 // Look in the on-disk hash table for an entry for
1656 PCHIdentifierLookupTrait Info(*this, II);
Daniel Dunbar2c422dc92009-10-18 20:26:12 +00001657 std::pair<const char*, unsigned> Key(II->getNameStart(), II->getLength());
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001658 PCHIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info);
1659 if (Pos == IdTable->end())
1660 continue;
Mike Stump11289f42009-09-09 15:08:12 +00001661
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001662 // Dereferencing the iterator has the effect of populating the
1663 // IdentifierInfo node with the various declarations it needs.
1664 (void)*Pos;
1665 }
Douglas Gregora868bbd2009-04-21 22:25:48 +00001666 }
1667
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001668 if (Context)
1669 InitializeContext(*Context);
Douglas Gregorfeb84b02009-04-14 21:18:50 +00001670
Douglas Gregora868bbd2009-04-21 22:25:48 +00001671 return Success;
Douglas Gregorfeb84b02009-04-14 21:18:50 +00001672}
1673
Douglas Gregoraae92242010-03-19 21:51:54 +00001674void PCHReader::setPreprocessor(Preprocessor &pp) {
1675 PP = &pp;
1676
1677 if (NumPreallocatedPreprocessingEntities) {
1678 if (!PP->getPreprocessingRecord())
1679 PP->createPreprocessingRecord();
1680 PP->getPreprocessingRecord()->SetExternalSource(*this,
1681 NumPreallocatedPreprocessingEntities);
1682 NumPreallocatedPreprocessingEntities = 0;
1683 }
1684}
1685
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001686void PCHReader::InitializeContext(ASTContext &Ctx) {
1687 Context = &Ctx;
1688 assert(Context && "Passed null context!");
1689
1690 assert(PP && "Forgot to set Preprocessor ?");
1691 PP->getIdentifierTable().setExternalIdentifierLookup(this);
1692 PP->getHeaderSearchInfo().SetExternalLookup(this);
Douglas Gregor9882a5a2010-01-04 19:18:44 +00001693 PP->setExternalSource(this);
Kovarththanan Rajaratnam39f2fbd12010-03-07 19:10:13 +00001694
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001695 // Load the translation unit declaration
1696 ReadDeclRecord(DeclOffsets[0], 0);
1697
1698 // Load the special types.
1699 Context->setBuiltinVaListType(
1700 GetType(SpecialTypes[pch::SPECIAL_TYPE_BUILTIN_VA_LIST]));
1701 if (unsigned Id = SpecialTypes[pch::SPECIAL_TYPE_OBJC_ID])
1702 Context->setObjCIdType(GetType(Id));
1703 if (unsigned Sel = SpecialTypes[pch::SPECIAL_TYPE_OBJC_SELECTOR])
1704 Context->setObjCSelType(GetType(Sel));
1705 if (unsigned Proto = SpecialTypes[pch::SPECIAL_TYPE_OBJC_PROTOCOL])
1706 Context->setObjCProtoType(GetType(Proto));
1707 if (unsigned Class = SpecialTypes[pch::SPECIAL_TYPE_OBJC_CLASS])
1708 Context->setObjCClassType(GetType(Class));
Steve Naroff7cae42b2009-07-10 23:34:53 +00001709
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001710 if (unsigned String = SpecialTypes[pch::SPECIAL_TYPE_CF_CONSTANT_STRING])
1711 Context->setCFConstantStringType(GetType(String));
Mike Stump11289f42009-09-09 15:08:12 +00001712 if (unsigned FastEnum
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001713 = SpecialTypes[pch::SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE])
1714 Context->setObjCFastEnumerationStateType(GetType(FastEnum));
Douglas Gregor27821ce2009-07-07 16:35:42 +00001715 if (unsigned File = SpecialTypes[pch::SPECIAL_TYPE_FILE]) {
1716 QualType FileType = GetType(File);
Ted Kremenek1ff615c2010-03-18 00:56:54 +00001717 if (FileType.isNull()) {
1718 Error("FILE type is NULL");
1719 return;
1720 }
John McCall9dd450b2009-09-21 23:43:11 +00001721 if (const TypedefType *Typedef = FileType->getAs<TypedefType>())
Douglas Gregor27821ce2009-07-07 16:35:42 +00001722 Context->setFILEDecl(Typedef->getDecl());
1723 else {
Ted Kremenekc23c7e62009-07-29 21:53:49 +00001724 const TagType *Tag = FileType->getAs<TagType>();
Ted Kremenek1ff615c2010-03-18 00:56:54 +00001725 if (!Tag) {
1726 Error("Invalid FILE type in PCH file");
1727 return;
1728 }
Douglas Gregor27821ce2009-07-07 16:35:42 +00001729 Context->setFILEDecl(Tag->getDecl());
1730 }
1731 }
Mike Stumpa4de80b2009-07-28 02:25:19 +00001732 if (unsigned Jmp_buf = SpecialTypes[pch::SPECIAL_TYPE_jmp_buf]) {
1733 QualType Jmp_bufType = GetType(Jmp_buf);
Ted Kremenek1ff615c2010-03-18 00:56:54 +00001734 if (Jmp_bufType.isNull()) {
1735 Error("jmp_bug type is NULL");
1736 return;
1737 }
John McCall9dd450b2009-09-21 23:43:11 +00001738 if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>())
Mike Stumpa4de80b2009-07-28 02:25:19 +00001739 Context->setjmp_bufDecl(Typedef->getDecl());
1740 else {
Ted Kremenekc23c7e62009-07-29 21:53:49 +00001741 const TagType *Tag = Jmp_bufType->getAs<TagType>();
Ted Kremenek1ff615c2010-03-18 00:56:54 +00001742 if (!Tag) {
1743 Error("Invalid jmp_bug type in PCH file");
1744 return;
1745 }
Mike Stumpa4de80b2009-07-28 02:25:19 +00001746 Context->setjmp_bufDecl(Tag->getDecl());
1747 }
1748 }
1749 if (unsigned Sigjmp_buf = SpecialTypes[pch::SPECIAL_TYPE_sigjmp_buf]) {
1750 QualType Sigjmp_bufType = GetType(Sigjmp_buf);
Ted Kremenek1ff615c2010-03-18 00:56:54 +00001751 if (Sigjmp_bufType.isNull()) {
1752 Error("sigjmp_buf type is NULL");
1753 return;
1754 }
John McCall9dd450b2009-09-21 23:43:11 +00001755 if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>())
Mike Stumpa4de80b2009-07-28 02:25:19 +00001756 Context->setsigjmp_bufDecl(Typedef->getDecl());
1757 else {
Ted Kremenekc23c7e62009-07-29 21:53:49 +00001758 const TagType *Tag = Sigjmp_bufType->getAs<TagType>();
Mike Stumpa4de80b2009-07-28 02:25:19 +00001759 assert(Tag && "Invalid sigjmp_buf type in PCH file");
1760 Context->setsigjmp_bufDecl(Tag->getDecl());
1761 }
1762 }
Mike Stump11289f42009-09-09 15:08:12 +00001763 if (unsigned ObjCIdRedef
Douglas Gregora8eed7d2009-08-21 00:27:50 +00001764 = SpecialTypes[pch::SPECIAL_TYPE_OBJC_ID_REDEFINITION])
1765 Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef);
Mike Stump11289f42009-09-09 15:08:12 +00001766 if (unsigned ObjCClassRedef
Douglas Gregora8eed7d2009-08-21 00:27:50 +00001767 = SpecialTypes[pch::SPECIAL_TYPE_OBJC_CLASS_REDEFINITION])
1768 Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef);
Mike Stumpd0153282009-10-20 02:12:22 +00001769 if (unsigned String = SpecialTypes[pch::SPECIAL_TYPE_BLOCK_DESCRIPTOR])
1770 Context->setBlockDescriptorType(GetType(String));
Mike Stumpe1b19ba2009-10-22 00:49:09 +00001771 if (unsigned String
1772 = SpecialTypes[pch::SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR])
1773 Context->setBlockDescriptorExtendedType(GetType(String));
Fariborz Jahaniane804c282010-04-23 17:41:07 +00001774 if (unsigned ObjCSelRedef
1775 = SpecialTypes[pch::SPECIAL_TYPE_OBJC_SEL_REDEFINITION])
1776 Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef);
1777 if (unsigned String = SpecialTypes[pch::SPECIAL_TYPE_NS_CONSTANT_STRING])
1778 Context->setNSConstantStringType(GetType(String));
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001779}
1780
Douglas Gregor45fe0362009-05-12 01:31:05 +00001781/// \brief Retrieve the name of the original source file name
1782/// directly from the PCH file, without actually loading the PCH
1783/// file.
Daniel Dunbar3b951482009-12-03 09:13:06 +00001784std::string PCHReader::getOriginalSourceFile(const std::string &PCHFileName,
1785 Diagnostic &Diags) {
Douglas Gregor45fe0362009-05-12 01:31:05 +00001786 // Open the PCH file.
1787 std::string ErrStr;
1788 llvm::OwningPtr<llvm::MemoryBuffer> Buffer;
1789 Buffer.reset(llvm::MemoryBuffer::getFile(PCHFileName.c_str(), &ErrStr));
1790 if (!Buffer) {
Daniel Dunbar3b951482009-12-03 09:13:06 +00001791 Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr;
Douglas Gregor45fe0362009-05-12 01:31:05 +00001792 return std::string();
1793 }
1794
1795 // Initialize the stream
1796 llvm::BitstreamReader StreamFile;
1797 llvm::BitstreamCursor Stream;
Mike Stump11289f42009-09-09 15:08:12 +00001798 StreamFile.init((const unsigned char *)Buffer->getBufferStart(),
Douglas Gregor45fe0362009-05-12 01:31:05 +00001799 (const unsigned char *)Buffer->getBufferEnd());
1800 Stream.init(StreamFile);
1801
1802 // Sniff for the signature.
1803 if (Stream.Read(8) != 'C' ||
1804 Stream.Read(8) != 'P' ||
1805 Stream.Read(8) != 'C' ||
1806 Stream.Read(8) != 'H') {
Daniel Dunbar3b951482009-12-03 09:13:06 +00001807 Diags.Report(diag::err_fe_not_a_pch_file) << PCHFileName;
Douglas Gregor45fe0362009-05-12 01:31:05 +00001808 return std::string();
1809 }
1810
1811 RecordData Record;
1812 while (!Stream.AtEndOfStream()) {
1813 unsigned Code = Stream.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +00001814
Douglas Gregor45fe0362009-05-12 01:31:05 +00001815 if (Code == llvm::bitc::ENTER_SUBBLOCK) {
1816 unsigned BlockID = Stream.ReadSubBlockID();
Mike Stump11289f42009-09-09 15:08:12 +00001817
Douglas Gregor45fe0362009-05-12 01:31:05 +00001818 // We only know the PCH subblock ID.
1819 switch (BlockID) {
1820 case pch::PCH_BLOCK_ID:
1821 if (Stream.EnterSubBlock(pch::PCH_BLOCK_ID)) {
Daniel Dunbar3b951482009-12-03 09:13:06 +00001822 Diags.Report(diag::err_fe_pch_malformed_block) << PCHFileName;
Douglas Gregor45fe0362009-05-12 01:31:05 +00001823 return std::string();
1824 }
1825 break;
Mike Stump11289f42009-09-09 15:08:12 +00001826
Douglas Gregor45fe0362009-05-12 01:31:05 +00001827 default:
1828 if (Stream.SkipBlock()) {
Daniel Dunbar3b951482009-12-03 09:13:06 +00001829 Diags.Report(diag::err_fe_pch_malformed_block) << PCHFileName;
Douglas Gregor45fe0362009-05-12 01:31:05 +00001830 return std::string();
1831 }
1832 break;
1833 }
1834 continue;
1835 }
1836
1837 if (Code == llvm::bitc::END_BLOCK) {
1838 if (Stream.ReadBlockEnd()) {
Daniel Dunbar3b951482009-12-03 09:13:06 +00001839 Diags.Report(diag::err_fe_pch_error_at_end_block) << PCHFileName;
Douglas Gregor45fe0362009-05-12 01:31:05 +00001840 return std::string();
1841 }
1842 continue;
1843 }
1844
1845 if (Code == llvm::bitc::DEFINE_ABBREV) {
1846 Stream.ReadAbbrevRecord();
1847 continue;
1848 }
1849
1850 Record.clear();
1851 const char *BlobStart = 0;
1852 unsigned BlobLen = 0;
Mike Stump11289f42009-09-09 15:08:12 +00001853 if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen)
Douglas Gregor45fe0362009-05-12 01:31:05 +00001854 == pch::ORIGINAL_FILE_NAME)
1855 return std::string(BlobStart, BlobLen);
Mike Stump11289f42009-09-09 15:08:12 +00001856 }
Douglas Gregor45fe0362009-05-12 01:31:05 +00001857
1858 return std::string();
1859}
1860
Douglas Gregor55abb232009-04-10 20:39:37 +00001861/// \brief Parse the record that corresponds to a LangOptions data
1862/// structure.
1863///
1864/// This routine compares the language options used to generate the
1865/// PCH file against the language options set for the current
1866/// compilation. For each option, we classify differences between the
1867/// two compiler states as either "benign" or "important". Benign
1868/// differences don't matter, and we accept them without complaint
1869/// (and without modifying the language options). Differences between
1870/// the states for important options cause the PCH file to be
1871/// unusable, so we emit a warning and return true to indicate that
1872/// there was an error.
1873///
1874/// \returns true if the PCH file is unacceptable, false otherwise.
1875bool PCHReader::ParseLanguageOptions(
1876 const llvm::SmallVectorImpl<uint64_t> &Record) {
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001877 if (Listener) {
1878 LangOptions LangOpts;
Mike Stump11289f42009-09-09 15:08:12 +00001879
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001880 #define PARSE_LANGOPT(Option) \
1881 LangOpts.Option = Record[Idx]; \
1882 ++Idx
Mike Stump11289f42009-09-09 15:08:12 +00001883
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001884 unsigned Idx = 0;
1885 PARSE_LANGOPT(Trigraphs);
1886 PARSE_LANGOPT(BCPLComment);
1887 PARSE_LANGOPT(DollarIdents);
1888 PARSE_LANGOPT(AsmPreprocessor);
1889 PARSE_LANGOPT(GNUMode);
Chandler Carruthe03aa552010-04-17 20:17:31 +00001890 PARSE_LANGOPT(GNUKeywords);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001891 PARSE_LANGOPT(ImplicitInt);
1892 PARSE_LANGOPT(Digraphs);
1893 PARSE_LANGOPT(HexFloats);
1894 PARSE_LANGOPT(C99);
1895 PARSE_LANGOPT(Microsoft);
1896 PARSE_LANGOPT(CPlusPlus);
1897 PARSE_LANGOPT(CPlusPlus0x);
1898 PARSE_LANGOPT(CXXOperatorNames);
1899 PARSE_LANGOPT(ObjC1);
1900 PARSE_LANGOPT(ObjC2);
1901 PARSE_LANGOPT(ObjCNonFragileABI);
Fariborz Jahanian45878032010-02-09 19:31:38 +00001902 PARSE_LANGOPT(ObjCNonFragileABI2);
Fariborz Jahanian62c56022010-04-22 21:01:59 +00001903 PARSE_LANGOPT(NoConstantCFStrings);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001904 PARSE_LANGOPT(PascalStrings);
1905 PARSE_LANGOPT(WritableStrings);
1906 PARSE_LANGOPT(LaxVectorConversions);
Nate Begemanf2911662009-06-25 23:01:11 +00001907 PARSE_LANGOPT(AltiVec);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001908 PARSE_LANGOPT(Exceptions);
Daniel Dunbar925152c2010-02-10 18:48:44 +00001909 PARSE_LANGOPT(SjLjExceptions);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001910 PARSE_LANGOPT(NeXTRuntime);
1911 PARSE_LANGOPT(Freestanding);
1912 PARSE_LANGOPT(NoBuiltin);
1913 PARSE_LANGOPT(ThreadsafeStatics);
Douglas Gregorb3286fe2009-09-03 14:36:33 +00001914 PARSE_LANGOPT(POSIXThreads);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001915 PARSE_LANGOPT(Blocks);
1916 PARSE_LANGOPT(EmitAllDecls);
1917 PARSE_LANGOPT(MathErrno);
Chris Lattner51924e512010-06-26 21:25:03 +00001918 LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy)
1919 Record[Idx++]);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001920 PARSE_LANGOPT(HeinousExtensions);
1921 PARSE_LANGOPT(Optimize);
1922 PARSE_LANGOPT(OptimizeSize);
1923 PARSE_LANGOPT(Static);
1924 PARSE_LANGOPT(PICLevel);
1925 PARSE_LANGOPT(GNUInline);
1926 PARSE_LANGOPT(NoInline);
1927 PARSE_LANGOPT(AccessControl);
1928 PARSE_LANGOPT(CharIsSigned);
John Thompsoned4e2952009-11-05 20:14:16 +00001929 PARSE_LANGOPT(ShortWChar);
Chris Lattner51924e512010-06-26 21:25:03 +00001930 LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]);
1931 LangOpts.setVisibilityMode((LangOptions::VisibilityMode)Record[Idx++]);
Daniel Dunbar143021e2009-09-21 04:16:19 +00001932 LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode)
Chris Lattner51924e512010-06-26 21:25:03 +00001933 Record[Idx++]);
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001934 PARSE_LANGOPT(InstantiationDepth);
Nate Begemanf2911662009-06-25 23:01:11 +00001935 PARSE_LANGOPT(OpenCL);
Mike Stumpd9546382009-12-12 01:27:46 +00001936 PARSE_LANGOPT(CatchUndefined);
1937 // FIXME: Missing ElideConstructors?!
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001938 #undef PARSE_LANGOPT
Douglas Gregor55abb232009-04-10 20:39:37 +00001939
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00001940 return Listener->ReadLanguageOptions(LangOpts);
Douglas Gregor55abb232009-04-10 20:39:37 +00001941 }
Douglas Gregor55abb232009-04-10 20:39:37 +00001942
1943 return false;
1944}
1945
Douglas Gregoraae92242010-03-19 21:51:54 +00001946void PCHReader::ReadPreprocessedEntities() {
1947 ReadDefinedMacros();
1948}
1949
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001950/// \brief Read and return the type at the given offset.
1951///
1952/// This routine actually reads the record corresponding to the type
1953/// at the given offset in the bitstream. It is a helper routine for
1954/// GetType, which deals with reading type IDs.
1955QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
Douglas Gregorfeb84b02009-04-14 21:18:50 +00001956 // Keep track of where we are in the stream, then jump back there
1957 // after reading this type.
Douglas Gregor12bfa382009-10-17 00:13:19 +00001958 SavedStreamPosition SavedPosition(DeclsCursor);
Douglas Gregorfeb84b02009-04-14 21:18:50 +00001959
Douglas Gregor1342e842009-07-06 18:54:52 +00001960 // Note that we are loading a type record.
1961 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +00001962
Douglas Gregor12bfa382009-10-17 00:13:19 +00001963 DeclsCursor.JumpToBit(Offset);
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001964 RecordData Record;
Douglas Gregor12bfa382009-10-17 00:13:19 +00001965 unsigned Code = DeclsCursor.ReadCode();
1966 switch ((pch::TypeCode)DeclsCursor.ReadRecord(Code, Record)) {
Douglas Gregor455b8f42009-04-15 22:00:08 +00001967 case pch::TYPE_EXT_QUAL: {
Ted Kremenek1ff615c2010-03-18 00:56:54 +00001968 if (Record.size() != 2) {
1969 Error("Incorrect encoding of extended qualifier type");
1970 return QualType();
1971 }
Douglas Gregor455b8f42009-04-15 22:00:08 +00001972 QualType Base = GetType(Record[0]);
John McCall8ccfcb52009-09-24 19:53:00 +00001973 Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]);
1974 return Context->getQualifiedType(Base, Quals);
Douglas Gregor455b8f42009-04-15 22:00:08 +00001975 }
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00001976
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001977 case pch::TYPE_COMPLEX: {
Ted Kremenek1ff615c2010-03-18 00:56:54 +00001978 if (Record.size() != 1) {
1979 Error("Incorrect encoding of complex type");
1980 return QualType();
1981 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001982 QualType ElemType = GetType(Record[0]);
Chris Lattner8575daa2009-04-27 21:45:14 +00001983 return Context->getComplexType(ElemType);
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001984 }
1985
1986 case pch::TYPE_POINTER: {
Ted Kremenek1ff615c2010-03-18 00:56:54 +00001987 if (Record.size() != 1) {
1988 Error("Incorrect encoding of pointer type");
1989 return QualType();
1990 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001991 QualType PointeeType = GetType(Record[0]);
Chris Lattner8575daa2009-04-27 21:45:14 +00001992 return Context->getPointerType(PointeeType);
Douglas Gregoref84c4b2009-04-09 22:27:44 +00001993 }
1994
1995 case pch::TYPE_BLOCK_POINTER: {
Ted Kremenek1ff615c2010-03-18 00:56:54 +00001996 if (Record.size() != 1) {
1997 Error("Incorrect encoding of block pointer type");
1998 return QualType();
1999 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002000 QualType PointeeType = GetType(Record[0]);
Chris Lattner8575daa2009-04-27 21:45:14 +00002001 return Context->getBlockPointerType(PointeeType);
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002002 }
2003
2004 case pch::TYPE_LVALUE_REFERENCE: {
Ted Kremenek1ff615c2010-03-18 00:56:54 +00002005 if (Record.size() != 1) {
2006 Error("Incorrect encoding of lvalue reference type");
2007 return QualType();
2008 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002009 QualType PointeeType = GetType(Record[0]);
Chris Lattner8575daa2009-04-27 21:45:14 +00002010 return Context->getLValueReferenceType(PointeeType);
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002011 }
2012
2013 case pch::TYPE_RVALUE_REFERENCE: {
Ted Kremenek1ff615c2010-03-18 00:56:54 +00002014 if (Record.size() != 1) {
2015 Error("Incorrect encoding of rvalue reference type");
2016 return QualType();
2017 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002018 QualType PointeeType = GetType(Record[0]);
Chris Lattner8575daa2009-04-27 21:45:14 +00002019 return Context->getRValueReferenceType(PointeeType);
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002020 }
2021
2022 case pch::TYPE_MEMBER_POINTER: {
Ted Kremenek1ff615c2010-03-18 00:56:54 +00002023 if (Record.size() != 1) {
2024 Error("Incorrect encoding of member pointer type");
2025 return QualType();
2026 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002027 QualType PointeeType = GetType(Record[0]);
2028 QualType ClassType = GetType(Record[1]);
Chris Lattner8575daa2009-04-27 21:45:14 +00002029 return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr());
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002030 }
2031
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002032 case pch::TYPE_CONSTANT_ARRAY: {
2033 QualType ElementType = GetType(Record[0]);
2034 ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1];
2035 unsigned IndexTypeQuals = Record[2];
2036 unsigned Idx = 3;
2037 llvm::APInt Size = ReadAPInt(Record, Idx);
Douglas Gregor04318252009-07-06 15:59:29 +00002038 return Context->getConstantArrayType(ElementType, Size,
2039 ASM, IndexTypeQuals);
2040 }
2041
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002042 case pch::TYPE_INCOMPLETE_ARRAY: {
2043 QualType ElementType = GetType(Record[0]);
2044 ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1];
2045 unsigned IndexTypeQuals = Record[2];
Chris Lattner8575daa2009-04-27 21:45:14 +00002046 return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals);
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002047 }
2048
2049 case pch::TYPE_VARIABLE_ARRAY: {
Douglas Gregorfeb84b02009-04-14 21:18:50 +00002050 QualType ElementType = GetType(Record[0]);
2051 ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1];
2052 unsigned IndexTypeQuals = Record[2];
Douglas Gregor04318252009-07-06 15:59:29 +00002053 SourceLocation LBLoc = SourceLocation::getFromRawEncoding(Record[3]);
2054 SourceLocation RBLoc = SourceLocation::getFromRawEncoding(Record[4]);
Chris Lattner8575daa2009-04-27 21:45:14 +00002055 return Context->getVariableArrayType(ElementType, ReadTypeExpr(),
Douglas Gregor04318252009-07-06 15:59:29 +00002056 ASM, IndexTypeQuals,
2057 SourceRange(LBLoc, RBLoc));
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002058 }
2059
2060 case pch::TYPE_VECTOR: {
Chris Lattner37141f42010-06-23 06:00:24 +00002061 if (Record.size() != 3) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00002062 Error("incorrect encoding of vector type in PCH file");
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002063 return QualType();
2064 }
2065
2066 QualType ElementType = GetType(Record[0]);
2067 unsigned NumElements = Record[1];
Chris Lattner37141f42010-06-23 06:00:24 +00002068 unsigned AltiVecSpec = Record[2];
2069 return Context->getVectorType(ElementType, NumElements,
2070 (VectorType::AltiVecSpecific)AltiVecSpec);
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002071 }
2072
2073 case pch::TYPE_EXT_VECTOR: {
Chris Lattner37141f42010-06-23 06:00:24 +00002074 if (Record.size() != 3) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00002075 Error("incorrect encoding of extended vector type in PCH file");
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002076 return QualType();
2077 }
2078
2079 QualType ElementType = GetType(Record[0]);
2080 unsigned NumElements = Record[1];
Chris Lattner8575daa2009-04-27 21:45:14 +00002081 return Context->getExtVectorType(ElementType, NumElements);
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002082 }
2083
2084 case pch::TYPE_FUNCTION_NO_PROTO: {
Rafael Espindola49b85ab2010-03-30 22:15:11 +00002085 if (Record.size() != 4) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00002086 Error("incorrect encoding of no-proto function type");
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002087 return QualType();
2088 }
2089 QualType ResultType = GetType(Record[0]);
Rafael Espindola49b85ab2010-03-30 22:15:11 +00002090 FunctionType::ExtInfo Info(Record[1], Record[2], (CallingConv)Record[3]);
Rafael Espindolac50c27c2010-03-30 20:24:48 +00002091 return Context->getFunctionNoProtoType(ResultType, Info);
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002092 }
2093
2094 case pch::TYPE_FUNCTION_PROTO: {
2095 QualType ResultType = GetType(Record[0]);
Douglas Gregordc728752009-12-22 18:11:50 +00002096 bool NoReturn = Record[1];
Rafael Espindola49b85ab2010-03-30 22:15:11 +00002097 unsigned RegParm = Record[2];
2098 CallingConv CallConv = (CallingConv)Record[3];
2099 unsigned Idx = 4;
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002100 unsigned NumParams = Record[Idx++];
2101 llvm::SmallVector<QualType, 16> ParamTypes;
2102 for (unsigned I = 0; I != NumParams; ++I)
2103 ParamTypes.push_back(GetType(Record[Idx++]));
2104 bool isVariadic = Record[Idx++];
2105 unsigned Quals = Record[Idx++];
Sebastian Redl5068f77ac2009-05-27 22:11:52 +00002106 bool hasExceptionSpec = Record[Idx++];
2107 bool hasAnyExceptionSpec = Record[Idx++];
2108 unsigned NumExceptions = Record[Idx++];
2109 llvm::SmallVector<QualType, 2> Exceptions;
2110 for (unsigned I = 0; I != NumExceptions; ++I)
2111 Exceptions.push_back(GetType(Record[Idx++]));
Jay Foad7d0479f2009-05-21 09:52:38 +00002112 return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams,
Sebastian Redl5068f77ac2009-05-27 22:11:52 +00002113 isVariadic, Quals, hasExceptionSpec,
2114 hasAnyExceptionSpec, NumExceptions,
Rafael Espindolac50c27c2010-03-30 20:24:48 +00002115 Exceptions.data(),
Rafael Espindola49b85ab2010-03-30 22:15:11 +00002116 FunctionType::ExtInfo(NoReturn, RegParm,
2117 CallConv));
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002118 }
2119
John McCallb96ec562009-12-04 22:46:56 +00002120 case pch::TYPE_UNRESOLVED_USING:
2121 return Context->getTypeDeclType(
2122 cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0])));
2123
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002124 case pch::TYPE_TYPEDEF:
Ted Kremenek1ff615c2010-03-18 00:56:54 +00002125 if (Record.size() != 1) {
2126 Error("incorrect encoding of typedef type");
2127 return QualType();
2128 }
Chris Lattner8575daa2009-04-27 21:45:14 +00002129 return Context->getTypeDeclType(cast<TypedefDecl>(GetDecl(Record[0])));
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002130
2131 case pch::TYPE_TYPEOF_EXPR:
Chris Lattner8575daa2009-04-27 21:45:14 +00002132 return Context->getTypeOfExprType(ReadTypeExpr());
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002133
2134 case pch::TYPE_TYPEOF: {
2135 if (Record.size() != 1) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00002136 Error("incorrect encoding of typeof(type) in PCH file");
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002137 return QualType();
2138 }
2139 QualType UnderlyingType = GetType(Record[0]);
Chris Lattner8575daa2009-04-27 21:45:14 +00002140 return Context->getTypeOfType(UnderlyingType);
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002141 }
Mike Stump11289f42009-09-09 15:08:12 +00002142
Anders Carlsson81df7b82009-06-24 19:06:50 +00002143 case pch::TYPE_DECLTYPE:
2144 return Context->getDecltypeType(ReadTypeExpr());
2145
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002146 case pch::TYPE_RECORD:
Ted Kremenek1ff615c2010-03-18 00:56:54 +00002147 if (Record.size() != 1) {
2148 Error("incorrect encoding of record type");
2149 return QualType();
2150 }
Chris Lattner8575daa2009-04-27 21:45:14 +00002151 return Context->getTypeDeclType(cast<RecordDecl>(GetDecl(Record[0])));
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002152
Douglas Gregor1daeb692009-04-13 18:14:40 +00002153 case pch::TYPE_ENUM:
Ted Kremenek1ff615c2010-03-18 00:56:54 +00002154 if (Record.size() != 1) {
2155 Error("incorrect encoding of enum type");
2156 return QualType();
2157 }
Chris Lattner8575daa2009-04-27 21:45:14 +00002158 return Context->getTypeDeclType(cast<EnumDecl>(GetDecl(Record[0])));
Douglas Gregor1daeb692009-04-13 18:14:40 +00002159
John McCallfcc33b02009-09-05 00:15:47 +00002160 case pch::TYPE_ELABORATED: {
Argyrios Kyrtzidisf0f7a792010-06-25 16:24:58 +00002161 unsigned Idx = 0;
2162 ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
2163 NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx);
2164 QualType NamedType = GetType(Record[Idx++]);
2165 return Context->getElaboratedType(Keyword, NNS, NamedType);
John McCallfcc33b02009-09-05 00:15:47 +00002166 }
2167
Steve Naroffc277ad12009-07-18 15:33:26 +00002168 case pch::TYPE_OBJC_INTERFACE: {
Chris Lattner587cbe12009-04-22 06:45:28 +00002169 unsigned Idx = 0;
2170 ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
John McCall8b07ec22010-05-15 11:32:37 +00002171 return Context->getObjCInterfaceType(ItfD);
2172 }
2173
2174 case pch::TYPE_OBJC_OBJECT: {
2175 unsigned Idx = 0;
2176 QualType Base = GetType(Record[Idx++]);
Chris Lattner587cbe12009-04-22 06:45:28 +00002177 unsigned NumProtos = Record[Idx++];
2178 llvm::SmallVector<ObjCProtocolDecl*, 4> Protos;
2179 for (unsigned I = 0; I != NumProtos; ++I)
2180 Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++])));
John McCall8b07ec22010-05-15 11:32:37 +00002181 return Context->getObjCObjectType(Base, Protos.data(), NumProtos);
Chris Lattner587cbe12009-04-22 06:45:28 +00002182 }
Douglas Gregor85c0fcd2009-04-13 20:46:52 +00002183
Steve Narofffb4330f2009-06-17 22:40:22 +00002184 case pch::TYPE_OBJC_OBJECT_POINTER: {
Chris Lattner6e054af2009-04-22 06:40:03 +00002185 unsigned Idx = 0;
John McCall8b07ec22010-05-15 11:32:37 +00002186 QualType Pointee = GetType(Record[Idx++]);
2187 return Context->getObjCObjectPointerType(Pointee);
Chris Lattner6e054af2009-04-22 06:40:03 +00002188 }
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002189
John McCallcebee162009-10-18 09:09:24 +00002190 case pch::TYPE_SUBST_TEMPLATE_TYPE_PARM: {
2191 unsigned Idx = 0;
2192 QualType Parm = GetType(Record[Idx++]);
2193 QualType Replacement = GetType(Record[Idx++]);
2194 return
2195 Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm),
2196 Replacement);
2197 }
John McCalle78aac42010-03-10 03:28:59 +00002198
2199 case pch::TYPE_INJECTED_CLASS_NAME: {
2200 CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0]));
2201 QualType TST = GetType(Record[1]); // probably derivable
2202 return Context->getInjectedClassNameType(D, TST);
2203 }
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00002204
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002205 case pch::TYPE_TEMPLATE_TYPE_PARM: {
2206 unsigned Idx = 0;
2207 unsigned Depth = Record[Idx++];
2208 unsigned Index = Record[Idx++];
2209 bool Pack = Record[Idx++];
2210 IdentifierInfo *Name = GetIdentifierInfo(Record, Idx);
2211 return Context->getTemplateTypeParmType(Depth, Index, Pack, Name);
2212 }
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00002213
2214 case pch::TYPE_DEPENDENT_NAME: {
2215 unsigned Idx = 0;
2216 ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
2217 NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx);
2218 const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx);
2219 return Context->getDependentNameType(Keyword, NNS, Name, QualType());
2220 }
Argyrios Kyrtzidisf0f7a792010-06-25 16:24:58 +00002221
2222 case pch::TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: {
2223 unsigned Idx = 0;
2224 ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
2225 NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx);
2226 const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx);
2227 unsigned NumArgs = Record[Idx++];
2228 llvm::SmallVector<TemplateArgument, 8> Args;
2229 Args.reserve(NumArgs);
2230 while (NumArgs--)
2231 Args.push_back(ReadTemplateArgument(Record, Idx));
2232 return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name,
2233 Args.size(), Args.data());
2234 }
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00002235
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002236 case pch::TYPE_TEMPLATE_SPECIALIZATION: {
2237 unsigned Idx = 0;
2238 TemplateName Name = ReadTemplateName(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002239 llvm::SmallVector<TemplateArgument, 8> Args;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00002240 ReadTemplateArgumentList(Args, Record, Idx);
2241 QualType Canon = GetType(Record[Idx++]);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002242 return Context->getTemplateSpecializationType(Name, Args.data(),Args.size(),
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00002243 Canon);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002244 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002245 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002246 // Suppress a GCC warning
2247 return QualType();
2248}
2249
John McCall8f115c62009-10-16 21:56:05 +00002250namespace {
2251
2252class TypeLocReader : public TypeLocVisitor<TypeLocReader> {
2253 PCHReader &Reader;
2254 const PCHReader::RecordData &Record;
2255 unsigned &Idx;
2256
2257public:
2258 TypeLocReader(PCHReader &Reader, const PCHReader::RecordData &Record,
2259 unsigned &Idx)
2260 : Reader(Reader), Record(Record), Idx(Idx) { }
2261
John McCall17001972009-10-18 01:05:36 +00002262 // We want compile-time assurance that we've enumerated all of
2263 // these, so unfortunately we have to declare them first, then
2264 // define them out-of-line.
2265#define ABSTRACT_TYPELOC(CLASS, PARENT)
John McCall8f115c62009-10-16 21:56:05 +00002266#define TYPELOC(CLASS, PARENT) \
John McCall17001972009-10-18 01:05:36 +00002267 void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc);
John McCall8f115c62009-10-16 21:56:05 +00002268#include "clang/AST/TypeLocNodes.def"
2269
John McCall17001972009-10-18 01:05:36 +00002270 void VisitFunctionTypeLoc(FunctionTypeLoc);
2271 void VisitArrayTypeLoc(ArrayTypeLoc);
John McCall8f115c62009-10-16 21:56:05 +00002272};
2273
2274}
2275
John McCall17001972009-10-18 01:05:36 +00002276void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
John McCall8f115c62009-10-16 21:56:05 +00002277 // nothing to do
2278}
John McCall17001972009-10-18 01:05:36 +00002279void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002280 TL.setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2281 if (TL.needsExtraLocalData()) {
2282 TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++]));
2283 TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++]));
2284 TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++]));
2285 TL.setModeAttr(Record[Idx++]);
2286 }
John McCall8f115c62009-10-16 21:56:05 +00002287}
John McCall17001972009-10-18 01:05:36 +00002288void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) {
2289 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall8f115c62009-10-16 21:56:05 +00002290}
John McCall17001972009-10-18 01:05:36 +00002291void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) {
2292 TL.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall8f115c62009-10-16 21:56:05 +00002293}
John McCall17001972009-10-18 01:05:36 +00002294void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
2295 TL.setCaretLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall8f115c62009-10-16 21:56:05 +00002296}
John McCall17001972009-10-18 01:05:36 +00002297void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
2298 TL.setAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall8f115c62009-10-16 21:56:05 +00002299}
John McCall17001972009-10-18 01:05:36 +00002300void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
2301 TL.setAmpAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall8f115c62009-10-16 21:56:05 +00002302}
John McCall17001972009-10-18 01:05:36 +00002303void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
2304 TL.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall8f115c62009-10-16 21:56:05 +00002305}
John McCall17001972009-10-18 01:05:36 +00002306void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) {
2307 TL.setLBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2308 TL.setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall8f115c62009-10-16 21:56:05 +00002309 if (Record[Idx++])
John McCall17001972009-10-18 01:05:36 +00002310 TL.setSizeExpr(Reader.ReadDeclExpr());
Douglas Gregor12bfa382009-10-17 00:13:19 +00002311 else
John McCall17001972009-10-18 01:05:36 +00002312 TL.setSizeExpr(0);
2313}
2314void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) {
2315 VisitArrayTypeLoc(TL);
2316}
2317void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) {
2318 VisitArrayTypeLoc(TL);
2319}
2320void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) {
2321 VisitArrayTypeLoc(TL);
2322}
2323void TypeLocReader::VisitDependentSizedArrayTypeLoc(
2324 DependentSizedArrayTypeLoc TL) {
2325 VisitArrayTypeLoc(TL);
2326}
2327void TypeLocReader::VisitDependentSizedExtVectorTypeLoc(
2328 DependentSizedExtVectorTypeLoc TL) {
2329 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2330}
2331void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) {
2332 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2333}
2334void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
2335 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2336}
2337void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) {
2338 TL.setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2339 TL.setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2340 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
John McCalle6347002009-10-23 01:28:53 +00002341 TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
John McCall17001972009-10-18 01:05:36 +00002342 }
2343}
2344void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) {
2345 VisitFunctionTypeLoc(TL);
2346}
2347void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) {
2348 VisitFunctionTypeLoc(TL);
2349}
John McCallb96ec562009-12-04 22:46:56 +00002350void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) {
2351 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2352}
John McCall17001972009-10-18 01:05:36 +00002353void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
2354 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2355}
2356void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00002357 TL.setTypeofLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2358 TL.setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2359 TL.setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall17001972009-10-18 01:05:36 +00002360}
2361void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00002362 TL.setTypeofLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2363 TL.setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2364 TL.setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2365 TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(Record, Idx));
John McCall17001972009-10-18 01:05:36 +00002366}
2367void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
2368 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2369}
2370void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) {
2371 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2372}
2373void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) {
2374 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2375}
John McCall17001972009-10-18 01:05:36 +00002376void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
2377 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2378}
John McCallcebee162009-10-18 09:09:24 +00002379void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc(
2380 SubstTemplateTypeParmTypeLoc TL) {
2381 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2382}
John McCall17001972009-10-18 01:05:36 +00002383void TypeLocReader::VisitTemplateSpecializationTypeLoc(
2384 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00002385 TL.setTemplateNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2386 TL.setLAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2387 TL.setRAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2388 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i)
2389 TL.setArgLocInfo(i,
2390 Reader.GetTemplateArgumentLocInfo(TL.getTypePtr()->getArg(i).getKind(),
2391 Record, Idx));
John McCall17001972009-10-18 01:05:36 +00002392}
Abramo Bagnara6150c882010-05-11 21:36:43 +00002393void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00002394 TL.setKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2395 TL.setQualifierRange(Reader.ReadSourceRange(Record, Idx));
John McCall17001972009-10-18 01:05:36 +00002396}
John McCalle78aac42010-03-10 03:28:59 +00002397void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
2398 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2399}
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00002400void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00002401 TL.setKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2402 TL.setQualifierRange(Reader.ReadSourceRange(Record, Idx));
John McCall17001972009-10-18 01:05:36 +00002403 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2404}
John McCallc392f372010-06-11 00:33:02 +00002405void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc(
2406 DependentTemplateSpecializationTypeLoc TL) {
2407 TL.setKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2408 TL.setQualifierRange(Reader.ReadSourceRange(Record, Idx));
2409 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2410 TL.setLAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2411 TL.setRAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2412 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
2413 TL.setArgLocInfo(I,
2414 Reader.GetTemplateArgumentLocInfo(TL.getTypePtr()->getArg(I).getKind(),
2415 Record, Idx));
2416}
John McCall17001972009-10-18 01:05:36 +00002417void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
2418 TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall8b07ec22010-05-15 11:32:37 +00002419}
2420void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
2421 TL.setHasBaseTypeAsWritten(Record[Idx++]);
John McCall17001972009-10-18 01:05:36 +00002422 TL.setLAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2423 TL.setRAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
2424 for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
2425 TL.setProtocolLoc(i, SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall8f115c62009-10-16 21:56:05 +00002426}
John McCallfc93cf92009-10-22 22:37:11 +00002427void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
2428 TL.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCallfc93cf92009-10-22 22:37:11 +00002429}
John McCall8f115c62009-10-16 21:56:05 +00002430
John McCallbcd03502009-12-07 02:54:59 +00002431TypeSourceInfo *PCHReader::GetTypeSourceInfo(const RecordData &Record,
John McCall8f115c62009-10-16 21:56:05 +00002432 unsigned &Idx) {
2433 QualType InfoTy = GetType(Record[Idx++]);
2434 if (InfoTy.isNull())
2435 return 0;
2436
John McCallbcd03502009-12-07 02:54:59 +00002437 TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy);
John McCall8f115c62009-10-16 21:56:05 +00002438 TypeLocReader TLR(*this, Record, Idx);
John McCallbcd03502009-12-07 02:54:59 +00002439 for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc())
John McCall8f115c62009-10-16 21:56:05 +00002440 TLR.Visit(TL);
John McCallbcd03502009-12-07 02:54:59 +00002441 return TInfo;
John McCall8f115c62009-10-16 21:56:05 +00002442}
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002443
Douglas Gregor1e9bf3b2009-04-10 17:25:41 +00002444QualType PCHReader::GetType(pch::TypeID ID) {
John McCall8ccfcb52009-09-24 19:53:00 +00002445 unsigned FastQuals = ID & Qualifiers::FastMask;
2446 unsigned Index = ID >> Qualifiers::FastWidth;
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002447
2448 if (Index < pch::NUM_PREDEF_TYPE_IDS) {
2449 QualType T;
2450 switch ((pch::PredefinedTypeIDs)Index) {
2451 case pch::PREDEF_TYPE_NULL_ID: return QualType();
Chris Lattner8575daa2009-04-27 21:45:14 +00002452 case pch::PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break;
2453 case pch::PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break;
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002454
2455 case pch::PREDEF_TYPE_CHAR_U_ID:
2456 case pch::PREDEF_TYPE_CHAR_S_ID:
2457 // FIXME: Check that the signedness of CharTy is correct!
Chris Lattner8575daa2009-04-27 21:45:14 +00002458 T = Context->CharTy;
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002459 break;
2460
Chris Lattner8575daa2009-04-27 21:45:14 +00002461 case pch::PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break;
2462 case pch::PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break;
2463 case pch::PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break;
2464 case pch::PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break;
2465 case pch::PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break;
Chris Lattnerf122cef2009-04-30 02:43:43 +00002466 case pch::PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break;
Chris Lattner8575daa2009-04-27 21:45:14 +00002467 case pch::PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break;
2468 case pch::PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break;
2469 case pch::PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break;
2470 case pch::PREDEF_TYPE_INT_ID: T = Context->IntTy; break;
2471 case pch::PREDEF_TYPE_LONG_ID: T = Context->LongTy; break;
2472 case pch::PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break;
Chris Lattnerf122cef2009-04-30 02:43:43 +00002473 case pch::PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break;
Chris Lattner8575daa2009-04-27 21:45:14 +00002474 case pch::PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break;
2475 case pch::PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break;
2476 case pch::PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break;
2477 case pch::PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break;
2478 case pch::PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break;
Sebastian Redl576fd422009-05-10 18:38:11 +00002479 case pch::PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break;
Alisdair Mereditha9ad47d2009-07-14 06:30:34 +00002480 case pch::PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break;
2481 case pch::PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break;
Steve Naroff1329fa02009-07-15 18:40:39 +00002482 case pch::PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break;
2483 case pch::PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break;
Fariborz Jahanian252ba5f2009-11-21 19:53:08 +00002484 case pch::PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break;
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002485 }
2486
2487 assert(!T.isNull() && "Unknown predefined type");
John McCall8ccfcb52009-09-24 19:53:00 +00002488 return T.withFastQualifiers(FastQuals);
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002489 }
2490
2491 Index -= pch::NUM_PREDEF_TYPE_IDS;
Steve Naroffc277ad12009-07-18 15:33:26 +00002492 //assert(Index < TypesLoaded.size() && "Type index out-of-range");
John McCall8ccfcb52009-09-24 19:53:00 +00002493 if (TypesLoaded[Index].isNull())
2494 TypesLoaded[Index] = ReadTypeRecord(TypeOffsets[Index]);
Mike Stump11289f42009-09-09 15:08:12 +00002495
John McCall8ccfcb52009-09-24 19:53:00 +00002496 return TypesLoaded[Index].withFastQualifiers(FastQuals);
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002497}
2498
John McCall0ad16662009-10-29 08:12:44 +00002499TemplateArgumentLocInfo
2500PCHReader::GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind,
2501 const RecordData &Record,
2502 unsigned &Index) {
2503 switch (Kind) {
2504 case TemplateArgument::Expression:
2505 return ReadDeclExpr();
2506 case TemplateArgument::Type:
John McCallbcd03502009-12-07 02:54:59 +00002507 return GetTypeSourceInfo(Record, Index);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002508 case TemplateArgument::Template: {
Kovarththanan Rajaratnam39f2fbd12010-03-07 19:10:13 +00002509 SourceLocation
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002510 QualStart = SourceLocation::getFromRawEncoding(Record[Index++]),
2511 QualEnd = SourceLocation::getFromRawEncoding(Record[Index++]),
2512 TemplateNameLoc = SourceLocation::getFromRawEncoding(Record[Index++]);
2513 return TemplateArgumentLocInfo(SourceRange(QualStart, QualEnd),
2514 TemplateNameLoc);
2515 }
John McCall0ad16662009-10-29 08:12:44 +00002516 case TemplateArgument::Null:
2517 case TemplateArgument::Integral:
2518 case TemplateArgument::Declaration:
2519 case TemplateArgument::Pack:
2520 return TemplateArgumentLocInfo();
2521 }
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002522 llvm_unreachable("unexpected template argument loc");
John McCall0ad16662009-10-29 08:12:44 +00002523 return TemplateArgumentLocInfo();
2524}
2525
Argyrios Kyrtzidisae85e242010-06-22 09:54:59 +00002526TemplateArgumentLoc
2527PCHReader::ReadTemplateArgumentLoc(const RecordData &Record, unsigned &Index) {
2528 TemplateArgument Arg = ReadTemplateArgument(Record, Index);
2529 return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(Arg.getKind(),
2530 Record, Index));
2531}
2532
John McCall75b960e2010-06-01 09:23:16 +00002533Decl *PCHReader::GetExternalDecl(uint32_t ID) {
2534 return GetDecl(ID);
2535}
2536
Douglas Gregor1e9bf3b2009-04-10 17:25:41 +00002537Decl *PCHReader::GetDecl(pch::DeclID ID) {
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002538 if (ID == 0)
2539 return 0;
2540
Douglas Gregor745ed142009-04-25 18:35:21 +00002541 if (ID > DeclsLoaded.size()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00002542 Error("declaration ID out-of-range for PCH file");
Douglas Gregor745ed142009-04-25 18:35:21 +00002543 return 0;
2544 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002545
Douglas Gregor745ed142009-04-25 18:35:21 +00002546 unsigned Index = ID - 1;
2547 if (!DeclsLoaded[Index])
2548 ReadDeclRecord(DeclOffsets[Index], Index);
2549
2550 return DeclsLoaded[Index];
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002551}
2552
Chris Lattner9c28af02009-04-27 05:46:25 +00002553/// \brief Resolve the offset of a statement into a statement.
2554///
2555/// This operation will read a new statement from the external
2556/// source each time it is called, and is meant to be used via a
2557/// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
John McCall75b960e2010-06-01 09:23:16 +00002558Stmt *PCHReader::GetExternalDeclStmt(uint64_t Offset) {
Chris Lattner1de76db2009-04-27 05:58:23 +00002559 // Since we know tha this statement is part of a decl, make sure to use the
2560 // decl cursor to read it.
2561 DeclsCursor.JumpToBit(Offset);
2562 return ReadStmt(DeclsCursor);
Douglas Gregor3c3aa612009-04-18 00:07:54 +00002563}
2564
John McCall75b960e2010-06-01 09:23:16 +00002565bool PCHReader::FindExternalLexicalDecls(const DeclContext *DC,
2566 llvm::SmallVectorImpl<Decl*> &Decls) {
Mike Stump11289f42009-09-09 15:08:12 +00002567 assert(DC->hasExternalLexicalStorage() &&
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002568 "DeclContext has no lexical decls in storage");
Ted Kremenek1ff615c2010-03-18 00:56:54 +00002569
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002570 uint64_t Offset = DeclContextOffsets[DC].first;
Ted Kremenek1ff615c2010-03-18 00:56:54 +00002571 if (Offset == 0) {
2572 Error("DeclContext has no lexical decls in storage");
2573 return true;
2574 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002575
Douglas Gregorfeb84b02009-04-14 21:18:50 +00002576 // Keep track of where we are in the stream, then jump back there
2577 // after reading this context.
Chris Lattner72405d62009-04-27 07:35:40 +00002578 SavedStreamPosition SavedPosition(DeclsCursor);
Douglas Gregorfeb84b02009-04-14 21:18:50 +00002579
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002580 // Load the record containing all of the declarations lexically in
2581 // this context.
Chris Lattner72405d62009-04-27 07:35:40 +00002582 DeclsCursor.JumpToBit(Offset);
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002583 RecordData Record;
Chris Lattner72405d62009-04-27 07:35:40 +00002584 unsigned Code = DeclsCursor.ReadCode();
2585 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Ted Kremenek1ff615c2010-03-18 00:56:54 +00002586 if (RecCode != pch::DECL_CONTEXT_LEXICAL) {
2587 Error("Expected lexical block");
2588 return true;
2589 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002590
2591 // Load all of the declaration IDs
John McCall75b960e2010-06-01 09:23:16 +00002592 for (RecordData::iterator I = Record.begin(), E = Record.end(); I != E; ++I)
2593 Decls.push_back(GetDecl(*I));
Douglas Gregora57c3ab2009-04-22 22:34:57 +00002594 ++NumLexicalDeclContextsRead;
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002595 return false;
2596}
2597
John McCall75b960e2010-06-01 09:23:16 +00002598DeclContext::lookup_result
2599PCHReader::FindExternalVisibleDeclsByName(const DeclContext *DC,
2600 DeclarationName Name) {
Mike Stump11289f42009-09-09 15:08:12 +00002601 assert(DC->hasExternalVisibleStorage() &&
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002602 "DeclContext has no visible decls in storage");
2603 uint64_t Offset = DeclContextOffsets[DC].second;
Ted Kremenek1ff615c2010-03-18 00:56:54 +00002604 if (Offset == 0) {
2605 Error("DeclContext has no visible decls in storage");
John McCall75b960e2010-06-01 09:23:16 +00002606 return DeclContext::lookup_result(DeclContext::lookup_iterator(),
2607 DeclContext::lookup_iterator());
Ted Kremenek1ff615c2010-03-18 00:56:54 +00002608 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002609
Douglas Gregorfeb84b02009-04-14 21:18:50 +00002610 // Keep track of where we are in the stream, then jump back there
2611 // after reading this context.
Chris Lattner72405d62009-04-27 07:35:40 +00002612 SavedStreamPosition SavedPosition(DeclsCursor);
Douglas Gregorfeb84b02009-04-14 21:18:50 +00002613
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002614 // Load the record containing all of the declarations visible in
2615 // this context.
Chris Lattner72405d62009-04-27 07:35:40 +00002616 DeclsCursor.JumpToBit(Offset);
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002617 RecordData Record;
Chris Lattner72405d62009-04-27 07:35:40 +00002618 unsigned Code = DeclsCursor.ReadCode();
2619 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Ted Kremenek1ff615c2010-03-18 00:56:54 +00002620 if (RecCode != pch::DECL_CONTEXT_VISIBLE) {
2621 Error("Expected visible block");
John McCall75b960e2010-06-01 09:23:16 +00002622 return DeclContext::lookup_result(DeclContext::lookup_iterator(),
2623 DeclContext::lookup_iterator());
Ted Kremenek1ff615c2010-03-18 00:56:54 +00002624 }
2625
John McCall75b960e2010-06-01 09:23:16 +00002626 llvm::SmallVector<VisibleDeclaration, 64> Decls;
2627 if (Record.empty()) {
2628 SetExternalVisibleDecls(DC, Decls);
2629 return DeclContext::lookup_result(DeclContext::lookup_iterator(),
2630 DeclContext::lookup_iterator());
2631 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002632
2633 unsigned Idx = 0;
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002634 while (Idx < Record.size()) {
2635 Decls.push_back(VisibleDeclaration());
2636 Decls.back().Name = ReadDeclarationName(Record, Idx);
2637
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002638 unsigned Size = Record[Idx++];
Chris Lattner72405d62009-04-27 07:35:40 +00002639 llvm::SmallVector<unsigned, 4> &LoadedDecls = Decls.back().Declarations;
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002640 LoadedDecls.reserve(Size);
2641 for (unsigned I = 0; I < Size; ++I)
2642 LoadedDecls.push_back(Record[Idx++]);
2643 }
2644
Douglas Gregora57c3ab2009-04-22 22:34:57 +00002645 ++NumVisibleDeclContextsRead;
John McCall75b960e2010-06-01 09:23:16 +00002646
2647 SetExternalVisibleDecls(DC, Decls);
2648 return const_cast<DeclContext*>(DC)->lookup(Name);
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002649}
2650
Douglas Gregor1a0d0b92009-04-14 00:24:19 +00002651void PCHReader::StartTranslationUnit(ASTConsumer *Consumer) {
Douglas Gregorb985eeb2009-04-22 19:09:20 +00002652 this->Consumer = Consumer;
2653
Douglas Gregor1a0d0b92009-04-14 00:24:19 +00002654 if (!Consumer)
2655 return;
2656
2657 for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00002658 // Force deserialization of this decl, which will cause it to be passed to
2659 // the consumer (or queued).
2660 GetDecl(ExternalDefinitions[I]);
Douglas Gregor1a0d0b92009-04-14 00:24:19 +00002661 }
Douglas Gregorf005eac2009-04-25 00:41:30 +00002662
2663 for (unsigned I = 0, N = InterestingDecls.size(); I != N; ++I) {
2664 DeclGroupRef DG(InterestingDecls[I]);
2665 Consumer->HandleTopLevelDecl(DG);
2666 }
Douglas Gregor1a0d0b92009-04-14 00:24:19 +00002667}
2668
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002669void PCHReader::PrintStats() {
2670 std::fprintf(stderr, "*** PCH Statistics:\n");
2671
Mike Stump11289f42009-09-09 15:08:12 +00002672 unsigned NumTypesLoaded
Douglas Gregor0e149972009-04-25 19:10:14 +00002673 = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(),
John McCall8ccfcb52009-09-24 19:53:00 +00002674 QualType());
Douglas Gregor0e149972009-04-25 19:10:14 +00002675 unsigned NumDeclsLoaded
2676 = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(),
2677 (Decl *)0);
2678 unsigned NumIdentifiersLoaded
2679 = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(),
2680 IdentifiersLoaded.end(),
2681 (IdentifierInfo *)0);
Mike Stump11289f42009-09-09 15:08:12 +00002682 unsigned NumSelectorsLoaded
Douglas Gregor0e149972009-04-25 19:10:14 +00002683 = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(),
2684 SelectorsLoaded.end(),
2685 Selector());
Douglas Gregorc3b1dd12009-04-13 20:50:16 +00002686
Douglas Gregorc5046832009-04-27 18:38:38 +00002687 std::fprintf(stderr, " %u stat cache hits\n", NumStatHits);
2688 std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses);
Douglas Gregor258ae542009-04-27 06:38:32 +00002689 if (TotalNumSLocEntries)
2690 std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n",
2691 NumSLocEntriesRead, TotalNumSLocEntries,
2692 ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100));
Douglas Gregor745ed142009-04-25 18:35:21 +00002693 if (!TypesLoaded.empty())
Douglas Gregor95c13f52009-04-25 17:48:32 +00002694 std::fprintf(stderr, " %u/%u types read (%f%%)\n",
Douglas Gregor745ed142009-04-25 18:35:21 +00002695 NumTypesLoaded, (unsigned)TypesLoaded.size(),
2696 ((float)NumTypesLoaded/TypesLoaded.size() * 100));
2697 if (!DeclsLoaded.empty())
Douglas Gregor95c13f52009-04-25 17:48:32 +00002698 std::fprintf(stderr, " %u/%u declarations read (%f%%)\n",
Douglas Gregor745ed142009-04-25 18:35:21 +00002699 NumDeclsLoaded, (unsigned)DeclsLoaded.size(),
2700 ((float)NumDeclsLoaded/DeclsLoaded.size() * 100));
Douglas Gregor0e149972009-04-25 19:10:14 +00002701 if (!IdentifiersLoaded.empty())
Douglas Gregor95c13f52009-04-25 17:48:32 +00002702 std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n",
Douglas Gregor0e149972009-04-25 19:10:14 +00002703 NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(),
2704 ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100));
Douglas Gregor95c13f52009-04-25 17:48:32 +00002705 if (TotalNumSelectors)
2706 std::fprintf(stderr, " %u/%u selectors read (%f%%)\n",
2707 NumSelectorsLoaded, TotalNumSelectors,
2708 ((float)NumSelectorsLoaded/TotalNumSelectors * 100));
2709 if (TotalNumStatements)
2710 std::fprintf(stderr, " %u/%u statements read (%f%%)\n",
2711 NumStatementsRead, TotalNumStatements,
2712 ((float)NumStatementsRead/TotalNumStatements * 100));
2713 if (TotalNumMacros)
2714 std::fprintf(stderr, " %u/%u macros read (%f%%)\n",
2715 NumMacrosRead, TotalNumMacros,
2716 ((float)NumMacrosRead/TotalNumMacros * 100));
2717 if (TotalLexicalDeclContexts)
2718 std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n",
2719 NumLexicalDeclContextsRead, TotalLexicalDeclContexts,
2720 ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts
2721 * 100));
2722 if (TotalVisibleDeclContexts)
2723 std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n",
2724 NumVisibleDeclContextsRead, TotalVisibleDeclContexts,
2725 ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts
2726 * 100));
2727 if (TotalSelectorsInMethodPool) {
2728 std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n",
2729 NumMethodPoolSelectorsRead, TotalSelectorsInMethodPool,
2730 ((float)NumMethodPoolSelectorsRead/TotalSelectorsInMethodPool
2731 * 100));
2732 std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses);
2733 }
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002734 std::fprintf(stderr, "\n");
2735}
2736
Douglas Gregora868bbd2009-04-21 22:25:48 +00002737void PCHReader::InitializeSema(Sema &S) {
2738 SemaObj = &S;
Douglas Gregorc78d3462009-04-24 21:10:55 +00002739 S.ExternalSource = this;
2740
Douglas Gregor7cd60f72009-04-22 21:15:06 +00002741 // Makes sure any declarations that were deserialized "too early"
2742 // still get added to the identifier's declaration chains.
2743 for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) {
2744 SemaObj->TUScope->AddDecl(Action::DeclPtrTy::make(PreloadedDecls[I]));
2745 SemaObj->IdResolver.AddDecl(PreloadedDecls[I]);
Douglas Gregora868bbd2009-04-21 22:25:48 +00002746 }
Douglas Gregor7cd60f72009-04-22 21:15:06 +00002747 PreloadedDecls.clear();
Douglas Gregord4df8652009-04-22 22:02:47 +00002748
2749 // If there were any tentative definitions, deserialize them and add
Sebastian Redl35351a92010-01-31 22:27:38 +00002750 // them to Sema's list of tentative definitions.
Douglas Gregord4df8652009-04-22 22:02:47 +00002751 for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) {
2752 VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I]));
Sebastian Redl35351a92010-01-31 22:27:38 +00002753 SemaObj->TentativeDefinitions.push_back(Var);
Douglas Gregord4df8652009-04-22 22:02:47 +00002754 }
Kovarththanan Rajaratnam39f2fbd12010-03-07 19:10:13 +00002755
Tanya Lattner90073802010-02-12 00:07:30 +00002756 // If there were any unused static functions, deserialize them and add to
2757 // Sema's list of unused static functions.
2758 for (unsigned I = 0, N = UnusedStaticFuncs.size(); I != N; ++I) {
2759 FunctionDecl *FD = cast<FunctionDecl>(GetDecl(UnusedStaticFuncs[I]));
2760 SemaObj->UnusedStaticFuncs.push_back(FD);
2761 }
Douglas Gregoracfc76c2009-04-22 22:18:58 +00002762
2763 // If there were any locally-scoped external declarations,
2764 // deserialize them and add them to Sema's table of locally-scoped
2765 // external declarations.
2766 for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) {
2767 NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I]));
2768 SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D;
2769 }
Douglas Gregor61cac2b2009-04-27 20:06:05 +00002770
2771 // If there were any ext_vector type declarations, deserialize them
2772 // and add them to Sema's vector of such declarations.
2773 for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I)
2774 SemaObj->ExtVectorDecls.push_back(
2775 cast<TypedefDecl>(GetDecl(ExtVectorDecls[I])));
Douglas Gregora868bbd2009-04-21 22:25:48 +00002776}
2777
2778IdentifierInfo* PCHReader::get(const char *NameStart, const char *NameEnd) {
2779 // Try to find this name within our on-disk hash table
Mike Stump11289f42009-09-09 15:08:12 +00002780 PCHIdentifierLookupTable *IdTable
Douglas Gregora868bbd2009-04-21 22:25:48 +00002781 = (PCHIdentifierLookupTable *)IdentifierLookupTable;
2782 std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart);
2783 PCHIdentifierLookupTable::iterator Pos = IdTable->find(Key);
2784 if (Pos == IdTable->end())
2785 return 0;
2786
2787 // Dereferencing the iterator has the effect of building the
2788 // IdentifierInfo node and populating it with the various
2789 // declarations it needs.
2790 return *Pos;
2791}
2792
Mike Stump11289f42009-09-09 15:08:12 +00002793std::pair<ObjCMethodList, ObjCMethodList>
Douglas Gregorc78d3462009-04-24 21:10:55 +00002794PCHReader::ReadMethodPool(Selector Sel) {
2795 if (!MethodPoolLookupTable)
2796 return std::pair<ObjCMethodList, ObjCMethodList>();
2797
2798 // Try to find this selector within our on-disk hash table.
2799 PCHMethodPoolLookupTable *PoolTable
2800 = (PCHMethodPoolLookupTable*)MethodPoolLookupTable;
2801 PCHMethodPoolLookupTable::iterator Pos = PoolTable->find(Sel);
Douglas Gregor95c13f52009-04-25 17:48:32 +00002802 if (Pos == PoolTable->end()) {
2803 ++NumMethodPoolMisses;
Douglas Gregorc78d3462009-04-24 21:10:55 +00002804 return std::pair<ObjCMethodList, ObjCMethodList>();;
Douglas Gregor95c13f52009-04-25 17:48:32 +00002805 }
Douglas Gregorc78d3462009-04-24 21:10:55 +00002806
Douglas Gregor95c13f52009-04-25 17:48:32 +00002807 ++NumMethodPoolSelectorsRead;
Douglas Gregorc78d3462009-04-24 21:10:55 +00002808 return *Pos;
2809}
2810
Douglas Gregor0e149972009-04-25 19:10:14 +00002811void PCHReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) {
Douglas Gregora868bbd2009-04-21 22:25:48 +00002812 assert(ID && "Non-zero identifier ID required");
Douglas Gregor6f00bf82009-04-28 21:53:25 +00002813 assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range");
Douglas Gregor0e149972009-04-25 19:10:14 +00002814 IdentifiersLoaded[ID - 1] = II;
Douglas Gregora868bbd2009-04-21 22:25:48 +00002815}
2816
Douglas Gregor1342e842009-07-06 18:54:52 +00002817/// \brief Set the globally-visible declarations associated with the given
2818/// identifier.
2819///
2820/// If the PCH reader is currently in a state where the given declaration IDs
Mike Stump11289f42009-09-09 15:08:12 +00002821/// cannot safely be resolved, they are queued until it is safe to resolve
Douglas Gregor1342e842009-07-06 18:54:52 +00002822/// them.
2823///
2824/// \param II an IdentifierInfo that refers to one or more globally-visible
2825/// declarations.
2826///
2827/// \param DeclIDs the set of declaration IDs with the name @p II that are
2828/// visible at global scope.
2829///
2830/// \param Nonrecursive should be true to indicate that the caller knows that
2831/// this call is non-recursive, and therefore the globally-visible declarations
2832/// will not be placed onto the pending queue.
Mike Stump11289f42009-09-09 15:08:12 +00002833void
2834PCHReader::SetGloballyVisibleDecls(IdentifierInfo *II,
Douglas Gregor1342e842009-07-06 18:54:52 +00002835 const llvm::SmallVectorImpl<uint32_t> &DeclIDs,
2836 bool Nonrecursive) {
2837 if (CurrentlyLoadingTypeOrDecl && !Nonrecursive) {
2838 PendingIdentifierInfos.push_back(PendingIdentifierInfo());
2839 PendingIdentifierInfo &PII = PendingIdentifierInfos.back();
2840 PII.II = II;
2841 for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I)
2842 PII.DeclIDs.push_back(DeclIDs[I]);
2843 return;
2844 }
Mike Stump11289f42009-09-09 15:08:12 +00002845
Douglas Gregor1342e842009-07-06 18:54:52 +00002846 for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) {
2847 NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I]));
2848 if (SemaObj) {
2849 // Introduce this declaration into the translation-unit scope
2850 // and add it to the declaration chain for this identifier, so
2851 // that (unqualified) name lookup will find it.
2852 SemaObj->TUScope->AddDecl(Action::DeclPtrTy::make(D));
2853 SemaObj->IdResolver.AddDeclToIdentifierChain(II, D);
2854 } else {
2855 // Queue this declaration so that it will be added to the
2856 // translation unit scope and identifier's declaration chain
2857 // once a Sema object is known.
2858 PreloadedDecls.push_back(D);
2859 }
2860 }
2861}
2862
Chris Lattnerc523d8e2009-04-11 21:15:38 +00002863IdentifierInfo *PCHReader::DecodeIdentifierInfo(unsigned ID) {
Douglas Gregor3ed42cb2009-04-11 00:14:32 +00002864 if (ID == 0)
2865 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002866
Douglas Gregor0e149972009-04-25 19:10:14 +00002867 if (!IdentifierTableData || IdentifiersLoaded.empty()) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00002868 Error("no identifier table in PCH file");
Douglas Gregor3ed42cb2009-04-11 00:14:32 +00002869 return 0;
2870 }
Mike Stump11289f42009-09-09 15:08:12 +00002871
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00002872 assert(PP && "Forgot to set Preprocessor ?");
Douglas Gregor0e149972009-04-25 19:10:14 +00002873 if (!IdentifiersLoaded[ID - 1]) {
2874 uint32_t Offset = IdentifierOffsets[ID - 1];
Douglas Gregor95272492009-04-25 21:21:38 +00002875 const char *Str = IdentifierTableData + Offset;
Douglas Gregor5287b4e2009-04-25 21:04:17 +00002876
Douglas Gregorab4df582009-04-28 20:01:51 +00002877 // All of the strings in the PCH file are preceded by a 16-bit
2878 // length. Extract that 16-bit length to avoid having to execute
2879 // strlen().
Ted Kremenekca42a512009-10-23 04:45:31 +00002880 // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as
2881 // unsigned integers. This is important to avoid integer overflow when
2882 // we cast them to 'unsigned'.
Ted Kremenek49c52322009-10-23 03:57:22 +00002883 const unsigned char *StrLenPtr = (const unsigned char*) Str - 2;
Douglas Gregorab4df582009-04-28 20:01:51 +00002884 unsigned StrLen = (((unsigned) StrLenPtr[0])
2885 | (((unsigned) StrLenPtr[1]) << 8)) - 1;
Mike Stump11289f42009-09-09 15:08:12 +00002886 IdentifiersLoaded[ID - 1]
Kovarththanan Rajaratnama3b09592010-03-12 10:32:27 +00002887 = &PP->getIdentifierTable().get(Str, StrLen);
Douglas Gregor3ed42cb2009-04-11 00:14:32 +00002888 }
Mike Stump11289f42009-09-09 15:08:12 +00002889
Douglas Gregor0e149972009-04-25 19:10:14 +00002890 return IdentifiersLoaded[ID - 1];
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002891}
2892
Douglas Gregor258ae542009-04-27 06:38:32 +00002893void PCHReader::ReadSLocEntry(unsigned ID) {
2894 ReadSLocEntryRecord(ID);
2895}
2896
Steve Naroff2ddea052009-04-23 10:39:46 +00002897Selector PCHReader::DecodeSelector(unsigned ID) {
2898 if (ID == 0)
2899 return Selector();
Mike Stump11289f42009-09-09 15:08:12 +00002900
Douglas Gregor6f00bf82009-04-28 21:53:25 +00002901 if (!MethodPoolLookupTableData)
Steve Naroff2ddea052009-04-23 10:39:46 +00002902 return Selector();
Douglas Gregor95c13f52009-04-25 17:48:32 +00002903
2904 if (ID > TotalNumSelectors) {
Douglas Gregor6f00bf82009-04-28 21:53:25 +00002905 Error("selector ID out of range in PCH file");
Steve Naroff2ddea052009-04-23 10:39:46 +00002906 return Selector();
2907 }
Douglas Gregor95c13f52009-04-25 17:48:32 +00002908
2909 unsigned Index = ID - 1;
2910 if (SelectorsLoaded[Index].getAsOpaquePtr() == 0) {
2911 // Load this selector from the selector table.
2912 // FIXME: endianness portability issues with SelectorOffsets table
2913 PCHMethodPoolLookupTrait Trait(*this);
Mike Stump11289f42009-09-09 15:08:12 +00002914 SelectorsLoaded[Index]
Douglas Gregor95c13f52009-04-25 17:48:32 +00002915 = Trait.ReadKey(MethodPoolLookupTableData + SelectorOffsets[Index], 0);
2916 }
2917
2918 return SelectorsLoaded[Index];
Steve Naroff2ddea052009-04-23 10:39:46 +00002919}
2920
John McCall75b960e2010-06-01 09:23:16 +00002921Selector PCHReader::GetExternalSelector(uint32_t ID) {
Douglas Gregord720daf2010-04-06 17:30:22 +00002922 return DecodeSelector(ID);
2923}
2924
John McCall75b960e2010-06-01 09:23:16 +00002925uint32_t PCHReader::GetNumExternalSelectors() {
Douglas Gregord720daf2010-04-06 17:30:22 +00002926 return TotalNumSelectors + 1;
2927}
2928
Mike Stump11289f42009-09-09 15:08:12 +00002929DeclarationName
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002930PCHReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) {
2931 DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++];
2932 switch (Kind) {
2933 case DeclarationName::Identifier:
2934 return DeclarationName(GetIdentifierInfo(Record, Idx));
2935
2936 case DeclarationName::ObjCZeroArgSelector:
2937 case DeclarationName::ObjCOneArgSelector:
2938 case DeclarationName::ObjCMultiArgSelector:
Steve Naroff3c301dc2009-04-23 15:15:40 +00002939 return DeclarationName(GetSelector(Record, Idx));
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002940
2941 case DeclarationName::CXXConstructorName:
Chris Lattner8575daa2009-04-27 21:45:14 +00002942 return Context->DeclarationNames.getCXXConstructorName(
Douglas Gregor2211d342009-08-05 05:36:45 +00002943 Context->getCanonicalType(GetType(Record[Idx++])));
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002944
2945 case DeclarationName::CXXDestructorName:
Chris Lattner8575daa2009-04-27 21:45:14 +00002946 return Context->DeclarationNames.getCXXDestructorName(
Douglas Gregor2211d342009-08-05 05:36:45 +00002947 Context->getCanonicalType(GetType(Record[Idx++])));
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002948
2949 case DeclarationName::CXXConversionFunctionName:
Chris Lattner8575daa2009-04-27 21:45:14 +00002950 return Context->DeclarationNames.getCXXConversionFunctionName(
Douglas Gregor2211d342009-08-05 05:36:45 +00002951 Context->getCanonicalType(GetType(Record[Idx++])));
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002952
2953 case DeclarationName::CXXOperatorName:
Chris Lattner8575daa2009-04-27 21:45:14 +00002954 return Context->DeclarationNames.getCXXOperatorName(
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002955 (OverloadedOperatorKind)Record[Idx++]);
2956
Alexis Hunt3d221f22009-11-29 07:34:05 +00002957 case DeclarationName::CXXLiteralOperatorName:
2958 return Context->DeclarationNames.getCXXLiteralOperatorName(
2959 GetIdentifierInfo(Record, Idx));
2960
Douglas Gregoref84c4b2009-04-09 22:27:44 +00002961 case DeclarationName::CXXUsingDirective:
2962 return DeclarationName::getUsingDirectiveName();
2963 }
2964
2965 // Required to silence GCC warning
2966 return DeclarationName();
2967}
Douglas Gregor55abb232009-04-10 20:39:37 +00002968
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002969TemplateName
2970PCHReader::ReadTemplateName(const RecordData &Record, unsigned &Idx) {
2971 TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++];
2972 switch (Kind) {
2973 case TemplateName::Template:
2974 return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++])));
2975
2976 case TemplateName::OverloadedTemplate: {
2977 unsigned size = Record[Idx++];
2978 UnresolvedSet<8> Decls;
2979 while (size--)
2980 Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++])));
2981
2982 return Context->getOverloadedTemplateName(Decls.begin(), Decls.end());
2983 }
2984
2985 case TemplateName::QualifiedTemplate: {
2986 NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx);
2987 bool hasTemplKeyword = Record[Idx++];
2988 TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++]));
2989 return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template);
2990 }
2991
2992 case TemplateName::DependentTemplate: {
2993 NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx);
2994 if (Record[Idx++]) // isIdentifier
2995 return Context->getDependentTemplateName(NNS,
2996 GetIdentifierInfo(Record, Idx));
2997 return Context->getDependentTemplateName(NNS,
2998 (OverloadedOperatorKind)Record[Idx++]);
2999 }
3000 }
3001
3002 assert(0 && "Unhandled template name kind!");
3003 return TemplateName();
3004}
3005
3006TemplateArgument
3007PCHReader::ReadTemplateArgument(const RecordData &Record, unsigned &Idx) {
3008 switch ((TemplateArgument::ArgKind)Record[Idx++]) {
3009 case TemplateArgument::Null:
3010 return TemplateArgument();
3011 case TemplateArgument::Type:
3012 return TemplateArgument(GetType(Record[Idx++]));
3013 case TemplateArgument::Declaration:
3014 return TemplateArgument(GetDecl(Record[Idx++]));
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +00003015 case TemplateArgument::Integral: {
3016 llvm::APSInt Value = ReadAPSInt(Record, Idx);
3017 QualType T = GetType(Record[Idx++]);
3018 return TemplateArgument(Value, T);
3019 }
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00003020 case TemplateArgument::Template:
3021 return TemplateArgument(ReadTemplateName(Record, Idx));
3022 case TemplateArgument::Expression:
3023 return TemplateArgument(ReadDeclExpr());
3024 case TemplateArgument::Pack: {
3025 unsigned NumArgs = Record[Idx++];
3026 llvm::SmallVector<TemplateArgument, 8> Args;
3027 Args.reserve(NumArgs);
3028 while (NumArgs--)
3029 Args.push_back(ReadTemplateArgument(Record, Idx));
3030 TemplateArgument TemplArg;
3031 TemplArg.setArgumentPack(Args.data(), Args.size(), /*CopyArgs=*/true);
3032 return TemplArg;
3033 }
3034 }
3035
3036 assert(0 && "Unhandled template argument kind!");
3037 return TemplateArgument();
3038}
3039
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00003040TemplateParameterList *
3041PCHReader::ReadTemplateParameterList(const RecordData &Record, unsigned &Idx) {
3042 SourceLocation TemplateLoc = ReadSourceLocation(Record, Idx);
3043 SourceLocation LAngleLoc = ReadSourceLocation(Record, Idx);
3044 SourceLocation RAngleLoc = ReadSourceLocation(Record, Idx);
3045
3046 unsigned NumParams = Record[Idx++];
3047 llvm::SmallVector<NamedDecl *, 16> Params;
3048 Params.reserve(NumParams);
3049 while (NumParams--)
3050 Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++])));
3051
3052 TemplateParameterList* TemplateParams =
3053 TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc,
3054 Params.data(), Params.size(), RAngleLoc);
3055 return TemplateParams;
3056}
3057
3058void
3059PCHReader::
3060ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs,
3061 const RecordData &Record, unsigned &Idx) {
3062 unsigned NumTemplateArgs = Record[Idx++];
3063 TemplArgs.reserve(NumTemplateArgs);
3064 while (NumTemplateArgs--)
3065 TemplArgs.push_back(ReadTemplateArgument(Record, Idx));
3066}
3067
Chris Lattnerca025db2010-05-07 21:43:38 +00003068NestedNameSpecifier *
3069PCHReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) {
3070 unsigned N = Record[Idx++];
3071 NestedNameSpecifier *NNS = 0, *Prev = 0;
3072 for (unsigned I = 0; I != N; ++I) {
3073 NestedNameSpecifier::SpecifierKind Kind
3074 = (NestedNameSpecifier::SpecifierKind)Record[Idx++];
3075 switch (Kind) {
3076 case NestedNameSpecifier::Identifier: {
3077 IdentifierInfo *II = GetIdentifierInfo(Record, Idx);
3078 NNS = NestedNameSpecifier::Create(*Context, Prev, II);
3079 break;
3080 }
3081
3082 case NestedNameSpecifier::Namespace: {
3083 NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++]));
3084 NNS = NestedNameSpecifier::Create(*Context, Prev, NS);
3085 break;
3086 }
3087
3088 case NestedNameSpecifier::TypeSpec:
3089 case NestedNameSpecifier::TypeSpecWithTemplate: {
3090 Type *T = GetType(Record[Idx++]).getTypePtr();
3091 bool Template = Record[Idx++];
3092 NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T);
3093 break;
3094 }
3095
3096 case NestedNameSpecifier::Global: {
3097 NNS = NestedNameSpecifier::GlobalSpecifier(*Context);
3098 // No associated value, and there can't be a prefix.
3099 break;
3100 }
3101 Prev = NNS;
3102 }
3103 }
3104 return NNS;
3105}
3106
3107SourceRange
3108PCHReader::ReadSourceRange(const RecordData &Record, unsigned &Idx) {
Daniel Dunbar6d3bc082010-06-02 15:47:10 +00003109 SourceLocation beg = SourceLocation::getFromRawEncoding(Record[Idx++]);
3110 SourceLocation end = SourceLocation::getFromRawEncoding(Record[Idx++]);
3111 return SourceRange(beg, end);
Chris Lattnerca025db2010-05-07 21:43:38 +00003112}
3113
Douglas Gregor1daeb692009-04-13 18:14:40 +00003114/// \brief Read an integral value
3115llvm::APInt PCHReader::ReadAPInt(const RecordData &Record, unsigned &Idx) {
3116 unsigned BitWidth = Record[Idx++];
3117 unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
3118 llvm::APInt Result(BitWidth, NumWords, &Record[Idx]);
3119 Idx += NumWords;
3120 return Result;
3121}
3122
3123/// \brief Read a signed integral value
3124llvm::APSInt PCHReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) {
3125 bool isUnsigned = Record[Idx++];
3126 return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned);
3127}
3128
Douglas Gregore0a3a512009-04-14 21:55:33 +00003129/// \brief Read a floating-point value
3130llvm::APFloat PCHReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) {
Douglas Gregore0a3a512009-04-14 21:55:33 +00003131 return llvm::APFloat(ReadAPInt(Record, Idx));
3132}
3133
Douglas Gregorbc8a78d52009-04-15 21:30:51 +00003134// \brief Read a string
3135std::string PCHReader::ReadString(const RecordData &Record, unsigned &Idx) {
3136 unsigned Len = Record[Idx++];
Jay Foad7d0479f2009-05-21 09:52:38 +00003137 std::string Result(Record.data() + Idx, Record.data() + Idx + Len);
Douglas Gregorbc8a78d52009-04-15 21:30:51 +00003138 Idx += Len;
3139 return Result;
3140}
3141
Chris Lattnercba86142010-05-10 00:25:06 +00003142CXXTemporary *PCHReader::ReadCXXTemporary(const RecordData &Record,
3143 unsigned &Idx) {
3144 CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++]));
3145 return CXXTemporary::Create(*Context, Decl);
3146}
3147
Douglas Gregor55abb232009-04-10 20:39:37 +00003148DiagnosticBuilder PCHReader::Diag(unsigned DiagID) {
Douglas Gregor92863e42009-04-10 23:10:45 +00003149 return Diag(SourceLocation(), DiagID);
3150}
3151
3152DiagnosticBuilder PCHReader::Diag(SourceLocation Loc, unsigned DiagID) {
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00003153 return Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
Douglas Gregor55abb232009-04-10 20:39:37 +00003154}
Douglas Gregora9af1d12009-04-17 00:04:06 +00003155
Douglas Gregora868bbd2009-04-21 22:25:48 +00003156/// \brief Retrieve the identifier table associated with the
3157/// preprocessor.
3158IdentifierTable &PCHReader::getIdentifierTable() {
Argyrios Kyrtzidis366985d2009-06-19 00:03:23 +00003159 assert(PP && "Forgot to set Preprocessor ?");
3160 return PP->getIdentifierTable();
Douglas Gregora868bbd2009-04-21 22:25:48 +00003161}
3162
Douglas Gregora9af1d12009-04-17 00:04:06 +00003163/// \brief Record that the given ID maps to the given switch-case
3164/// statement.
3165void PCHReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) {
3166 assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID");
3167 SwitchCaseStmts[ID] = SC;
3168}
3169
3170/// \brief Retrieve the switch-case statement with the given ID.
3171SwitchCase *PCHReader::getSwitchCaseWithID(unsigned ID) {
3172 assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID");
3173 return SwitchCaseStmts[ID];
3174}
Douglas Gregor6cc68a42009-04-17 18:18:49 +00003175
3176/// \brief Record that the given label statement has been
3177/// deserialized and has the given ID.
3178void PCHReader::RecordLabelStmt(LabelStmt *S, unsigned ID) {
Mike Stump11289f42009-09-09 15:08:12 +00003179 assert(LabelStmts.find(ID) == LabelStmts.end() &&
Douglas Gregor6cc68a42009-04-17 18:18:49 +00003180 "Deserialized label twice");
3181 LabelStmts[ID] = S;
3182
3183 // If we've already seen any goto statements that point to this
3184 // label, resolve them now.
3185 typedef std::multimap<unsigned, GotoStmt *>::iterator GotoIter;
3186 std::pair<GotoIter, GotoIter> Gotos = UnresolvedGotoStmts.equal_range(ID);
3187 for (GotoIter Goto = Gotos.first; Goto != Gotos.second; ++Goto)
3188 Goto->second->setLabel(S);
3189 UnresolvedGotoStmts.erase(Gotos.first, Gotos.second);
Douglas Gregor779d8652009-04-17 18:58:21 +00003190
3191 // If we've already seen any address-label statements that point to
3192 // this label, resolve them now.
3193 typedef std::multimap<unsigned, AddrLabelExpr *>::iterator AddrLabelIter;
Mike Stump11289f42009-09-09 15:08:12 +00003194 std::pair<AddrLabelIter, AddrLabelIter> AddrLabels
Douglas Gregor779d8652009-04-17 18:58:21 +00003195 = UnresolvedAddrLabelExprs.equal_range(ID);
Mike Stump11289f42009-09-09 15:08:12 +00003196 for (AddrLabelIter AddrLabel = AddrLabels.first;
Douglas Gregor779d8652009-04-17 18:58:21 +00003197 AddrLabel != AddrLabels.second; ++AddrLabel)
3198 AddrLabel->second->setLabel(S);
3199 UnresolvedAddrLabelExprs.erase(AddrLabels.first, AddrLabels.second);
Douglas Gregor6cc68a42009-04-17 18:18:49 +00003200}
3201
3202/// \brief Set the label of the given statement to the label
3203/// identified by ID.
3204///
3205/// Depending on the order in which the label and other statements
3206/// referencing that label occur, this operation may complete
3207/// immediately (updating the statement) or it may queue the
3208/// statement to be back-patched later.
3209void PCHReader::SetLabelOf(GotoStmt *S, unsigned ID) {
3210 std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID);
3211 if (Label != LabelStmts.end()) {
3212 // We've already seen this label, so set the label of the goto and
3213 // we're done.
3214 S->setLabel(Label->second);
3215 } else {
3216 // We haven't seen this label yet, so add this goto to the set of
3217 // unresolved goto statements.
3218 UnresolvedGotoStmts.insert(std::make_pair(ID, S));
3219 }
3220}
Douglas Gregor779d8652009-04-17 18:58:21 +00003221
3222/// \brief Set the label of the given expression to the label
3223/// identified by ID.
3224///
3225/// Depending on the order in which the label and other statements
3226/// referencing that label occur, this operation may complete
3227/// immediately (updating the statement) or it may queue the
3228/// statement to be back-patched later.
3229void PCHReader::SetLabelOf(AddrLabelExpr *S, unsigned ID) {
3230 std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID);
3231 if (Label != LabelStmts.end()) {
3232 // We've already seen this label, so set the label of the
3233 // label-address expression and we're done.
3234 S->setLabel(Label->second);
3235 } else {
3236 // We haven't seen this label yet, so add this label-address
3237 // expression to the set of unresolved label-address expressions.
3238 UnresolvedAddrLabelExprs.insert(std::make_pair(ID, S));
3239 }
3240}
Douglas Gregor1342e842009-07-06 18:54:52 +00003241
3242
Mike Stump11289f42009-09-09 15:08:12 +00003243PCHReader::LoadingTypeOrDecl::LoadingTypeOrDecl(PCHReader &Reader)
Douglas Gregor1342e842009-07-06 18:54:52 +00003244 : Reader(Reader), Parent(Reader.CurrentlyLoadingTypeOrDecl) {
3245 Reader.CurrentlyLoadingTypeOrDecl = this;
3246}
3247
3248PCHReader::LoadingTypeOrDecl::~LoadingTypeOrDecl() {
3249 if (!Parent) {
3250 // If any identifiers with corresponding top-level declarations have
3251 // been loaded, load those declarations now.
3252 while (!Reader.PendingIdentifierInfos.empty()) {
3253 Reader.SetGloballyVisibleDecls(Reader.PendingIdentifierInfos.front().II,
3254 Reader.PendingIdentifierInfos.front().DeclIDs,
3255 true);
3256 Reader.PendingIdentifierInfos.pop_front();
3257 }
3258 }
3259
Mike Stump11289f42009-09-09 15:08:12 +00003260 Reader.CurrentlyLoadingTypeOrDecl = Parent;
Douglas Gregor1342e842009-07-06 18:54:52 +00003261}