Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1 | //===--- PCHReader.cpp - Precompiled Headers Reader -------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the PCHReader class, which reads a precompiled header. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 13 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 14 | #include "clang/Frontend/PCHReader.h" |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 15 | #include "clang/Frontend/FrontendDiagnostic.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 16 | #include "../Sema/Sema.h" // FIXME: move Sema headers elsewhere |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 20 | #include "clang/AST/Type.h" |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 21 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 22 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 23 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 24 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 25 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 26 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 27 | #include "clang/Basic/FileManager.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 28 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 29 | #include "llvm/Bitcode/BitstreamReader.h" |
| 30 | #include "llvm/Support/Compiler.h" |
| 31 | #include "llvm/Support/MemoryBuffer.h" |
| 32 | #include <algorithm> |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 33 | #include <iterator> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 34 | #include <cstdio> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 35 | #include <sys/stat.h> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 36 | using namespace clang; |
| 37 | |
| 38 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 39 | // PCH reader validator implementation |
| 40 | //===----------------------------------------------------------------------===// |
| 41 | |
| 42 | PCHReaderListener::~PCHReaderListener() {} |
| 43 | |
| 44 | bool |
| 45 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 46 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 47 | #define PARSE_LANGOPT_BENIGN(Option) |
| 48 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 49 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 50 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 51 | return true; \ |
| 52 | } |
| 53 | |
| 54 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 55 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 56 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 57 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 58 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
| 59 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 60 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 61 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 62 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
| 63 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
| 64 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 65 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 66 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 67 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 68 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 69 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
| 70 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 71 | PARSE_LANGOPT_BENIGN(WritableStrings); |
| 72 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
| 73 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 74 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 75 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
| 76 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 77 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 78 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
| 79 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
| 80 | diag::warn_pch_thread_safe_statics); |
| 81 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 82 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 83 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
| 84 | PARSE_LANGOPT_IMPORTANT(OverflowChecking, diag::warn_pch_overflow_checking); |
| 85 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
| 86 | diag::warn_pch_heinous_extensions); |
| 87 | // FIXME: Most of the options below are benign if the macro wasn't |
| 88 | // used. Unfortunately, this means that a PCH compiled without |
| 89 | // optimization can't be used with optimization turned on, even |
| 90 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 91 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 92 | // doesn't matter. We could consider making this some special kind |
| 93 | // of check. |
| 94 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 95 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 96 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 97 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 98 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 99 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
| 100 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 101 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
| 102 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
| 103 | Reader.Diag(diag::warn_pch_gc_mode) |
| 104 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 105 | return true; |
| 106 | } |
| 107 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
| 108 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 69cfb9b | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 109 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 110 | #undef PARSE_LANGOPT_IRRELEVANT |
| 111 | #undef PARSE_LANGOPT_BENIGN |
| 112 | |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | bool PCHValidator::ReadTargetTriple(const std::string &Triple) { |
| 117 | if (Triple != PP.getTargetInfo().getTargetTriple()) { |
| 118 | Reader.Diag(diag::warn_pch_target_triple) |
| 119 | << Triple << PP.getTargetInfo().getTargetTriple(); |
| 120 | return true; |
| 121 | } |
| 122 | return false; |
| 123 | } |
| 124 | |
| 125 | /// \brief Split the given string into a vector of lines, eliminating |
| 126 | /// any empty lines in the process. |
| 127 | /// |
| 128 | /// \param Str the string to split. |
| 129 | /// \param Len the length of Str. |
| 130 | /// \param KeepEmptyLines true if empty lines should be included |
| 131 | /// \returns a vector of lines, with the line endings removed |
| 132 | static std::vector<std::string> splitLines(const char *Str, unsigned Len, |
| 133 | bool KeepEmptyLines = false) { |
| 134 | std::vector<std::string> Lines; |
| 135 | for (unsigned LineStart = 0; LineStart < Len; ++LineStart) { |
| 136 | unsigned LineEnd = LineStart; |
| 137 | while (LineEnd < Len && Str[LineEnd] != '\n') |
| 138 | ++LineEnd; |
| 139 | if (LineStart != LineEnd || KeepEmptyLines) |
| 140 | Lines.push_back(std::string(&Str[LineStart], &Str[LineEnd])); |
| 141 | LineStart = LineEnd; |
| 142 | } |
| 143 | return Lines; |
| 144 | } |
| 145 | |
| 146 | /// \brief Determine whether the string Haystack starts with the |
| 147 | /// substring Needle. |
| 148 | static bool startsWith(const std::string &Haystack, const char *Needle) { |
| 149 | for (unsigned I = 0, N = Haystack.size(); Needle[I] != 0; ++I) { |
| 150 | if (I == N) |
| 151 | return false; |
| 152 | if (Haystack[I] != Needle[I]) |
| 153 | return false; |
| 154 | } |
| 155 | |
| 156 | return true; |
| 157 | } |
| 158 | |
| 159 | /// \brief Determine whether the string Haystack starts with the |
| 160 | /// substring Needle. |
| 161 | static inline bool startsWith(const std::string &Haystack, |
| 162 | const std::string &Needle) { |
| 163 | return startsWith(Haystack, Needle.c_str()); |
| 164 | } |
| 165 | |
| 166 | bool PCHValidator::ReadPredefinesBuffer(const char *PCHPredef, |
| 167 | unsigned PCHPredefLen, |
| 168 | FileID PCHBufferID, |
| 169 | std::string &SuggestedPredefines) { |
| 170 | const char *Predef = PP.getPredefines().c_str(); |
| 171 | unsigned PredefLen = PP.getPredefines().size(); |
| 172 | |
| 173 | // If the two predefines buffers compare equal, we're done! |
| 174 | if (PredefLen == PCHPredefLen && |
| 175 | strncmp(Predef, PCHPredef, PCHPredefLen) == 0) |
| 176 | return false; |
| 177 | |
| 178 | SourceManager &SourceMgr = PP.getSourceManager(); |
| 179 | |
| 180 | // The predefines buffers are different. Determine what the |
| 181 | // differences are, and whether they require us to reject the PCH |
| 182 | // file. |
| 183 | std::vector<std::string> CmdLineLines = splitLines(Predef, PredefLen); |
| 184 | std::vector<std::string> PCHLines = splitLines(PCHPredef, PCHPredefLen); |
| 185 | |
| 186 | // Sort both sets of predefined buffer lines, since |
| 187 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 188 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 189 | |
| 190 | // Determine which predefines that where used to build the PCH file |
| 191 | // are missing from the command line. |
| 192 | std::vector<std::string> MissingPredefines; |
| 193 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 194 | CmdLineLines.begin(), CmdLineLines.end(), |
| 195 | std::back_inserter(MissingPredefines)); |
| 196 | |
| 197 | bool MissingDefines = false; |
| 198 | bool ConflictingDefines = false; |
| 199 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
| 200 | const std::string &Missing = MissingPredefines[I]; |
| 201 | if (!startsWith(Missing, "#define ") != 0) { |
| 202 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 203 | return true; |
| 204 | } |
| 205 | |
| 206 | // This is a macro definition. Determine the name of the macro |
| 207 | // we're defining. |
| 208 | std::string::size_type StartOfMacroName = strlen("#define "); |
| 209 | std::string::size_type EndOfMacroName |
| 210 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 211 | assert(EndOfMacroName != std::string::npos && |
| 212 | "Couldn't find the end of the macro name"); |
| 213 | std::string MacroName = Missing.substr(StartOfMacroName, |
| 214 | EndOfMacroName - StartOfMacroName); |
| 215 | |
| 216 | // Determine whether this macro was given a different definition |
| 217 | // on the command line. |
| 218 | std::string MacroDefStart = "#define " + MacroName; |
| 219 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
| 220 | std::vector<std::string>::iterator ConflictPos |
| 221 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 222 | MacroDefStart); |
| 223 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
| 224 | if (!startsWith(*ConflictPos, MacroDefStart)) { |
| 225 | // Different macro; we're done. |
| 226 | ConflictPos = CmdLineLines.end(); |
| 227 | break; |
| 228 | } |
| 229 | |
| 230 | assert(ConflictPos->size() > MacroDefLen && |
| 231 | "Invalid #define in predefines buffer?"); |
| 232 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
| 233 | (*ConflictPos)[MacroDefLen] != '(') |
| 234 | continue; // Longer macro name; keep trying. |
| 235 | |
| 236 | // We found a conflicting macro definition. |
| 237 | break; |
| 238 | } |
| 239 | |
| 240 | if (ConflictPos != CmdLineLines.end()) { |
| 241 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 242 | << MacroName; |
| 243 | |
| 244 | // Show the definition of this macro within the PCH file. |
| 245 | const char *MissingDef = strstr(PCHPredef, Missing.c_str()); |
| 246 | unsigned Offset = MissingDef - PCHPredef; |
| 247 | SourceLocation PCHMissingLoc |
| 248 | = SourceMgr.getLocForStartOfFile(PCHBufferID) |
| 249 | .getFileLocWithOffset(Offset); |
| 250 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) |
| 251 | << MacroName; |
| 252 | |
| 253 | ConflictingDefines = true; |
| 254 | continue; |
| 255 | } |
| 256 | |
| 257 | // If the macro doesn't conflict, then we'll just pick up the |
| 258 | // macro definition from the PCH file. Warn the user that they |
| 259 | // made a mistake. |
| 260 | if (ConflictingDefines) |
| 261 | continue; // Don't complain if there are already conflicting defs |
| 262 | |
| 263 | if (!MissingDefines) { |
| 264 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 265 | MissingDefines = true; |
| 266 | } |
| 267 | |
| 268 | // Show the definition of this macro within the PCH file. |
| 269 | const char *MissingDef = strstr(PCHPredef, Missing.c_str()); |
| 270 | unsigned Offset = MissingDef - PCHPredef; |
| 271 | SourceLocation PCHMissingLoc |
| 272 | = SourceMgr.getLocForStartOfFile(PCHBufferID) |
| 273 | .getFileLocWithOffset(Offset); |
| 274 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 275 | } |
| 276 | |
| 277 | if (ConflictingDefines) |
| 278 | return true; |
| 279 | |
| 280 | // Determine what predefines were introduced based on command-line |
| 281 | // parameters that were not present when building the PCH |
| 282 | // file. Extra #defines are okay, so long as the identifiers being |
| 283 | // defined were not used within the precompiled header. |
| 284 | std::vector<std::string> ExtraPredefines; |
| 285 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 286 | PCHLines.begin(), PCHLines.end(), |
| 287 | std::back_inserter(ExtraPredefines)); |
| 288 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
| 289 | const std::string &Extra = ExtraPredefines[I]; |
| 290 | if (!startsWith(Extra, "#define ") != 0) { |
| 291 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 292 | return true; |
| 293 | } |
| 294 | |
| 295 | // This is an extra macro definition. Determine the name of the |
| 296 | // macro we're defining. |
| 297 | std::string::size_type StartOfMacroName = strlen("#define "); |
| 298 | std::string::size_type EndOfMacroName |
| 299 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 300 | assert(EndOfMacroName != std::string::npos && |
| 301 | "Couldn't find the end of the macro name"); |
| 302 | std::string MacroName = Extra.substr(StartOfMacroName, |
| 303 | EndOfMacroName - StartOfMacroName); |
| 304 | |
| 305 | // Check whether this name was used somewhere in the PCH file. If |
| 306 | // so, defining it as a macro could change behavior, so we reject |
| 307 | // the PCH file. |
| 308 | if (IdentifierInfo *II = Reader.get(MacroName.c_str(), |
| 309 | MacroName.c_str() + MacroName.size())) { |
| 310 | Reader.Diag(diag::warn_macro_name_used_in_pch) |
| 311 | << II; |
| 312 | return true; |
| 313 | } |
| 314 | |
| 315 | // Add this definition to the suggested predefines buffer. |
| 316 | SuggestedPredefines += Extra; |
| 317 | SuggestedPredefines += '\n'; |
| 318 | } |
| 319 | |
| 320 | // If we get here, it's because the predefines buffer had compatible |
| 321 | // contents. Accept the PCH file. |
| 322 | return false; |
| 323 | } |
| 324 | |
| 325 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI) { |
| 326 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, NumHeaderInfos++); |
| 327 | } |
| 328 | |
| 329 | void PCHValidator::ReadCounter(unsigned Value) { |
| 330 | PP.setCounterValue(Value); |
| 331 | } |
| 332 | |
| 333 | |
| 334 | |
| 335 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 336 | // PCH reader implementation |
| 337 | //===----------------------------------------------------------------------===// |
| 338 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 339 | PCHReader::PCHReader(Preprocessor &PP, ASTContext *Context, |
| 340 | const char *isysroot) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 341 | : Listener(new PCHValidator(PP, *this)), SourceMgr(PP.getSourceManager()), |
| 342 | FileMgr(PP.getFileManager()), Diags(PP.getDiagnostics()), |
| 343 | SemaObj(0), PP(&PP), Context(Context), Consumer(0), |
| 344 | IdentifierTableData(0), IdentifierLookupTable(0), |
| 345 | IdentifierOffsets(0), |
| 346 | MethodPoolLookupTable(0), MethodPoolLookupTableData(0), |
| 347 | TotalSelectorsInMethodPool(0), SelectorOffsets(0), |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 348 | TotalNumSelectors(0), Comments(0), NumComments(0), isysroot(isysroot), |
Douglas Gregor | 2e22253 | 2009-07-02 17:08:52 +0000 | [diff] [blame] | 349 | NumStatHits(0), NumStatMisses(0), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 350 | NumSLocEntriesRead(0), NumStatementsRead(0), |
| 351 | NumMacrosRead(0), NumMethodPoolSelectorsRead(0), NumMethodPoolMisses(0), |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 352 | NumLexicalDeclContextsRead(0), NumVisibleDeclContextsRead(0), |
| 353 | CurrentlyLoadingTypeOrDecl(0) { |
| 354 | RelocatablePCH = false; |
| 355 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 356 | |
| 357 | PCHReader::PCHReader(SourceManager &SourceMgr, FileManager &FileMgr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 358 | Diagnostic &Diags, const char *isysroot) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 359 | : SourceMgr(SourceMgr), FileMgr(FileMgr), Diags(Diags), |
Argyrios Kyrtzidis | 5710211 | 2009-06-19 07:55:35 +0000 | [diff] [blame] | 360 | SemaObj(0), PP(0), Context(0), Consumer(0), |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 361 | IdentifierTableData(0), IdentifierLookupTable(0), |
| 362 | IdentifierOffsets(0), |
| 363 | MethodPoolLookupTable(0), MethodPoolLookupTableData(0), |
| 364 | TotalSelectorsInMethodPool(0), SelectorOffsets(0), |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 365 | TotalNumSelectors(0), Comments(0), NumComments(0), isysroot(isysroot), |
| 366 | NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 367 | NumSLocEntriesRead(0), NumStatementsRead(0), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 368 | NumMacrosRead(0), NumMethodPoolSelectorsRead(0), NumMethodPoolMisses(0), |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 369 | NumLexicalDeclContextsRead(0), NumVisibleDeclContextsRead(0), |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 370 | CurrentlyLoadingTypeOrDecl(0) { |
| 371 | RelocatablePCH = false; |
| 372 | } |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 373 | |
| 374 | PCHReader::~PCHReader() {} |
| 375 | |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 376 | Expr *PCHReader::ReadDeclExpr() { |
| 377 | return dyn_cast_or_null<Expr>(ReadStmt(DeclsCursor)); |
| 378 | } |
| 379 | |
| 380 | Expr *PCHReader::ReadTypeExpr() { |
Chris Lattner | 52e97d1 | 2009-04-27 05:41:06 +0000 | [diff] [blame] | 381 | return dyn_cast_or_null<Expr>(ReadStmt(Stream)); |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 385 | namespace { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 386 | class VISIBILITY_HIDDEN PCHMethodPoolLookupTrait { |
| 387 | PCHReader &Reader; |
| 388 | |
| 389 | public: |
| 390 | typedef std::pair<ObjCMethodList, ObjCMethodList> data_type; |
| 391 | |
| 392 | typedef Selector external_key_type; |
| 393 | typedef external_key_type internal_key_type; |
| 394 | |
| 395 | explicit PCHMethodPoolLookupTrait(PCHReader &Reader) : Reader(Reader) { } |
| 396 | |
| 397 | static bool EqualKey(const internal_key_type& a, |
| 398 | const internal_key_type& b) { |
| 399 | return a == b; |
| 400 | } |
| 401 | |
| 402 | static unsigned ComputeHash(Selector Sel) { |
| 403 | unsigned N = Sel.getNumArgs(); |
| 404 | if (N == 0) |
| 405 | ++N; |
| 406 | unsigned R = 5381; |
| 407 | for (unsigned I = 0; I != N; ++I) |
| 408 | if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I)) |
| 409 | R = clang::BernsteinHashPartial(II->getName(), II->getLength(), R); |
| 410 | return R; |
| 411 | } |
| 412 | |
| 413 | // This hopefully will just get inlined and removed by the optimizer. |
| 414 | static const internal_key_type& |
| 415 | GetInternalKey(const external_key_type& x) { return x; } |
| 416 | |
| 417 | static std::pair<unsigned, unsigned> |
| 418 | ReadKeyDataLength(const unsigned char*& d) { |
| 419 | using namespace clang::io; |
| 420 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 421 | unsigned DataLen = ReadUnalignedLE16(d); |
| 422 | return std::make_pair(KeyLen, DataLen); |
| 423 | } |
| 424 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 425 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 426 | using namespace clang::io; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 427 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 428 | unsigned N = ReadUnalignedLE16(d); |
| 429 | IdentifierInfo *FirstII |
| 430 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 431 | if (N == 0) |
| 432 | return SelTable.getNullarySelector(FirstII); |
| 433 | else if (N == 1) |
| 434 | return SelTable.getUnarySelector(FirstII); |
| 435 | |
| 436 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 437 | Args.push_back(FirstII); |
| 438 | for (unsigned I = 1; I != N; ++I) |
| 439 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 440 | |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 441 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 445 | using namespace clang::io; |
| 446 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 447 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 448 | |
| 449 | data_type Result; |
| 450 | |
| 451 | // Load instance methods |
| 452 | ObjCMethodList *Prev = 0; |
| 453 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
| 454 | ObjCMethodDecl *Method |
| 455 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
| 456 | if (!Result.first.Method) { |
| 457 | // This is the first method, which is the easy case. |
| 458 | Result.first.Method = Method; |
| 459 | Prev = &Result.first; |
| 460 | continue; |
| 461 | } |
| 462 | |
| 463 | Prev->Next = new ObjCMethodList(Method, 0); |
| 464 | Prev = Prev->Next; |
| 465 | } |
| 466 | |
| 467 | // Load factory methods |
| 468 | Prev = 0; |
| 469 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
| 470 | ObjCMethodDecl *Method |
| 471 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
| 472 | if (!Result.second.Method) { |
| 473 | // This is the first method, which is the easy case. |
| 474 | Result.second.Method = Method; |
| 475 | Prev = &Result.second; |
| 476 | continue; |
| 477 | } |
| 478 | |
| 479 | Prev->Next = new ObjCMethodList(Method, 0); |
| 480 | Prev = Prev->Next; |
| 481 | } |
| 482 | |
| 483 | return Result; |
| 484 | } |
| 485 | }; |
| 486 | |
| 487 | } // end anonymous namespace |
| 488 | |
| 489 | /// \brief The on-disk hash table used for the global method pool. |
| 490 | typedef OnDiskChainedHashTable<PCHMethodPoolLookupTrait> |
| 491 | PCHMethodPoolLookupTable; |
| 492 | |
| 493 | namespace { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 494 | class VISIBILITY_HIDDEN PCHIdentifierLookupTrait { |
| 495 | PCHReader &Reader; |
| 496 | |
| 497 | // If we know the IdentifierInfo in advance, it is here and we will |
| 498 | // not build a new one. Used when deserializing information about an |
| 499 | // identifier that was constructed before the PCH file was read. |
| 500 | IdentifierInfo *KnownII; |
| 501 | |
| 502 | public: |
| 503 | typedef IdentifierInfo * data_type; |
| 504 | |
| 505 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 506 | |
| 507 | typedef external_key_type internal_key_type; |
| 508 | |
| 509 | explicit PCHIdentifierLookupTrait(PCHReader &Reader, IdentifierInfo *II = 0) |
| 510 | : Reader(Reader), KnownII(II) { } |
| 511 | |
| 512 | static bool EqualKey(const internal_key_type& a, |
| 513 | const internal_key_type& b) { |
| 514 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 515 | : false; |
| 516 | } |
| 517 | |
| 518 | static unsigned ComputeHash(const internal_key_type& a) { |
| 519 | return BernsteinHash(a.first, a.second); |
| 520 | } |
| 521 | |
| 522 | // This hopefully will just get inlined and removed by the optimizer. |
| 523 | static const internal_key_type& |
| 524 | GetInternalKey(const external_key_type& x) { return x; } |
| 525 | |
| 526 | static std::pair<unsigned, unsigned> |
| 527 | ReadKeyDataLength(const unsigned char*& d) { |
| 528 | using namespace clang::io; |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 529 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 530 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 531 | return std::make_pair(KeyLen, DataLen); |
| 532 | } |
| 533 | |
| 534 | static std::pair<const char*, unsigned> |
| 535 | ReadKey(const unsigned char* d, unsigned n) { |
| 536 | assert(n >= 2 && d[n-1] == '\0'); |
| 537 | return std::make_pair((const char*) d, n-1); |
| 538 | } |
| 539 | |
| 540 | IdentifierInfo *ReadData(const internal_key_type& k, |
| 541 | const unsigned char* d, |
| 542 | unsigned DataLen) { |
| 543 | using namespace clang::io; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 544 | pch::IdentID ID = ReadUnalignedLE32(d); |
| 545 | bool IsInteresting = ID & 0x01; |
| 546 | |
| 547 | // Wipe out the "is interesting" bit. |
| 548 | ID = ID >> 1; |
| 549 | |
| 550 | if (!IsInteresting) { |
| 551 | // For unintersting identifiers, just build the IdentifierInfo |
| 552 | // and associate it with the persistent ID. |
| 553 | IdentifierInfo *II = KnownII; |
| 554 | if (!II) |
| 555 | II = &Reader.getIdentifierTable().CreateIdentifierInfo( |
| 556 | k.first, k.first + k.second); |
| 557 | Reader.SetIdentifierInfo(ID, II); |
| 558 | return II; |
| 559 | } |
| 560 | |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 561 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 562 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 563 | Bits >>= 1; |
| 564 | bool Poisoned = Bits & 0x01; |
| 565 | Bits >>= 1; |
| 566 | bool ExtensionToken = Bits & 0x01; |
| 567 | Bits >>= 1; |
| 568 | bool hasMacroDefinition = Bits & 0x01; |
| 569 | Bits >>= 1; |
| 570 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 571 | Bits >>= 10; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 572 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 573 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 574 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 575 | |
| 576 | // Build the IdentifierInfo itself and link the identifier ID with |
| 577 | // the new IdentifierInfo. |
| 578 | IdentifierInfo *II = KnownII; |
| 579 | if (!II) |
Douglas Gregor | 5f8e330 | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 580 | II = &Reader.getIdentifierTable().CreateIdentifierInfo( |
| 581 | k.first, k.first + k.second); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 582 | Reader.SetIdentifierInfo(ID, II); |
| 583 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 584 | // Set or check the various bits in the IdentifierInfo structure. |
| 585 | // FIXME: Load token IDs lazily, too? |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 586 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 587 | assert(II->isExtensionToken() == ExtensionToken && |
| 588 | "Incorrect extension token flag"); |
| 589 | (void)ExtensionToken; |
| 590 | II->setIsPoisoned(Poisoned); |
| 591 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 592 | "Incorrect C++ operator keyword flag"); |
| 593 | (void)CPlusPlusOperatorKeyword; |
| 594 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 595 | // If this identifier is a macro, deserialize the macro |
| 596 | // definition. |
| 597 | if (hasMacroDefinition) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 598 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 599 | Reader.ReadMacroRecord(Offset); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 600 | DataLen -= 4; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 601 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 602 | |
| 603 | // Read all of the declarations visible at global scope with this |
| 604 | // name. |
Chris Lattner | 6bf690f | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 605 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 606 | if (DataLen > 0) { |
| 607 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 608 | for (; DataLen > 0; DataLen -= 4) |
| 609 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 610 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 611 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 612 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 613 | return II; |
| 614 | } |
| 615 | }; |
| 616 | |
| 617 | } // end anonymous namespace |
| 618 | |
| 619 | /// \brief The on-disk hash table used to contain information about |
| 620 | /// all of the identifiers in the program. |
| 621 | typedef OnDiskChainedHashTable<PCHIdentifierLookupTrait> |
| 622 | PCHIdentifierLookupTable; |
| 623 | |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 624 | bool PCHReader::Error(const char *Msg) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 625 | unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Fatal, Msg); |
| 626 | Diag(DiagID); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 627 | return true; |
| 628 | } |
| 629 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 630 | /// \brief Check the contents of the predefines buffer against the |
| 631 | /// contents of the predefines buffer used to build the PCH file. |
| 632 | /// |
| 633 | /// The contents of the two predefines buffers should be the same. If |
| 634 | /// not, then some command-line option changed the preprocessor state |
| 635 | /// and we must reject the PCH file. |
| 636 | /// |
| 637 | /// \param PCHPredef The start of the predefines buffer in the PCH |
| 638 | /// file. |
| 639 | /// |
| 640 | /// \param PCHPredefLen The length of the predefines buffer in the PCH |
| 641 | /// file. |
| 642 | /// |
| 643 | /// \param PCHBufferID The FileID for the PCH predefines buffer. |
| 644 | /// |
| 645 | /// \returns true if there was a mismatch (in which case the PCH file |
| 646 | /// should be ignored), or false otherwise. |
| 647 | bool PCHReader::CheckPredefinesBuffer(const char *PCHPredef, |
| 648 | unsigned PCHPredefLen, |
| 649 | FileID PCHBufferID) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 650 | if (Listener) |
| 651 | return Listener->ReadPredefinesBuffer(PCHPredef, PCHPredefLen, PCHBufferID, |
| 652 | SuggestedPredefines); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 653 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 656 | //===----------------------------------------------------------------------===// |
| 657 | // Source Manager Deserialization |
| 658 | //===----------------------------------------------------------------------===// |
| 659 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 660 | /// \brief Read the line table in the source manager block. |
| 661 | /// \returns true if ther was an error. |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 662 | bool PCHReader::ParseLineTable(llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 663 | unsigned Idx = 0; |
| 664 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 665 | |
| 666 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 667 | std::map<int, int> FileIDs; |
| 668 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 669 | // Extract the file name |
| 670 | unsigned FilenameLen = Record[Idx++]; |
| 671 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 672 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 673 | MaybeAddSystemRootToFilename(Filename); |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 674 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
| 675 | Filename.size()); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | // Parse the line entries |
| 679 | std::vector<LineEntry> Entries; |
| 680 | while (Idx < Record.size()) { |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 681 | int FID = FileIDs[Record[Idx++]]; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 682 | |
| 683 | // Extract the line entries |
| 684 | unsigned NumEntries = Record[Idx++]; |
| 685 | Entries.clear(); |
| 686 | Entries.reserve(NumEntries); |
| 687 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 688 | unsigned FileOffset = Record[Idx++]; |
| 689 | unsigned LineNo = Record[Idx++]; |
| 690 | int FilenameID = Record[Idx++]; |
| 691 | SrcMgr::CharacteristicKind FileKind |
| 692 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 693 | unsigned IncludeOffset = Record[Idx++]; |
| 694 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 695 | FileKind, IncludeOffset)); |
| 696 | } |
| 697 | LineTable.AddEntry(FID, Entries); |
| 698 | } |
| 699 | |
| 700 | return false; |
| 701 | } |
| 702 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 703 | namespace { |
| 704 | |
| 705 | class VISIBILITY_HIDDEN PCHStatData { |
| 706 | public: |
| 707 | const bool hasStat; |
| 708 | const ino_t ino; |
| 709 | const dev_t dev; |
| 710 | const mode_t mode; |
| 711 | const time_t mtime; |
| 712 | const off_t size; |
| 713 | |
| 714 | PCHStatData(ino_t i, dev_t d, mode_t mo, time_t m, off_t s) |
| 715 | : hasStat(true), ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
| 716 | |
| 717 | PCHStatData() |
| 718 | : hasStat(false), ino(0), dev(0), mode(0), mtime(0), size(0) {} |
| 719 | }; |
| 720 | |
| 721 | class VISIBILITY_HIDDEN PCHStatLookupTrait { |
| 722 | public: |
| 723 | typedef const char *external_key_type; |
| 724 | typedef const char *internal_key_type; |
| 725 | |
| 726 | typedef PCHStatData data_type; |
| 727 | |
| 728 | static unsigned ComputeHash(const char *path) { |
| 729 | return BernsteinHash(path); |
| 730 | } |
| 731 | |
| 732 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 733 | |
| 734 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 735 | return strcmp(a, b) == 0; |
| 736 | } |
| 737 | |
| 738 | static std::pair<unsigned, unsigned> |
| 739 | ReadKeyDataLength(const unsigned char*& d) { |
| 740 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 741 | unsigned DataLen = (unsigned) *d++; |
| 742 | return std::make_pair(KeyLen + 1, DataLen); |
| 743 | } |
| 744 | |
| 745 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 746 | return (const char *)d; |
| 747 | } |
| 748 | |
| 749 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 750 | unsigned /*DataLen*/) { |
| 751 | using namespace clang::io; |
| 752 | |
| 753 | if (*d++ == 1) |
| 754 | return data_type(); |
| 755 | |
| 756 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 757 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 758 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
| 759 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
| 760 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 761 | return data_type(ino, dev, mode, mtime, size); |
| 762 | } |
| 763 | }; |
| 764 | |
| 765 | /// \brief stat() cache for precompiled headers. |
| 766 | /// |
| 767 | /// This cache is very similar to the stat cache used by pretokenized |
| 768 | /// headers. |
| 769 | class VISIBILITY_HIDDEN PCHStatCache : public StatSysCallCache { |
| 770 | typedef OnDiskChainedHashTable<PCHStatLookupTrait> CacheTy; |
| 771 | CacheTy *Cache; |
| 772 | |
| 773 | unsigned &NumStatHits, &NumStatMisses; |
| 774 | public: |
| 775 | PCHStatCache(const unsigned char *Buckets, |
| 776 | const unsigned char *Base, |
| 777 | unsigned &NumStatHits, |
| 778 | unsigned &NumStatMisses) |
| 779 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 780 | Cache = CacheTy::Create(Buckets, Base); |
| 781 | } |
| 782 | |
| 783 | ~PCHStatCache() { delete Cache; } |
| 784 | |
| 785 | int stat(const char *path, struct stat *buf) { |
| 786 | // Do the lookup for the file's data in the PCH file. |
| 787 | CacheTy::iterator I = Cache->find(path); |
| 788 | |
| 789 | // If we don't get a hit in the PCH file just forward to 'stat'. |
| 790 | if (I == Cache->end()) { |
| 791 | ++NumStatMisses; |
| 792 | return ::stat(path, buf); |
| 793 | } |
| 794 | |
| 795 | ++NumStatHits; |
| 796 | PCHStatData Data = *I; |
| 797 | |
| 798 | if (!Data.hasStat) |
| 799 | return 1; |
| 800 | |
| 801 | buf->st_ino = Data.ino; |
| 802 | buf->st_dev = Data.dev; |
| 803 | buf->st_mtime = Data.mtime; |
| 804 | buf->st_mode = Data.mode; |
| 805 | buf->st_size = Data.size; |
| 806 | return 0; |
| 807 | } |
| 808 | }; |
| 809 | } // end anonymous namespace |
| 810 | |
| 811 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 812 | /// \brief Read the source manager block |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 813 | PCHReader::PCHReadResult PCHReader::ReadSourceManagerBlock() { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 814 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 815 | |
| 816 | // Set the source-location entry cursor to the current position in |
| 817 | // the stream. This cursor will be used to read the contents of the |
| 818 | // source manager block initially, and then lazily read |
| 819 | // source-location entries as needed. |
| 820 | SLocEntryCursor = Stream; |
| 821 | |
| 822 | // The stream itself is going to skip over the source manager block. |
| 823 | if (Stream.SkipBlock()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 824 | Error("malformed block record in PCH file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 825 | return Failure; |
| 826 | } |
| 827 | |
| 828 | // Enter the source manager block. |
| 829 | if (SLocEntryCursor.EnterSubBlock(pch::SOURCE_MANAGER_BLOCK_ID)) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 830 | Error("malformed source manager block record in PCH file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 831 | return Failure; |
| 832 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 833 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 834 | RecordData Record; |
| 835 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 836 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 837 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 838 | if (SLocEntryCursor.ReadBlockEnd()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 839 | Error("error at end of Source Manager block in PCH file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 840 | return Failure; |
| 841 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 842 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 846 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 847 | SLocEntryCursor.ReadSubBlockID(); |
| 848 | if (SLocEntryCursor.SkipBlock()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 849 | Error("malformed block record in PCH file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 850 | return Failure; |
| 851 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 852 | continue; |
| 853 | } |
| 854 | |
| 855 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 856 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 857 | continue; |
| 858 | } |
| 859 | |
| 860 | // Read a record. |
| 861 | const char *BlobStart; |
| 862 | unsigned BlobLen; |
| 863 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 864 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 865 | default: // Default behavior: ignore. |
| 866 | break; |
| 867 | |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 868 | case pch::SM_LINE_TABLE: |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 869 | if (ParseLineTable(Record)) |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 870 | return Failure; |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 871 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 872 | |
| 873 | case pch::SM_HEADER_FILE_INFO: { |
| 874 | HeaderFileInfo HFI; |
| 875 | HFI.isImport = Record[0]; |
| 876 | HFI.DirInfo = Record[1]; |
| 877 | HFI.NumIncludes = Record[2]; |
| 878 | HFI.ControllingMacroID = Record[3]; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 879 | if (Listener) |
| 880 | Listener->ReadHeaderFileInfo(HFI); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 881 | break; |
| 882 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 883 | |
| 884 | case pch::SM_SLOC_FILE_ENTRY: |
| 885 | case pch::SM_SLOC_BUFFER_ENTRY: |
| 886 | case pch::SM_SLOC_INSTANTIATION_ENTRY: |
| 887 | // Once we hit one of the source location entries, we're done. |
| 888 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | } |
| 892 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 893 | /// \brief Read in the source location entry with the given ID. |
| 894 | PCHReader::PCHReadResult PCHReader::ReadSLocEntryRecord(unsigned ID) { |
| 895 | if (ID == 0) |
| 896 | return Success; |
| 897 | |
| 898 | if (ID > TotalNumSLocEntries) { |
| 899 | Error("source location entry ID out-of-range for PCH file"); |
| 900 | return Failure; |
| 901 | } |
| 902 | |
| 903 | ++NumSLocEntriesRead; |
| 904 | SLocEntryCursor.JumpToBit(SLocOffsets[ID - 1]); |
| 905 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 906 | if (Code == llvm::bitc::END_BLOCK || |
| 907 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 908 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 909 | Error("incorrectly-formatted source location entry in PCH file"); |
| 910 | return Failure; |
| 911 | } |
| 912 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 913 | RecordData Record; |
| 914 | const char *BlobStart; |
| 915 | unsigned BlobLen; |
| 916 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 917 | default: |
| 918 | Error("incorrectly-formatted source location entry in PCH file"); |
| 919 | return Failure; |
| 920 | |
| 921 | case pch::SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 922 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 923 | MaybeAddSystemRootToFilename(Filename); |
| 924 | const FileEntry *File = FileMgr.getFile(Filename); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 925 | if (File == 0) { |
| 926 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 927 | ErrorStr += Filename; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 928 | ErrorStr += "' referenced by PCH file"; |
| 929 | Error(ErrorStr.c_str()); |
| 930 | return Failure; |
| 931 | } |
| 932 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 933 | FileID FID = SourceMgr.createFileID(File, |
| 934 | SourceLocation::getFromRawEncoding(Record[1]), |
| 935 | (SrcMgr::CharacteristicKind)Record[2], |
| 936 | ID, Record[0]); |
| 937 | if (Record[3]) |
| 938 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 939 | .setHasLineDirectives(); |
| 940 | |
| 941 | break; |
| 942 | } |
| 943 | |
| 944 | case pch::SM_SLOC_BUFFER_ENTRY: { |
| 945 | const char *Name = BlobStart; |
| 946 | unsigned Offset = Record[0]; |
| 947 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 948 | Record.clear(); |
| 949 | unsigned RecCode |
| 950 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
| 951 | assert(RecCode == pch::SM_SLOC_BUFFER_BLOB && "Ill-formed PCH file"); |
| 952 | (void)RecCode; |
| 953 | llvm::MemoryBuffer *Buffer |
| 954 | = llvm::MemoryBuffer::getMemBuffer(BlobStart, |
| 955 | BlobStart + BlobLen - 1, |
| 956 | Name); |
| 957 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
| 958 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 959 | if (strcmp(Name, "<built-in>") == 0) { |
| 960 | PCHPredefinesBufferID = BufferID; |
| 961 | PCHPredefines = BlobStart; |
| 962 | PCHPredefinesLen = BlobLen - 1; |
| 963 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 964 | |
| 965 | break; |
| 966 | } |
| 967 | |
| 968 | case pch::SM_SLOC_INSTANTIATION_ENTRY: { |
| 969 | SourceLocation SpellingLoc |
| 970 | = SourceLocation::getFromRawEncoding(Record[1]); |
| 971 | SourceMgr.createInstantiationLoc(SpellingLoc, |
| 972 | SourceLocation::getFromRawEncoding(Record[2]), |
| 973 | SourceLocation::getFromRawEncoding(Record[3]), |
| 974 | Record[4], |
| 975 | ID, |
| 976 | Record[0]); |
| 977 | break; |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | return Success; |
| 982 | } |
| 983 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 984 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 985 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 986 | /// and then leave the cursor pointing into the block. |
| 987 | bool PCHReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
| 988 | unsigned BlockID) { |
| 989 | if (Cursor.EnterSubBlock(BlockID)) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 990 | Error("malformed block record in PCH file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 991 | return Failure; |
| 992 | } |
| 993 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 994 | while (true) { |
| 995 | unsigned Code = Cursor.ReadCode(); |
| 996 | |
| 997 | // We expect all abbrevs to be at the start of the block. |
| 998 | if (Code != llvm::bitc::DEFINE_ABBREV) |
| 999 | return false; |
| 1000 | Cursor.ReadAbbrevRecord(); |
| 1001 | } |
| 1002 | } |
| 1003 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1004 | void PCHReader::ReadMacroRecord(uint64_t Offset) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1005 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1006 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1007 | // Keep track of where we are in the stream, then jump back there |
| 1008 | // after reading this macro. |
| 1009 | SavedStreamPosition SavedPosition(Stream); |
| 1010 | |
| 1011 | Stream.JumpToBit(Offset); |
| 1012 | RecordData Record; |
| 1013 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1014 | MacroInfo *Macro = 0; |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 1015 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1016 | while (true) { |
| 1017 | unsigned Code = Stream.ReadCode(); |
| 1018 | switch (Code) { |
| 1019 | case llvm::bitc::END_BLOCK: |
| 1020 | return; |
| 1021 | |
| 1022 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1023 | // No known subblocks, always skip them. |
| 1024 | Stream.ReadSubBlockID(); |
| 1025 | if (Stream.SkipBlock()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1026 | Error("malformed block record in PCH file"); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1027 | return; |
| 1028 | } |
| 1029 | continue; |
| 1030 | |
| 1031 | case llvm::bitc::DEFINE_ABBREV: |
| 1032 | Stream.ReadAbbrevRecord(); |
| 1033 | continue; |
| 1034 | default: break; |
| 1035 | } |
| 1036 | |
| 1037 | // Read a record. |
| 1038 | Record.clear(); |
| 1039 | pch::PreprocessorRecordTypes RecType = |
| 1040 | (pch::PreprocessorRecordTypes)Stream.ReadRecord(Code, Record); |
| 1041 | switch (RecType) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1042 | case pch::PP_MACRO_OBJECT_LIKE: |
| 1043 | case pch::PP_MACRO_FUNCTION_LIKE: { |
| 1044 | // If we already have a macro, that means that we've hit the end |
| 1045 | // of the definition of the macro we were looking for. We're |
| 1046 | // done. |
| 1047 | if (Macro) |
| 1048 | return; |
| 1049 | |
| 1050 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1051 | if (II == 0) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1052 | Error("macro must have a name in PCH file"); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1053 | return; |
| 1054 | } |
| 1055 | SourceLocation Loc = SourceLocation::getFromRawEncoding(Record[1]); |
| 1056 | bool isUsed = Record[2]; |
| 1057 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1058 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1059 | MI->setIsUsed(isUsed); |
| 1060 | |
| 1061 | if (RecType == pch::PP_MACRO_FUNCTION_LIKE) { |
| 1062 | // Decode function-like macro info. |
| 1063 | bool isC99VarArgs = Record[3]; |
| 1064 | bool isGNUVarArgs = Record[4]; |
| 1065 | MacroArgs.clear(); |
| 1066 | unsigned NumArgs = Record[5]; |
| 1067 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1068 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1069 | |
| 1070 | // Install function-like macro info. |
| 1071 | MI->setIsFunctionLike(); |
| 1072 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1073 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1074 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1075 | PP->getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | // Finally, install the macro. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1079 | PP->setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1080 | |
| 1081 | // Remember that we saw this macro last so that we add the tokens that |
| 1082 | // form its body to it. |
| 1083 | Macro = MI; |
| 1084 | ++NumMacrosRead; |
| 1085 | break; |
| 1086 | } |
| 1087 | |
| 1088 | case pch::PP_TOKEN: { |
| 1089 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1090 | // erroneous, just pretend we didn't see this. |
| 1091 | if (Macro == 0) break; |
| 1092 | |
| 1093 | Token Tok; |
| 1094 | Tok.startToken(); |
| 1095 | Tok.setLocation(SourceLocation::getFromRawEncoding(Record[0])); |
| 1096 | Tok.setLength(Record[1]); |
| 1097 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1098 | Tok.setIdentifierInfo(II); |
| 1099 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1100 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1101 | Macro->AddTokenToBody(Tok); |
| 1102 | break; |
| 1103 | } |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 1104 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1108 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1109 | /// not an absolute path, add the system root to the beginning of the file |
| 1110 | /// name. |
| 1111 | void PCHReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
| 1112 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1113 | if (!RelocatablePCH) |
| 1114 | return; |
| 1115 | |
| 1116 | if (Filename.empty() || Filename[0] == '/' || Filename[0] == '<') |
| 1117 | return; |
| 1118 | |
| 1119 | std::string FIXME = Filename; |
| 1120 | |
| 1121 | if (isysroot == 0) { |
| 1122 | // If no system root was given, default to '/' |
| 1123 | Filename.insert(Filename.begin(), '/'); |
| 1124 | return; |
| 1125 | } |
| 1126 | |
| 1127 | unsigned Length = strlen(isysroot); |
| 1128 | if (isysroot[Length - 1] != '/') |
| 1129 | Filename.insert(Filename.begin(), '/'); |
| 1130 | |
| 1131 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1132 | } |
| 1133 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1134 | PCHReader::PCHReadResult |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1135 | PCHReader::ReadPCHBlock() { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1136 | if (Stream.EnterSubBlock(pch::PCH_BLOCK_ID)) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1137 | Error("malformed block record in PCH file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1138 | return Failure; |
| 1139 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1140 | |
| 1141 | // Read all of the records and blocks for the PCH file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1142 | RecordData Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1143 | while (!Stream.AtEndOfStream()) { |
| 1144 | unsigned Code = Stream.ReadCode(); |
| 1145 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1146 | if (Stream.ReadBlockEnd()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1147 | Error("error at end of module block in PCH file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1148 | return Failure; |
| 1149 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1150 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1151 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1155 | switch (Stream.ReadSubBlockID()) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1156 | case pch::TYPES_BLOCK_ID: // Skip types block (lazily loaded) |
| 1157 | default: // Skip unknown content. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1158 | if (Stream.SkipBlock()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1159 | Error("malformed block record in PCH file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1160 | return Failure; |
| 1161 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1162 | break; |
| 1163 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1164 | case pch::DECLS_BLOCK_ID: |
| 1165 | // We lazily load the decls block, but we want to set up the |
| 1166 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1167 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1168 | // With the main cursor, we just skip over it. |
| 1169 | DeclsCursor = Stream; |
| 1170 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1171 | // Read the abbrevs. |
| 1172 | ReadBlockAbbrevs(DeclsCursor, pch::DECLS_BLOCK_ID)) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1173 | Error("malformed block record in PCH file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1174 | return Failure; |
| 1175 | } |
| 1176 | break; |
| 1177 | |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1178 | case pch::PREPROCESSOR_BLOCK_ID: |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1179 | if (Stream.SkipBlock()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1180 | Error("malformed block record in PCH file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1181 | return Failure; |
| 1182 | } |
| 1183 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1184 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1185 | case pch::SOURCE_MANAGER_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1186 | switch (ReadSourceManagerBlock()) { |
| 1187 | case Success: |
| 1188 | break; |
| 1189 | |
| 1190 | case Failure: |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1191 | Error("malformed source manager block in PCH file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1192 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1193 | |
| 1194 | case IgnorePCH: |
| 1195 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1196 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1197 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1198 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1199 | continue; |
| 1200 | } |
| 1201 | |
| 1202 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1203 | Stream.ReadAbbrevRecord(); |
| 1204 | continue; |
| 1205 | } |
| 1206 | |
| 1207 | // Read and process a record. |
| 1208 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1209 | const char *BlobStart = 0; |
| 1210 | unsigned BlobLen = 0; |
| 1211 | switch ((pch::PCHRecordTypes)Stream.ReadRecord(Code, Record, |
| 1212 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1213 | default: // Default behavior: ignore. |
| 1214 | break; |
| 1215 | |
| 1216 | case pch::TYPE_OFFSET: |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 1217 | if (!TypesLoaded.empty()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1218 | Error("duplicate TYPE_OFFSET record in PCH file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1219 | return Failure; |
| 1220 | } |
Chris Lattner | c732f5a | 2009-04-27 18:24:17 +0000 | [diff] [blame] | 1221 | TypeOffsets = (const uint32_t *)BlobStart; |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 1222 | TypesLoaded.resize(Record[0]); |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1223 | break; |
| 1224 | |
| 1225 | case pch::DECL_OFFSET: |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 1226 | if (!DeclsLoaded.empty()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1227 | Error("duplicate DECL_OFFSET record in PCH file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1228 | return Failure; |
| 1229 | } |
Chris Lattner | c732f5a | 2009-04-27 18:24:17 +0000 | [diff] [blame] | 1230 | DeclOffsets = (const uint32_t *)BlobStart; |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 1231 | DeclsLoaded.resize(Record[0]); |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1232 | break; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1233 | |
| 1234 | case pch::LANGUAGE_OPTIONS: |
| 1235 | if (ParseLanguageOptions(Record)) |
| 1236 | return IgnorePCH; |
| 1237 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1238 | |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 1239 | case pch::METADATA: { |
| 1240 | if (Record[0] != pch::VERSION_MAJOR) { |
| 1241 | Diag(Record[0] < pch::VERSION_MAJOR? diag::warn_pch_version_too_old |
| 1242 | : diag::warn_pch_version_too_new); |
| 1243 | return IgnorePCH; |
| 1244 | } |
| 1245 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1246 | RelocatablePCH = Record[4]; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1247 | if (Listener) { |
| 1248 | std::string TargetTriple(BlobStart, BlobLen); |
| 1249 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1250 | return IgnorePCH; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1251 | } |
| 1252 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1253 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1254 | |
| 1255 | case pch::IDENTIFIER_TABLE: |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1256 | IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1257 | if (Record[0]) { |
| 1258 | IdentifierLookupTable |
| 1259 | = PCHIdentifierLookupTable::Create( |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1260 | (const unsigned char *)IdentifierTableData + Record[0], |
| 1261 | (const unsigned char *)IdentifierTableData, |
| 1262 | PCHIdentifierLookupTrait(*this)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1263 | if (PP) |
| 1264 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1265 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1266 | break; |
| 1267 | |
| 1268 | case pch::IDENTIFIER_OFFSET: |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1269 | if (!IdentifiersLoaded.empty()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1270 | Error("duplicate IDENTIFIER_OFFSET record in PCH file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1271 | return Failure; |
| 1272 | } |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1273 | IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1274 | IdentifiersLoaded.resize(Record[0]); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1275 | if (PP) |
| 1276 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1277 | break; |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1278 | |
| 1279 | case pch::EXTERNAL_DEFINITIONS: |
| 1280 | if (!ExternalDefinitions.empty()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1281 | Error("duplicate EXTERNAL_DEFINITIONS record in PCH file"); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1282 | return Failure; |
| 1283 | } |
| 1284 | ExternalDefinitions.swap(Record); |
| 1285 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1286 | |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1287 | case pch::SPECIAL_TYPES: |
| 1288 | SpecialTypes.swap(Record); |
| 1289 | break; |
| 1290 | |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1291 | case pch::STATISTICS: |
| 1292 | TotalNumStatements = Record[0]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1293 | TotalNumMacros = Record[1]; |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 1294 | TotalLexicalDeclContexts = Record[2]; |
| 1295 | TotalVisibleDeclContexts = Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1296 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1297 | |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 1298 | case pch::TENTATIVE_DEFINITIONS: |
| 1299 | if (!TentativeDefinitions.empty()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1300 | Error("duplicate TENTATIVE_DEFINITIONS record in PCH file"); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 1301 | return Failure; |
| 1302 | } |
| 1303 | TentativeDefinitions.swap(Record); |
| 1304 | break; |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1305 | |
| 1306 | case pch::LOCALLY_SCOPED_EXTERNAL_DECLS: |
| 1307 | if (!LocallyScopedExternalDecls.empty()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1308 | Error("duplicate LOCALLY_SCOPED_EXTERNAL_DECLS record in PCH file"); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1309 | return Failure; |
| 1310 | } |
| 1311 | LocallyScopedExternalDecls.swap(Record); |
| 1312 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1313 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1314 | case pch::SELECTOR_OFFSETS: |
| 1315 | SelectorOffsets = (const uint32_t *)BlobStart; |
| 1316 | TotalNumSelectors = Record[0]; |
| 1317 | SelectorsLoaded.resize(TotalNumSelectors); |
| 1318 | break; |
| 1319 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1320 | case pch::METHOD_POOL: |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1321 | MethodPoolLookupTableData = (const unsigned char *)BlobStart; |
| 1322 | if (Record[0]) |
| 1323 | MethodPoolLookupTable |
| 1324 | = PCHMethodPoolLookupTable::Create( |
| 1325 | MethodPoolLookupTableData + Record[0], |
| 1326 | MethodPoolLookupTableData, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1327 | PCHMethodPoolLookupTrait(*this)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1328 | TotalSelectorsInMethodPool = Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1329 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1330 | |
| 1331 | case pch::PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1332 | if (!Record.empty() && Listener) |
| 1333 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1334 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1335 | |
| 1336 | case pch::SOURCE_LOCATION_OFFSETS: |
Chris Lattner | 090d9b5 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1337 | SLocOffsets = (const uint32_t *)BlobStart; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1338 | TotalNumSLocEntries = Record[0]; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1339 | SourceMgr.PreallocateSLocEntries(this, |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1340 | TotalNumSLocEntries, |
| 1341 | Record[1]); |
| 1342 | break; |
| 1343 | |
| 1344 | case pch::SOURCE_LOCATION_PRELOADS: |
| 1345 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 1346 | PCHReadResult Result = ReadSLocEntryRecord(Record[I]); |
| 1347 | if (Result != Success) |
| 1348 | return Result; |
| 1349 | } |
| 1350 | break; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1351 | |
| 1352 | case pch::STAT_CACHE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1353 | FileMgr.setStatCache( |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1354 | new PCHStatCache((const unsigned char *)BlobStart + Record[0], |
| 1355 | (const unsigned char *)BlobStart, |
| 1356 | NumStatHits, NumStatMisses)); |
| 1357 | break; |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 1358 | |
| 1359 | case pch::EXT_VECTOR_DECLS: |
| 1360 | if (!ExtVectorDecls.empty()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1361 | Error("duplicate EXT_VECTOR_DECLS record in PCH file"); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 1362 | return Failure; |
| 1363 | } |
| 1364 | ExtVectorDecls.swap(Record); |
| 1365 | break; |
| 1366 | |
| 1367 | case pch::OBJC_CATEGORY_IMPLEMENTATIONS: |
| 1368 | if (!ObjCCategoryImpls.empty()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1369 | Error("duplicate OBJC_CATEGORY_IMPLEMENTATIONS record in PCH file"); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 1370 | return Failure; |
| 1371 | } |
| 1372 | ObjCCategoryImpls.swap(Record); |
| 1373 | break; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1374 | |
| 1375 | case pch::ORIGINAL_FILE_NAME: |
| 1376 | OriginalFileName.assign(BlobStart, BlobLen); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1377 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1378 | break; |
Douglas Gregor | 2e22253 | 2009-07-02 17:08:52 +0000 | [diff] [blame] | 1379 | |
| 1380 | case pch::COMMENT_RANGES: |
| 1381 | Comments = (SourceRange *)BlobStart; |
| 1382 | NumComments = BlobLen / sizeof(SourceRange); |
| 1383 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1384 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1385 | } |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1386 | Error("premature end of bitstream in PCH file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1387 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1390 | PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1391 | // Set the PCH file name. |
| 1392 | this->FileName = FileName; |
| 1393 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1394 | // Open the PCH file. |
| 1395 | std::string ErrStr; |
| 1396 | Buffer.reset(llvm::MemoryBuffer::getFile(FileName.c_str(), &ErrStr)); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1397 | if (!Buffer) { |
| 1398 | Error(ErrStr.c_str()); |
| 1399 | return IgnorePCH; |
| 1400 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1401 | |
| 1402 | // Initialize the stream |
Chris Lattner | b9fa917 | 2009-04-26 20:59:20 +0000 | [diff] [blame] | 1403 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
| 1404 | (const unsigned char *)Buffer->getBufferEnd()); |
| 1405 | Stream.init(StreamFile); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1406 | |
| 1407 | // Sniff for the signature. |
| 1408 | if (Stream.Read(8) != 'C' || |
| 1409 | Stream.Read(8) != 'P' || |
| 1410 | Stream.Read(8) != 'C' || |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1411 | Stream.Read(8) != 'H') { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1412 | Diag(diag::err_not_a_pch_file) << FileName; |
| 1413 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1414 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1415 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1416 | while (!Stream.AtEndOfStream()) { |
| 1417 | unsigned Code = Stream.ReadCode(); |
| 1418 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1419 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1420 | Error("invalid record at top-level of PCH file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1421 | return Failure; |
| 1422 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1423 | |
| 1424 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1425 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1426 | // We only know the PCH subblock ID. |
| 1427 | switch (BlockID) { |
| 1428 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1429 | if (Stream.ReadBlockInfoBlock()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1430 | Error("malformed BlockInfoBlock in PCH file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1431 | return Failure; |
| 1432 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1433 | break; |
| 1434 | case pch::PCH_BLOCK_ID: |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1435 | switch (ReadPCHBlock()) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1436 | case Success: |
| 1437 | break; |
| 1438 | |
| 1439 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1440 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1441 | |
| 1442 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1443 | // FIXME: We could consider reading through to the end of this |
| 1444 | // PCH block, skipping subblocks, to see if there are other |
| 1445 | // PCH blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 1446 | |
| 1447 | // Clear out any preallocated source location entries, so that |
| 1448 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1449 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 1450 | |
| 1451 | // Remove the stat cache. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1452 | FileMgr.setStatCache(0); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 1453 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1454 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1455 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1456 | break; |
| 1457 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1458 | if (Stream.SkipBlock()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1459 | Error("malformed block record in PCH file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1460 | return Failure; |
| 1461 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1462 | break; |
| 1463 | } |
| 1464 | } |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1465 | |
| 1466 | // Check the predefines buffer. |
| 1467 | if (CheckPredefinesBuffer(PCHPredefines, PCHPredefinesLen, |
| 1468 | PCHPredefinesBufferID)) |
| 1469 | return IgnorePCH; |
| 1470 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1471 | if (PP) { |
| 1472 | // Initialization of builtins and library builtins occurs before the |
| 1473 | // PCH file is read, so there may be some identifiers that were |
| 1474 | // loaded into the IdentifierTable before we intercepted the |
| 1475 | // creation of identifiers. Iterate through the list of known |
| 1476 | // identifiers and determine whether we have to establish |
| 1477 | // preprocessor definitions or top-level identifier declaration |
| 1478 | // chains for those identifiers. |
| 1479 | // |
| 1480 | // We copy the IdentifierInfo pointers to a small vector first, |
| 1481 | // since de-serializing declarations or macro definitions can add |
| 1482 | // new entries into the identifier table, invalidating the |
| 1483 | // iterators. |
| 1484 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 1485 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 1486 | IdEnd = PP->getIdentifierTable().end(); |
| 1487 | Id != IdEnd; ++Id) |
| 1488 | Identifiers.push_back(Id->second); |
| 1489 | PCHIdentifierLookupTable *IdTable |
| 1490 | = (PCHIdentifierLookupTable *)IdentifierLookupTable; |
| 1491 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 1492 | IdentifierInfo *II = Identifiers[I]; |
| 1493 | // Look in the on-disk hash table for an entry for |
| 1494 | PCHIdentifierLookupTrait Info(*this, II); |
| 1495 | std::pair<const char*, unsigned> Key(II->getName(), II->getLength()); |
| 1496 | PCHIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
| 1497 | if (Pos == IdTable->end()) |
| 1498 | continue; |
| 1499 | |
| 1500 | // Dereferencing the iterator has the effect of populating the |
| 1501 | // IdentifierInfo node with the various declarations it needs. |
| 1502 | (void)*Pos; |
| 1503 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1506 | if (Context) |
| 1507 | InitializeContext(*Context); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1508 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1509 | return Success; |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1512 | void PCHReader::InitializeContext(ASTContext &Ctx) { |
| 1513 | Context = &Ctx; |
| 1514 | assert(Context && "Passed null context!"); |
| 1515 | |
| 1516 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1517 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 1518 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 1519 | |
| 1520 | // Load the translation unit declaration |
| 1521 | ReadDeclRecord(DeclOffsets[0], 0); |
| 1522 | |
| 1523 | // Load the special types. |
| 1524 | Context->setBuiltinVaListType( |
| 1525 | GetType(SpecialTypes[pch::SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 1526 | if (unsigned Id = SpecialTypes[pch::SPECIAL_TYPE_OBJC_ID]) |
| 1527 | Context->setObjCIdType(GetType(Id)); |
| 1528 | if (unsigned Sel = SpecialTypes[pch::SPECIAL_TYPE_OBJC_SELECTOR]) |
| 1529 | Context->setObjCSelType(GetType(Sel)); |
| 1530 | if (unsigned Proto = SpecialTypes[pch::SPECIAL_TYPE_OBJC_PROTOCOL]) |
| 1531 | Context->setObjCProtoType(GetType(Proto)); |
| 1532 | if (unsigned Class = SpecialTypes[pch::SPECIAL_TYPE_OBJC_CLASS]) |
| 1533 | Context->setObjCClassType(GetType(Class)); |
| 1534 | if (unsigned String = SpecialTypes[pch::SPECIAL_TYPE_CF_CONSTANT_STRING]) |
| 1535 | Context->setCFConstantStringType(GetType(String)); |
| 1536 | if (unsigned FastEnum |
| 1537 | = SpecialTypes[pch::SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
| 1538 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame^] | 1539 | if (unsigned File = SpecialTypes[pch::SPECIAL_TYPE_FILE]) { |
| 1540 | QualType FileType = GetType(File); |
| 1541 | assert(!FileType.isNull() && "FILE type is NULL"); |
| 1542 | if (const TypedefType *Typedef = FileType->getAsTypedefType()) |
| 1543 | Context->setFILEDecl(Typedef->getDecl()); |
| 1544 | else { |
| 1545 | const TagType *Tag = FileType->getAsTagType(); |
| 1546 | assert(Tag && "Invalid FILE type in PCH file"); |
| 1547 | Context->setFILEDecl(Tag->getDecl()); |
| 1548 | } |
| 1549 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1550 | } |
| 1551 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1552 | /// \brief Retrieve the name of the original source file name |
| 1553 | /// directly from the PCH file, without actually loading the PCH |
| 1554 | /// file. |
| 1555 | std::string PCHReader::getOriginalSourceFile(const std::string &PCHFileName) { |
| 1556 | // Open the PCH file. |
| 1557 | std::string ErrStr; |
| 1558 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
| 1559 | Buffer.reset(llvm::MemoryBuffer::getFile(PCHFileName.c_str(), &ErrStr)); |
| 1560 | if (!Buffer) { |
| 1561 | fprintf(stderr, "error: %s\n", ErrStr.c_str()); |
| 1562 | return std::string(); |
| 1563 | } |
| 1564 | |
| 1565 | // Initialize the stream |
| 1566 | llvm::BitstreamReader StreamFile; |
| 1567 | llvm::BitstreamCursor Stream; |
| 1568 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
| 1569 | (const unsigned char *)Buffer->getBufferEnd()); |
| 1570 | Stream.init(StreamFile); |
| 1571 | |
| 1572 | // Sniff for the signature. |
| 1573 | if (Stream.Read(8) != 'C' || |
| 1574 | Stream.Read(8) != 'P' || |
| 1575 | Stream.Read(8) != 'C' || |
| 1576 | Stream.Read(8) != 'H') { |
| 1577 | fprintf(stderr, |
| 1578 | "error: '%s' does not appear to be a precompiled header file\n", |
| 1579 | PCHFileName.c_str()); |
| 1580 | return std::string(); |
| 1581 | } |
| 1582 | |
| 1583 | RecordData Record; |
| 1584 | while (!Stream.AtEndOfStream()) { |
| 1585 | unsigned Code = Stream.ReadCode(); |
| 1586 | |
| 1587 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1588 | unsigned BlockID = Stream.ReadSubBlockID(); |
| 1589 | |
| 1590 | // We only know the PCH subblock ID. |
| 1591 | switch (BlockID) { |
| 1592 | case pch::PCH_BLOCK_ID: |
| 1593 | if (Stream.EnterSubBlock(pch::PCH_BLOCK_ID)) { |
| 1594 | fprintf(stderr, "error: malformed block record in PCH file\n"); |
| 1595 | return std::string(); |
| 1596 | } |
| 1597 | break; |
| 1598 | |
| 1599 | default: |
| 1600 | if (Stream.SkipBlock()) { |
| 1601 | fprintf(stderr, "error: malformed block record in PCH file\n"); |
| 1602 | return std::string(); |
| 1603 | } |
| 1604 | break; |
| 1605 | } |
| 1606 | continue; |
| 1607 | } |
| 1608 | |
| 1609 | if (Code == llvm::bitc::END_BLOCK) { |
| 1610 | if (Stream.ReadBlockEnd()) { |
| 1611 | fprintf(stderr, "error: error at end of module block in PCH file\n"); |
| 1612 | return std::string(); |
| 1613 | } |
| 1614 | continue; |
| 1615 | } |
| 1616 | |
| 1617 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1618 | Stream.ReadAbbrevRecord(); |
| 1619 | continue; |
| 1620 | } |
| 1621 | |
| 1622 | Record.clear(); |
| 1623 | const char *BlobStart = 0; |
| 1624 | unsigned BlobLen = 0; |
| 1625 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
| 1626 | == pch::ORIGINAL_FILE_NAME) |
| 1627 | return std::string(BlobStart, BlobLen); |
| 1628 | } |
| 1629 | |
| 1630 | return std::string(); |
| 1631 | } |
| 1632 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1633 | /// \brief Parse the record that corresponds to a LangOptions data |
| 1634 | /// structure. |
| 1635 | /// |
| 1636 | /// This routine compares the language options used to generate the |
| 1637 | /// PCH file against the language options set for the current |
| 1638 | /// compilation. For each option, we classify differences between the |
| 1639 | /// two compiler states as either "benign" or "important". Benign |
| 1640 | /// differences don't matter, and we accept them without complaint |
| 1641 | /// (and without modifying the language options). Differences between |
| 1642 | /// the states for important options cause the PCH file to be |
| 1643 | /// unusable, so we emit a warning and return true to indicate that |
| 1644 | /// there was an error. |
| 1645 | /// |
| 1646 | /// \returns true if the PCH file is unacceptable, false otherwise. |
| 1647 | bool PCHReader::ParseLanguageOptions( |
| 1648 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1649 | if (Listener) { |
| 1650 | LangOptions LangOpts; |
| 1651 | |
| 1652 | #define PARSE_LANGOPT(Option) \ |
| 1653 | LangOpts.Option = Record[Idx]; \ |
| 1654 | ++Idx |
| 1655 | |
| 1656 | unsigned Idx = 0; |
| 1657 | PARSE_LANGOPT(Trigraphs); |
| 1658 | PARSE_LANGOPT(BCPLComment); |
| 1659 | PARSE_LANGOPT(DollarIdents); |
| 1660 | PARSE_LANGOPT(AsmPreprocessor); |
| 1661 | PARSE_LANGOPT(GNUMode); |
| 1662 | PARSE_LANGOPT(ImplicitInt); |
| 1663 | PARSE_LANGOPT(Digraphs); |
| 1664 | PARSE_LANGOPT(HexFloats); |
| 1665 | PARSE_LANGOPT(C99); |
| 1666 | PARSE_LANGOPT(Microsoft); |
| 1667 | PARSE_LANGOPT(CPlusPlus); |
| 1668 | PARSE_LANGOPT(CPlusPlus0x); |
| 1669 | PARSE_LANGOPT(CXXOperatorNames); |
| 1670 | PARSE_LANGOPT(ObjC1); |
| 1671 | PARSE_LANGOPT(ObjC2); |
| 1672 | PARSE_LANGOPT(ObjCNonFragileABI); |
| 1673 | PARSE_LANGOPT(PascalStrings); |
| 1674 | PARSE_LANGOPT(WritableStrings); |
| 1675 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 1676 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1677 | PARSE_LANGOPT(Exceptions); |
| 1678 | PARSE_LANGOPT(NeXTRuntime); |
| 1679 | PARSE_LANGOPT(Freestanding); |
| 1680 | PARSE_LANGOPT(NoBuiltin); |
| 1681 | PARSE_LANGOPT(ThreadsafeStatics); |
| 1682 | PARSE_LANGOPT(Blocks); |
| 1683 | PARSE_LANGOPT(EmitAllDecls); |
| 1684 | PARSE_LANGOPT(MathErrno); |
| 1685 | PARSE_LANGOPT(OverflowChecking); |
| 1686 | PARSE_LANGOPT(HeinousExtensions); |
| 1687 | PARSE_LANGOPT(Optimize); |
| 1688 | PARSE_LANGOPT(OptimizeSize); |
| 1689 | PARSE_LANGOPT(Static); |
| 1690 | PARSE_LANGOPT(PICLevel); |
| 1691 | PARSE_LANGOPT(GNUInline); |
| 1692 | PARSE_LANGOPT(NoInline); |
| 1693 | PARSE_LANGOPT(AccessControl); |
| 1694 | PARSE_LANGOPT(CharIsSigned); |
| 1695 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx]); |
| 1696 | ++Idx; |
| 1697 | LangOpts.setVisibilityMode((LangOptions::VisibilityMode)Record[Idx]); |
| 1698 | ++Idx; |
| 1699 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 1700 | PARSE_LANGOPT(OpenCL); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1701 | #undef PARSE_LANGOPT |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1702 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1703 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1704 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1705 | |
| 1706 | return false; |
| 1707 | } |
| 1708 | |
Douglas Gregor | 2e22253 | 2009-07-02 17:08:52 +0000 | [diff] [blame] | 1709 | void PCHReader::ReadComments(std::vector<SourceRange> &Comments) { |
| 1710 | Comments.resize(NumComments); |
| 1711 | std::copy(this->Comments, this->Comments + NumComments, |
| 1712 | Comments.begin()); |
| 1713 | } |
| 1714 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1715 | /// \brief Read and return the type at the given offset. |
| 1716 | /// |
| 1717 | /// This routine actually reads the record corresponding to the type |
| 1718 | /// at the given offset in the bitstream. It is a helper routine for |
| 1719 | /// GetType, which deals with reading type IDs. |
| 1720 | QualType PCHReader::ReadTypeRecord(uint64_t Offset) { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1721 | // Keep track of where we are in the stream, then jump back there |
| 1722 | // after reading this type. |
| 1723 | SavedStreamPosition SavedPosition(Stream); |
| 1724 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 1725 | // Note that we are loading a type record. |
| 1726 | LoadingTypeOrDecl Loading(*this); |
| 1727 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1728 | Stream.JumpToBit(Offset); |
| 1729 | RecordData Record; |
| 1730 | unsigned Code = Stream.ReadCode(); |
| 1731 | switch ((pch::TypeCode)Stream.ReadRecord(Code, Record)) { |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 1732 | case pch::TYPE_EXT_QUAL: { |
| 1733 | assert(Record.size() == 3 && |
| 1734 | "Incorrect encoding of extended qualifier type"); |
| 1735 | QualType Base = GetType(Record[0]); |
| 1736 | QualType::GCAttrTypes GCAttr = (QualType::GCAttrTypes)Record[1]; |
| 1737 | unsigned AddressSpace = Record[2]; |
| 1738 | |
| 1739 | QualType T = Base; |
| 1740 | if (GCAttr != QualType::GCNone) |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1741 | T = Context->getObjCGCQualType(T, GCAttr); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 1742 | if (AddressSpace) |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1743 | T = Context->getAddrSpaceQualType(T, AddressSpace); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 1744 | return T; |
| 1745 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1746 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1747 | case pch::TYPE_FIXED_WIDTH_INT: { |
| 1748 | assert(Record.size() == 2 && "Incorrect encoding of fixed-width int type"); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1749 | return Context->getFixedWidthIntType(Record[0], Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | case pch::TYPE_COMPLEX: { |
| 1753 | assert(Record.size() == 1 && "Incorrect encoding of complex type"); |
| 1754 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1755 | return Context->getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | case pch::TYPE_POINTER: { |
| 1759 | assert(Record.size() == 1 && "Incorrect encoding of pointer type"); |
| 1760 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1761 | return Context->getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | case pch::TYPE_BLOCK_POINTER: { |
| 1765 | assert(Record.size() == 1 && "Incorrect encoding of block pointer type"); |
| 1766 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1767 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | case pch::TYPE_LVALUE_REFERENCE: { |
| 1771 | assert(Record.size() == 1 && "Incorrect encoding of lvalue reference type"); |
| 1772 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1773 | return Context->getLValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | case pch::TYPE_RVALUE_REFERENCE: { |
| 1777 | assert(Record.size() == 1 && "Incorrect encoding of rvalue reference type"); |
| 1778 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1779 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | case pch::TYPE_MEMBER_POINTER: { |
| 1783 | assert(Record.size() == 1 && "Incorrect encoding of member pointer type"); |
| 1784 | QualType PointeeType = GetType(Record[0]); |
| 1785 | QualType ClassType = GetType(Record[1]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1786 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1789 | case pch::TYPE_CONSTANT_ARRAY: { |
| 1790 | QualType ElementType = GetType(Record[0]); |
| 1791 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 1792 | unsigned IndexTypeQuals = Record[2]; |
| 1793 | unsigned Idx = 3; |
| 1794 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 1795 | return Context->getConstantArrayType(ElementType, Size, |
| 1796 | ASM, IndexTypeQuals); |
| 1797 | } |
| 1798 | |
| 1799 | case pch::TYPE_CONSTANT_ARRAY_WITH_EXPR: { |
| 1800 | QualType ElementType = GetType(Record[0]); |
| 1801 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 1802 | unsigned IndexTypeQuals = Record[2]; |
| 1803 | SourceLocation LBLoc = SourceLocation::getFromRawEncoding(Record[3]); |
| 1804 | SourceLocation RBLoc = SourceLocation::getFromRawEncoding(Record[4]); |
| 1805 | unsigned Idx = 5; |
| 1806 | llvm::APInt Size = ReadAPInt(Record, Idx); |
| 1807 | return Context->getConstantArrayWithExprType(ElementType, |
| 1808 | Size, ReadTypeExpr(), |
| 1809 | ASM, IndexTypeQuals, |
| 1810 | SourceRange(LBLoc, RBLoc)); |
| 1811 | } |
| 1812 | |
| 1813 | case pch::TYPE_CONSTANT_ARRAY_WITHOUT_EXPR: { |
| 1814 | QualType ElementType = GetType(Record[0]); |
| 1815 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 1816 | unsigned IndexTypeQuals = Record[2]; |
| 1817 | unsigned Idx = 3; |
| 1818 | llvm::APInt Size = ReadAPInt(Record, Idx); |
| 1819 | return Context->getConstantArrayWithoutExprType(ElementType, Size, |
| 1820 | ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | case pch::TYPE_INCOMPLETE_ARRAY: { |
| 1824 | QualType ElementType = GetType(Record[0]); |
| 1825 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 1826 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1827 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | case pch::TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1831 | QualType ElementType = GetType(Record[0]); |
| 1832 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 1833 | unsigned IndexTypeQuals = Record[2]; |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 1834 | SourceLocation LBLoc = SourceLocation::getFromRawEncoding(Record[3]); |
| 1835 | SourceLocation RBLoc = SourceLocation::getFromRawEncoding(Record[4]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1836 | return Context->getVariableArrayType(ElementType, ReadTypeExpr(), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 1837 | ASM, IndexTypeQuals, |
| 1838 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | case pch::TYPE_VECTOR: { |
| 1842 | if (Record.size() != 2) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1843 | Error("incorrect encoding of vector type in PCH file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1844 | return QualType(); |
| 1845 | } |
| 1846 | |
| 1847 | QualType ElementType = GetType(Record[0]); |
| 1848 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1849 | return Context->getVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | case pch::TYPE_EXT_VECTOR: { |
| 1853 | if (Record.size() != 2) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1854 | Error("incorrect encoding of extended vector type in PCH file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1855 | return QualType(); |
| 1856 | } |
| 1857 | |
| 1858 | QualType ElementType = GetType(Record[0]); |
| 1859 | unsigned NumElements = Record[1]; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1860 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | case pch::TYPE_FUNCTION_NO_PROTO: { |
| 1864 | if (Record.size() != 1) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1865 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1866 | return QualType(); |
| 1867 | } |
| 1868 | QualType ResultType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1869 | return Context->getFunctionNoProtoType(ResultType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | case pch::TYPE_FUNCTION_PROTO: { |
| 1873 | QualType ResultType = GetType(Record[0]); |
| 1874 | unsigned Idx = 1; |
| 1875 | unsigned NumParams = Record[Idx++]; |
| 1876 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 1877 | for (unsigned I = 0; I != NumParams; ++I) |
| 1878 | ParamTypes.push_back(GetType(Record[Idx++])); |
| 1879 | bool isVariadic = Record[Idx++]; |
| 1880 | unsigned Quals = Record[Idx++]; |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 1881 | bool hasExceptionSpec = Record[Idx++]; |
| 1882 | bool hasAnyExceptionSpec = Record[Idx++]; |
| 1883 | unsigned NumExceptions = Record[Idx++]; |
| 1884 | llvm::SmallVector<QualType, 2> Exceptions; |
| 1885 | for (unsigned I = 0; I != NumExceptions; ++I) |
| 1886 | Exceptions.push_back(GetType(Record[Idx++])); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1887 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 1888 | isVariadic, Quals, hasExceptionSpec, |
| 1889 | hasAnyExceptionSpec, NumExceptions, |
| 1890 | Exceptions.data()); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | case pch::TYPE_TYPEDEF: |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1894 | assert(Record.size() == 1 && "incorrect encoding of typedef type"); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1895 | return Context->getTypeDeclType(cast<TypedefDecl>(GetDecl(Record[0]))); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1896 | |
| 1897 | case pch::TYPE_TYPEOF_EXPR: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1898 | return Context->getTypeOfExprType(ReadTypeExpr()); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1899 | |
| 1900 | case pch::TYPE_TYPEOF: { |
| 1901 | if (Record.size() != 1) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1902 | Error("incorrect encoding of typeof(type) in PCH file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1903 | return QualType(); |
| 1904 | } |
| 1905 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1906 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1907 | } |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 1908 | |
| 1909 | case pch::TYPE_DECLTYPE: |
| 1910 | return Context->getDecltypeType(ReadTypeExpr()); |
| 1911 | |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1912 | case pch::TYPE_RECORD: |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1913 | assert(Record.size() == 1 && "incorrect encoding of record type"); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1914 | return Context->getTypeDeclType(cast<RecordDecl>(GetDecl(Record[0]))); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1915 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 1916 | case pch::TYPE_ENUM: |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1917 | assert(Record.size() == 1 && "incorrect encoding of enum type"); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1918 | return Context->getTypeDeclType(cast<EnumDecl>(GetDecl(Record[0]))); |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 1919 | |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1920 | case pch::TYPE_OBJC_INTERFACE: |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 1921 | assert(Record.size() == 1 && "incorrect encoding of objc interface type"); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1922 | return Context->getObjCInterfaceType( |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 1923 | cast<ObjCInterfaceDecl>(GetDecl(Record[0]))); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1924 | |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 1925 | case pch::TYPE_OBJC_QUALIFIED_INTERFACE: { |
| 1926 | unsigned Idx = 0; |
| 1927 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
| 1928 | unsigned NumProtos = Record[Idx++]; |
| 1929 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 1930 | for (unsigned I = 0; I != NumProtos; ++I) |
| 1931 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1932 | return Context->getObjCQualifiedInterfaceType(ItfD, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 1933 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 1934 | |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1935 | case pch::TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 1936 | unsigned Idx = 0; |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1937 | ObjCInterfaceDecl *ItfD = |
| 1938 | cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 1939 | unsigned NumProtos = Record[Idx++]; |
| 1940 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 1941 | for (unsigned I = 0; I != NumProtos; ++I) |
| 1942 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1943 | return Context->getObjCObjectPointerType(ItfD, Protos.data(), NumProtos); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 1944 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1945 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1946 | // Suppress a GCC warning |
| 1947 | return QualType(); |
| 1948 | } |
| 1949 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1950 | |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1951 | QualType PCHReader::GetType(pch::TypeID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1952 | unsigned Quals = ID & 0x07; |
| 1953 | unsigned Index = ID >> 3; |
| 1954 | |
| 1955 | if (Index < pch::NUM_PREDEF_TYPE_IDS) { |
| 1956 | QualType T; |
| 1957 | switch ((pch::PredefinedTypeIDs)Index) { |
| 1958 | case pch::PREDEF_TYPE_NULL_ID: return QualType(); |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1959 | case pch::PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 1960 | case pch::PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1961 | |
| 1962 | case pch::PREDEF_TYPE_CHAR_U_ID: |
| 1963 | case pch::PREDEF_TYPE_CHAR_S_ID: |
| 1964 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1965 | T = Context->CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1966 | break; |
| 1967 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1968 | case pch::PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 1969 | case pch::PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 1970 | case pch::PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 1971 | case pch::PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 1972 | case pch::PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 1973 | case pch::PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1974 | case pch::PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 1975 | case pch::PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 1976 | case pch::PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 1977 | case pch::PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 1978 | case pch::PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 1979 | case pch::PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 1980 | case pch::PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1981 | case pch::PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 1982 | case pch::PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 1983 | case pch::PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 1984 | case pch::PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
| 1985 | case pch::PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 1986 | case pch::PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | assert(!T.isNull() && "Unknown predefined type"); |
| 1990 | return T.getQualifiedType(Quals); |
| 1991 | } |
| 1992 | |
| 1993 | Index -= pch::NUM_PREDEF_TYPE_IDS; |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 1994 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 1995 | if (!TypesLoaded[Index]) |
| 1996 | TypesLoaded[Index] = ReadTypeRecord(TypeOffsets[Index]).getTypePtr(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1997 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 1998 | return QualType(TypesLoaded[Index], Quals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2001 | Decl *PCHReader::GetDecl(pch::DeclID ID) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2002 | if (ID == 0) |
| 2003 | return 0; |
| 2004 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2005 | if (ID > DeclsLoaded.size()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 2006 | Error("declaration ID out-of-range for PCH file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2007 | return 0; |
| 2008 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2009 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2010 | unsigned Index = ID - 1; |
| 2011 | if (!DeclsLoaded[Index]) |
| 2012 | ReadDeclRecord(DeclOffsets[Index], Index); |
| 2013 | |
| 2014 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 2017 | /// \brief Resolve the offset of a statement into a statement. |
| 2018 | /// |
| 2019 | /// This operation will read a new statement from the external |
| 2020 | /// source each time it is called, and is meant to be used via a |
| 2021 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
| 2022 | Stmt *PCHReader::GetDeclStmt(uint64_t Offset) { |
Chris Lattner | da93061 | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 2023 | // Since we know tha this statement is part of a decl, make sure to use the |
| 2024 | // decl cursor to read it. |
| 2025 | DeclsCursor.JumpToBit(Offset); |
| 2026 | return ReadStmt(DeclsCursor); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2029 | bool PCHReader::ReadDeclsLexicallyInContext(DeclContext *DC, |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2030 | llvm::SmallVectorImpl<pch::DeclID> &Decls) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2031 | assert(DC->hasExternalLexicalStorage() && |
| 2032 | "DeclContext has no lexical decls in storage"); |
| 2033 | uint64_t Offset = DeclContextOffsets[DC].first; |
| 2034 | assert(Offset && "DeclContext has no lexical decls in storage"); |
| 2035 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2036 | // Keep track of where we are in the stream, then jump back there |
| 2037 | // after reading this context. |
Chris Lattner | c47be9e | 2009-04-27 07:35:40 +0000 | [diff] [blame] | 2038 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2039 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2040 | // Load the record containing all of the declarations lexically in |
| 2041 | // this context. |
Chris Lattner | c47be9e | 2009-04-27 07:35:40 +0000 | [diff] [blame] | 2042 | DeclsCursor.JumpToBit(Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2043 | RecordData Record; |
Chris Lattner | c47be9e | 2009-04-27 07:35:40 +0000 | [diff] [blame] | 2044 | unsigned Code = DeclsCursor.ReadCode(); |
| 2045 | unsigned RecCode = DeclsCursor.ReadRecord(Code, Record); |
Douglas Gregor | 6a2bfb2 | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 2046 | (void)RecCode; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2047 | assert(RecCode == pch::DECL_CONTEXT_LEXICAL && "Expected lexical block"); |
| 2048 | |
| 2049 | // Load all of the declaration IDs |
| 2050 | Decls.clear(); |
| 2051 | Decls.insert(Decls.end(), Record.begin(), Record.end()); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2052 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2053 | return false; |
| 2054 | } |
| 2055 | |
| 2056 | bool PCHReader::ReadDeclsVisibleInContext(DeclContext *DC, |
Chris Lattner | c47be9e | 2009-04-27 07:35:40 +0000 | [diff] [blame] | 2057 | llvm::SmallVectorImpl<VisibleDeclaration> &Decls) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2058 | assert(DC->hasExternalVisibleStorage() && |
| 2059 | "DeclContext has no visible decls in storage"); |
| 2060 | uint64_t Offset = DeclContextOffsets[DC].second; |
| 2061 | assert(Offset && "DeclContext has no visible decls in storage"); |
| 2062 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2063 | // Keep track of where we are in the stream, then jump back there |
| 2064 | // after reading this context. |
Chris Lattner | c47be9e | 2009-04-27 07:35:40 +0000 | [diff] [blame] | 2065 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2066 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2067 | // Load the record containing all of the declarations visible in |
| 2068 | // this context. |
Chris Lattner | c47be9e | 2009-04-27 07:35:40 +0000 | [diff] [blame] | 2069 | DeclsCursor.JumpToBit(Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2070 | RecordData Record; |
Chris Lattner | c47be9e | 2009-04-27 07:35:40 +0000 | [diff] [blame] | 2071 | unsigned Code = DeclsCursor.ReadCode(); |
| 2072 | unsigned RecCode = DeclsCursor.ReadRecord(Code, Record); |
Douglas Gregor | 6a2bfb2 | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 2073 | (void)RecCode; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2074 | assert(RecCode == pch::DECL_CONTEXT_VISIBLE && "Expected visible block"); |
| 2075 | if (Record.size() == 0) |
| 2076 | return false; |
| 2077 | |
| 2078 | Decls.clear(); |
| 2079 | |
| 2080 | unsigned Idx = 0; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2081 | while (Idx < Record.size()) { |
| 2082 | Decls.push_back(VisibleDeclaration()); |
| 2083 | Decls.back().Name = ReadDeclarationName(Record, Idx); |
| 2084 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2085 | unsigned Size = Record[Idx++]; |
Chris Lattner | c47be9e | 2009-04-27 07:35:40 +0000 | [diff] [blame] | 2086 | llvm::SmallVector<unsigned, 4> &LoadedDecls = Decls.back().Declarations; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2087 | LoadedDecls.reserve(Size); |
| 2088 | for (unsigned I = 0; I < Size; ++I) |
| 2089 | LoadedDecls.push_back(Record[Idx++]); |
| 2090 | } |
| 2091 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2092 | ++NumVisibleDeclContextsRead; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2093 | return false; |
| 2094 | } |
| 2095 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2096 | void PCHReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 2097 | this->Consumer = Consumer; |
| 2098 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2099 | if (!Consumer) |
| 2100 | return; |
| 2101 | |
| 2102 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
| 2103 | Decl *D = GetDecl(ExternalDefinitions[I]); |
| 2104 | DeclGroupRef DG(D); |
| 2105 | Consumer->HandleTopLevelDecl(DG); |
| 2106 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 2107 | |
| 2108 | for (unsigned I = 0, N = InterestingDecls.size(); I != N; ++I) { |
| 2109 | DeclGroupRef DG(InterestingDecls[I]); |
| 2110 | Consumer->HandleTopLevelDecl(DG); |
| 2111 | } |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2112 | } |
| 2113 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2114 | void PCHReader::PrintStats() { |
| 2115 | std::fprintf(stderr, "*** PCH Statistics:\n"); |
| 2116 | |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2117 | unsigned NumTypesLoaded |
| 2118 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
| 2119 | (Type *)0); |
| 2120 | unsigned NumDeclsLoaded |
| 2121 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 2122 | (Decl *)0); |
| 2123 | unsigned NumIdentifiersLoaded |
| 2124 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 2125 | IdentifiersLoaded.end(), |
| 2126 | (IdentifierInfo *)0); |
| 2127 | unsigned NumSelectorsLoaded |
| 2128 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 2129 | SelectorsLoaded.end(), |
| 2130 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 2131 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2132 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 2133 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2134 | if (TotalNumSLocEntries) |
| 2135 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 2136 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 2137 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2138 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2139 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2140 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 2141 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 2142 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2143 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2144 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 2145 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2146 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2147 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2148 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 2149 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2150 | if (TotalNumSelectors) |
| 2151 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
| 2152 | NumSelectorsLoaded, TotalNumSelectors, |
| 2153 | ((float)NumSelectorsLoaded/TotalNumSelectors * 100)); |
| 2154 | if (TotalNumStatements) |
| 2155 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 2156 | NumStatementsRead, TotalNumStatements, |
| 2157 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 2158 | if (TotalNumMacros) |
| 2159 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 2160 | NumMacrosRead, TotalNumMacros, |
| 2161 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 2162 | if (TotalLexicalDeclContexts) |
| 2163 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 2164 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 2165 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 2166 | * 100)); |
| 2167 | if (TotalVisibleDeclContexts) |
| 2168 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 2169 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 2170 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 2171 | * 100)); |
| 2172 | if (TotalSelectorsInMethodPool) { |
| 2173 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
| 2174 | NumMethodPoolSelectorsRead, TotalSelectorsInMethodPool, |
| 2175 | ((float)NumMethodPoolSelectorsRead/TotalSelectorsInMethodPool |
| 2176 | * 100)); |
| 2177 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
| 2178 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2179 | std::fprintf(stderr, "\n"); |
| 2180 | } |
| 2181 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2182 | void PCHReader::InitializeSema(Sema &S) { |
| 2183 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2184 | S.ExternalSource = this; |
| 2185 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 2186 | // Makes sure any declarations that were deserialized "too early" |
| 2187 | // still get added to the identifier's declaration chains. |
| 2188 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 2189 | SemaObj->TUScope->AddDecl(Action::DeclPtrTy::make(PreloadedDecls[I])); |
| 2190 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2191 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 2192 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2193 | |
| 2194 | // If there were any tentative definitions, deserialize them and add |
| 2195 | // them to Sema's table of tentative definitions. |
| 2196 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 2197 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 2198 | SemaObj->TentativeDefinitions[Var->getDeclName()] = Var; |
| 2199 | } |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2200 | |
| 2201 | // If there were any locally-scoped external declarations, |
| 2202 | // deserialize them and add them to Sema's table of locally-scoped |
| 2203 | // external declarations. |
| 2204 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 2205 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 2206 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 2207 | } |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2208 | |
| 2209 | // If there were any ext_vector type declarations, deserialize them |
| 2210 | // and add them to Sema's vector of such declarations. |
| 2211 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 2212 | SemaObj->ExtVectorDecls.push_back( |
| 2213 | cast<TypedefDecl>(GetDecl(ExtVectorDecls[I]))); |
| 2214 | |
| 2215 | // If there were any Objective-C category implementations, |
| 2216 | // deserialize them and add them to Sema's vector of such |
| 2217 | // definitions. |
| 2218 | for (unsigned I = 0, N = ObjCCategoryImpls.size(); I != N; ++I) |
| 2219 | SemaObj->ObjCCategoryImpls.push_back( |
| 2220 | cast<ObjCCategoryImplDecl>(GetDecl(ObjCCategoryImpls[I]))); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | IdentifierInfo* PCHReader::get(const char *NameStart, const char *NameEnd) { |
| 2224 | // Try to find this name within our on-disk hash table |
| 2225 | PCHIdentifierLookupTable *IdTable |
| 2226 | = (PCHIdentifierLookupTable *)IdentifierLookupTable; |
| 2227 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
| 2228 | PCHIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
| 2229 | if (Pos == IdTable->end()) |
| 2230 | return 0; |
| 2231 | |
| 2232 | // Dereferencing the iterator has the effect of building the |
| 2233 | // IdentifierInfo node and populating it with the various |
| 2234 | // declarations it needs. |
| 2235 | return *Pos; |
| 2236 | } |
| 2237 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2238 | std::pair<ObjCMethodList, ObjCMethodList> |
| 2239 | PCHReader::ReadMethodPool(Selector Sel) { |
| 2240 | if (!MethodPoolLookupTable) |
| 2241 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
| 2242 | |
| 2243 | // Try to find this selector within our on-disk hash table. |
| 2244 | PCHMethodPoolLookupTable *PoolTable |
| 2245 | = (PCHMethodPoolLookupTable*)MethodPoolLookupTable; |
| 2246 | PCHMethodPoolLookupTable::iterator Pos = PoolTable->find(Sel); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2247 | if (Pos == PoolTable->end()) { |
| 2248 | ++NumMethodPoolMisses; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2249 | return std::pair<ObjCMethodList, ObjCMethodList>();; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2250 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2251 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2252 | ++NumMethodPoolSelectorsRead; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2253 | return *Pos; |
| 2254 | } |
| 2255 | |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2256 | void PCHReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2257 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 2258 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2259 | IdentifiersLoaded[ID - 1] = II; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2260 | } |
| 2261 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2262 | /// \brief Set the globally-visible declarations associated with the given |
| 2263 | /// identifier. |
| 2264 | /// |
| 2265 | /// If the PCH reader is currently in a state where the given declaration IDs |
| 2266 | /// cannot safely be resolved, they are queued until it is safe to resolve |
| 2267 | /// them. |
| 2268 | /// |
| 2269 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 2270 | /// declarations. |
| 2271 | /// |
| 2272 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 2273 | /// visible at global scope. |
| 2274 | /// |
| 2275 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 2276 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 2277 | /// will not be placed onto the pending queue. |
| 2278 | void |
| 2279 | PCHReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
| 2280 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 2281 | bool Nonrecursive) { |
| 2282 | if (CurrentlyLoadingTypeOrDecl && !Nonrecursive) { |
| 2283 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 2284 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 2285 | PII.II = II; |
| 2286 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) |
| 2287 | PII.DeclIDs.push_back(DeclIDs[I]); |
| 2288 | return; |
| 2289 | } |
| 2290 | |
| 2291 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 2292 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 2293 | if (SemaObj) { |
| 2294 | // Introduce this declaration into the translation-unit scope |
| 2295 | // and add it to the declaration chain for this identifier, so |
| 2296 | // that (unqualified) name lookup will find it. |
| 2297 | SemaObj->TUScope->AddDecl(Action::DeclPtrTy::make(D)); |
| 2298 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
| 2299 | } else { |
| 2300 | // Queue this declaration so that it will be added to the |
| 2301 | // translation unit scope and identifier's declaration chain |
| 2302 | // once a Sema object is known. |
| 2303 | PreloadedDecls.push_back(D); |
| 2304 | } |
| 2305 | } |
| 2306 | } |
| 2307 | |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2308 | IdentifierInfo *PCHReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2309 | if (ID == 0) |
| 2310 | return 0; |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2311 | |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2312 | if (!IdentifierTableData || IdentifiersLoaded.empty()) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 2313 | Error("no identifier table in PCH file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2314 | return 0; |
| 2315 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2316 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2317 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2318 | if (!IdentifiersLoaded[ID - 1]) { |
| 2319 | uint32_t Offset = IdentifierOffsets[ID - 1]; |
Douglas Gregor | 17e1c5e | 2009-04-25 21:21:38 +0000 | [diff] [blame] | 2320 | const char *Str = IdentifierTableData + Offset; |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 2321 | |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 2322 | // All of the strings in the PCH file are preceded by a 16-bit |
| 2323 | // length. Extract that 16-bit length to avoid having to execute |
| 2324 | // strlen(). |
| 2325 | const char *StrLenPtr = Str - 2; |
| 2326 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 2327 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
| 2328 | IdentifiersLoaded[ID - 1] |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2329 | = &PP->getIdentifierTable().get(Str, Str + StrLen); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2330 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2331 | |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2332 | return IdentifiersLoaded[ID - 1]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2333 | } |
| 2334 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2335 | void PCHReader::ReadSLocEntry(unsigned ID) { |
| 2336 | ReadSLocEntryRecord(ID); |
| 2337 | } |
| 2338 | |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2339 | Selector PCHReader::DecodeSelector(unsigned ID) { |
| 2340 | if (ID == 0) |
| 2341 | return Selector(); |
| 2342 | |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 2343 | if (!MethodPoolLookupTableData) |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2344 | return Selector(); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2345 | |
| 2346 | if (ID > TotalNumSelectors) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 2347 | Error("selector ID out of range in PCH file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2348 | return Selector(); |
| 2349 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2350 | |
| 2351 | unsigned Index = ID - 1; |
| 2352 | if (SelectorsLoaded[Index].getAsOpaquePtr() == 0) { |
| 2353 | // Load this selector from the selector table. |
| 2354 | // FIXME: endianness portability issues with SelectorOffsets table |
| 2355 | PCHMethodPoolLookupTrait Trait(*this); |
| 2356 | SelectorsLoaded[Index] |
| 2357 | = Trait.ReadKey(MethodPoolLookupTableData + SelectorOffsets[Index], 0); |
| 2358 | } |
| 2359 | |
| 2360 | return SelectorsLoaded[Index]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2363 | DeclarationName |
| 2364 | PCHReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
| 2365 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 2366 | switch (Kind) { |
| 2367 | case DeclarationName::Identifier: |
| 2368 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 2369 | |
| 2370 | case DeclarationName::ObjCZeroArgSelector: |
| 2371 | case DeclarationName::ObjCOneArgSelector: |
| 2372 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 2373 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2374 | |
| 2375 | case DeclarationName::CXXConstructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2376 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2377 | GetType(Record[Idx++])); |
| 2378 | |
| 2379 | case DeclarationName::CXXDestructorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2380 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2381 | GetType(Record[Idx++])); |
| 2382 | |
| 2383 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2384 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2385 | GetType(Record[Idx++])); |
| 2386 | |
| 2387 | case DeclarationName::CXXOperatorName: |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2388 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2389 | (OverloadedOperatorKind)Record[Idx++]); |
| 2390 | |
| 2391 | case DeclarationName::CXXUsingDirective: |
| 2392 | return DeclarationName::getUsingDirectiveName(); |
| 2393 | } |
| 2394 | |
| 2395 | // Required to silence GCC warning |
| 2396 | return DeclarationName(); |
| 2397 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2398 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2399 | /// \brief Read an integral value |
| 2400 | llvm::APInt PCHReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
| 2401 | unsigned BitWidth = Record[Idx++]; |
| 2402 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 2403 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 2404 | Idx += NumWords; |
| 2405 | return Result; |
| 2406 | } |
| 2407 | |
| 2408 | /// \brief Read a signed integral value |
| 2409 | llvm::APSInt PCHReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
| 2410 | bool isUnsigned = Record[Idx++]; |
| 2411 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 2412 | } |
| 2413 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 2414 | /// \brief Read a floating-point value |
| 2415 | llvm::APFloat PCHReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 2416 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 2417 | } |
| 2418 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2419 | // \brief Read a string |
| 2420 | std::string PCHReader::ReadString(const RecordData &Record, unsigned &Idx) { |
| 2421 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 2422 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2423 | Idx += Len; |
| 2424 | return Result; |
| 2425 | } |
| 2426 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2427 | DiagnosticBuilder PCHReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2428 | return Diag(SourceLocation(), DiagID); |
| 2429 | } |
| 2430 | |
| 2431 | DiagnosticBuilder PCHReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2432 | return Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2433 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 2434 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2435 | /// \brief Retrieve the identifier table associated with the |
| 2436 | /// preprocessor. |
| 2437 | IdentifierTable &PCHReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2438 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2439 | return PP->getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 2442 | /// \brief Record that the given ID maps to the given switch-case |
| 2443 | /// statement. |
| 2444 | void PCHReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
| 2445 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 2446 | SwitchCaseStmts[ID] = SC; |
| 2447 | } |
| 2448 | |
| 2449 | /// \brief Retrieve the switch-case statement with the given ID. |
| 2450 | SwitchCase *PCHReader::getSwitchCaseWithID(unsigned ID) { |
| 2451 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 2452 | return SwitchCaseStmts[ID]; |
| 2453 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 2454 | |
| 2455 | /// \brief Record that the given label statement has been |
| 2456 | /// deserialized and has the given ID. |
| 2457 | void PCHReader::RecordLabelStmt(LabelStmt *S, unsigned ID) { |
| 2458 | assert(LabelStmts.find(ID) == LabelStmts.end() && |
| 2459 | "Deserialized label twice"); |
| 2460 | LabelStmts[ID] = S; |
| 2461 | |
| 2462 | // If we've already seen any goto statements that point to this |
| 2463 | // label, resolve them now. |
| 2464 | typedef std::multimap<unsigned, GotoStmt *>::iterator GotoIter; |
| 2465 | std::pair<GotoIter, GotoIter> Gotos = UnresolvedGotoStmts.equal_range(ID); |
| 2466 | for (GotoIter Goto = Gotos.first; Goto != Gotos.second; ++Goto) |
| 2467 | Goto->second->setLabel(S); |
| 2468 | UnresolvedGotoStmts.erase(Gotos.first, Gotos.second); |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 2469 | |
| 2470 | // If we've already seen any address-label statements that point to |
| 2471 | // this label, resolve them now. |
| 2472 | typedef std::multimap<unsigned, AddrLabelExpr *>::iterator AddrLabelIter; |
| 2473 | std::pair<AddrLabelIter, AddrLabelIter> AddrLabels |
| 2474 | = UnresolvedAddrLabelExprs.equal_range(ID); |
| 2475 | for (AddrLabelIter AddrLabel = AddrLabels.first; |
| 2476 | AddrLabel != AddrLabels.second; ++AddrLabel) |
| 2477 | AddrLabel->second->setLabel(S); |
| 2478 | UnresolvedAddrLabelExprs.erase(AddrLabels.first, AddrLabels.second); |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | /// \brief Set the label of the given statement to the label |
| 2482 | /// identified by ID. |
| 2483 | /// |
| 2484 | /// Depending on the order in which the label and other statements |
| 2485 | /// referencing that label occur, this operation may complete |
| 2486 | /// immediately (updating the statement) or it may queue the |
| 2487 | /// statement to be back-patched later. |
| 2488 | void PCHReader::SetLabelOf(GotoStmt *S, unsigned ID) { |
| 2489 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 2490 | if (Label != LabelStmts.end()) { |
| 2491 | // We've already seen this label, so set the label of the goto and |
| 2492 | // we're done. |
| 2493 | S->setLabel(Label->second); |
| 2494 | } else { |
| 2495 | // We haven't seen this label yet, so add this goto to the set of |
| 2496 | // unresolved goto statements. |
| 2497 | UnresolvedGotoStmts.insert(std::make_pair(ID, S)); |
| 2498 | } |
| 2499 | } |
Douglas Gregor | 7d5c2f2 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 2500 | |
| 2501 | /// \brief Set the label of the given expression to the label |
| 2502 | /// identified by ID. |
| 2503 | /// |
| 2504 | /// Depending on the order in which the label and other statements |
| 2505 | /// referencing that label occur, this operation may complete |
| 2506 | /// immediately (updating the statement) or it may queue the |
| 2507 | /// statement to be back-patched later. |
| 2508 | void PCHReader::SetLabelOf(AddrLabelExpr *S, unsigned ID) { |
| 2509 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 2510 | if (Label != LabelStmts.end()) { |
| 2511 | // We've already seen this label, so set the label of the |
| 2512 | // label-address expression and we're done. |
| 2513 | S->setLabel(Label->second); |
| 2514 | } else { |
| 2515 | // We haven't seen this label yet, so add this label-address |
| 2516 | // expression to the set of unresolved label-address expressions. |
| 2517 | UnresolvedAddrLabelExprs.insert(std::make_pair(ID, S)); |
| 2518 | } |
| 2519 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2520 | |
| 2521 | |
| 2522 | PCHReader::LoadingTypeOrDecl::LoadingTypeOrDecl(PCHReader &Reader) |
| 2523 | : Reader(Reader), Parent(Reader.CurrentlyLoadingTypeOrDecl) { |
| 2524 | Reader.CurrentlyLoadingTypeOrDecl = this; |
| 2525 | } |
| 2526 | |
| 2527 | PCHReader::LoadingTypeOrDecl::~LoadingTypeOrDecl() { |
| 2528 | if (!Parent) { |
| 2529 | // If any identifiers with corresponding top-level declarations have |
| 2530 | // been loaded, load those declarations now. |
| 2531 | while (!Reader.PendingIdentifierInfos.empty()) { |
| 2532 | Reader.SetGloballyVisibleDecls(Reader.PendingIdentifierInfos.front().II, |
| 2533 | Reader.PendingIdentifierInfos.front().DeclIDs, |
| 2534 | true); |
| 2535 | Reader.PendingIdentifierInfos.pop_front(); |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | Reader.CurrentlyLoadingTypeOrDecl = Parent; |
| 2540 | } |