Sebastian Redl | 904c9c8 | 2010-08-18 23:57:11 +0000 | [diff] [blame] | 1 | //===--- ASTReader.cpp - AST File Reader ------------------------*- C++ -*-===// |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 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 | // |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 10 | // This file defines the ASTReader class, which reads AST files. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 13 | |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTReader.h" |
| 15 | #include "clang/Serialization/ASTDeserializationListener.h" |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 16 | #include "clang/Serialization/ModuleManager.h" |
Chandler Carruth | a2398d7 | 2011-12-09 00:02:23 +0000 | [diff] [blame] | 17 | #include "clang/Serialization/SerializationDiagnostic.h" |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 18 | #include "ASTCommon.h" |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 19 | #include "ASTReaderInternals.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 20 | #include "clang/Sema/Sema.h" |
John McCall | 5f1e094 | 2010-08-24 08:50:51 +0000 | [diff] [blame] | 21 | #include "clang/Sema/Scope.h" |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 22 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 23 | #include "clang/AST/ASTContext.h" |
John McCall | 2a7fb27 | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 25 | #include "clang/AST/Expr.h" |
John McCall | 7a1fad3 | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 26 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 27 | #include "clang/AST/NestedNameSpecifier.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 28 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 29 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 30 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 31 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 32 | #include "clang/Lex/Preprocessor.h" |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 33 | #include "clang/Lex/PreprocessorOptions.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 34 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 35 | #include "clang/Lex/HeaderSearchOptions.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 36 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 37 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 38 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 39 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 40 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 41 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 42 | #include "clang/Basic/TargetOptions.h" |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 43 | #include "clang/Basic/Version.h" |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 44 | #include "clang/Basic/VersionTuple.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 45 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 46 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 47 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 48 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 49 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 50 | #include "llvm/Support/Path.h" |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 51 | #include "llvm/Support/SaveAndRestore.h" |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 52 | #include "llvm/Support/system_error.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 53 | #include <algorithm> |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 54 | #include <iterator> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 55 | #include <cstdio> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 56 | #include <sys/stat.h> |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 57 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 58 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 59 | using namespace clang::serialization; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 60 | using namespace clang::serialization::reader; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 61 | |
| 62 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 63 | // PCH validator implementation |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 64 | //===----------------------------------------------------------------------===// |
| 65 | |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 66 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 67 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 68 | /// \brief Compare the given set of language options against an existing set of |
| 69 | /// language options. |
| 70 | /// |
| 71 | /// \param Diags If non-NULL, diagnostics will be emitted via this engine. |
| 72 | /// |
| 73 | /// \returns true if the languagae options mis-match, false otherwise. |
| 74 | static bool checkLanguageOptions(const LangOptions &LangOpts, |
| 75 | const LangOptions &ExistingLangOpts, |
| 76 | DiagnosticsEngine *Diags) { |
| 77 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 78 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 79 | if (Diags) \ |
| 80 | Diags->Report(diag::err_pch_langopt_mismatch) \ |
| 81 | << Description << LangOpts.Name << ExistingLangOpts.Name; \ |
| 82 | return true; \ |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 85 | #define VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 86 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 87 | if (Diags) \ |
| 88 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 89 | << Description; \ |
| 90 | return true; \ |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 91 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 92 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 93 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 94 | if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \ |
| 95 | if (Diags) \ |
| 96 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 97 | << Description; \ |
| 98 | return true; \ |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | #define BENIGN_LANGOPT(Name, Bits, Default, Description) |
| 102 | #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
| 103 | #include "clang/Basic/LangOptions.def" |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 104 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 105 | if (ExistingLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) { |
| 106 | if (Diags) |
| 107 | Diags->Report(diag::err_pch_langopt_value_mismatch) |
| 108 | << "target Objective-C runtime"; |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 109 | return true; |
| 110 | } |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 111 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 112 | return false; |
| 113 | } |
| 114 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 115 | /// \brief Compare the given set of target options against an existing set of |
| 116 | /// target options. |
| 117 | /// |
| 118 | /// \param Diags If non-NULL, diagnostics will be emitted via this engine. |
| 119 | /// |
| 120 | /// \returns true if the target options mis-match, false otherwise. |
| 121 | static bool checkTargetOptions(const TargetOptions &TargetOpts, |
| 122 | const TargetOptions &ExistingTargetOpts, |
| 123 | DiagnosticsEngine *Diags) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 124 | #define CHECK_TARGET_OPT(Field, Name) \ |
| 125 | if (TargetOpts.Field != ExistingTargetOpts.Field) { \ |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 126 | if (Diags) \ |
| 127 | Diags->Report(diag::err_pch_targetopt_mismatch) \ |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 128 | << Name << TargetOpts.Field << ExistingTargetOpts.Field; \ |
| 129 | return true; \ |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | CHECK_TARGET_OPT(Triple, "target"); |
| 133 | CHECK_TARGET_OPT(CPU, "target CPU"); |
| 134 | CHECK_TARGET_OPT(ABI, "target ABI"); |
| 135 | CHECK_TARGET_OPT(CXXABI, "target C++ ABI"); |
| 136 | CHECK_TARGET_OPT(LinkerVersion, "target linker version"); |
| 137 | #undef CHECK_TARGET_OPT |
| 138 | |
| 139 | // Compare feature sets. |
| 140 | SmallVector<StringRef, 4> ExistingFeatures( |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 141 | ExistingTargetOpts.FeaturesAsWritten.begin(), |
| 142 | ExistingTargetOpts.FeaturesAsWritten.end()); |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 143 | SmallVector<StringRef, 4> ReadFeatures(TargetOpts.FeaturesAsWritten.begin(), |
| 144 | TargetOpts.FeaturesAsWritten.end()); |
| 145 | std::sort(ExistingFeatures.begin(), ExistingFeatures.end()); |
| 146 | std::sort(ReadFeatures.begin(), ReadFeatures.end()); |
| 147 | |
| 148 | unsigned ExistingIdx = 0, ExistingN = ExistingFeatures.size(); |
| 149 | unsigned ReadIdx = 0, ReadN = ReadFeatures.size(); |
| 150 | while (ExistingIdx < ExistingN && ReadIdx < ReadN) { |
| 151 | if (ExistingFeatures[ExistingIdx] == ReadFeatures[ReadIdx]) { |
| 152 | ++ExistingIdx; |
| 153 | ++ReadIdx; |
| 154 | continue; |
| 155 | } |
| 156 | |
| 157 | if (ReadFeatures[ReadIdx] < ExistingFeatures[ExistingIdx]) { |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 158 | if (Diags) |
| 159 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 160 | << false << ReadFeatures[ReadIdx]; |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 161 | return true; |
| 162 | } |
| 163 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 164 | if (Diags) |
| 165 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 166 | << true << ExistingFeatures[ExistingIdx]; |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 167 | return true; |
| 168 | } |
| 169 | |
| 170 | if (ExistingIdx < ExistingN) { |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 171 | if (Diags) |
| 172 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 173 | << true << ExistingFeatures[ExistingIdx]; |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 174 | return true; |
| 175 | } |
| 176 | |
| 177 | if (ReadIdx < ReadN) { |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 178 | if (Diags) |
| 179 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 180 | << false << ReadFeatures[ReadIdx]; |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 181 | return true; |
| 182 | } |
| 183 | |
| 184 | return false; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 187 | bool |
| 188 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts, |
| 189 | bool Complain) { |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 190 | const LangOptions &ExistingLangOpts = PP.getLangOpts(); |
| 191 | return checkLanguageOptions(LangOpts, ExistingLangOpts, |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 192 | Complain? &Reader.Diags : 0); |
| 193 | } |
| 194 | |
| 195 | bool PCHValidator::ReadTargetOptions(const TargetOptions &TargetOpts, |
| 196 | bool Complain) { |
| 197 | const TargetOptions &ExistingTargetOpts = PP.getTargetInfo().getTargetOpts(); |
| 198 | return checkTargetOptions(TargetOpts, ExistingTargetOpts, |
| 199 | Complain? &Reader.Diags : 0); |
| 200 | } |
| 201 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 202 | namespace { |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 203 | typedef llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> > |
| 204 | MacroDefinitionsMap; |
| 205 | } |
| 206 | |
| 207 | /// \brief Collect the macro definitions provided by the given preprocessor |
| 208 | /// options. |
| 209 | static void collectMacroDefinitions(const PreprocessorOptions &PPOpts, |
| 210 | MacroDefinitionsMap &Macros, |
| 211 | SmallVectorImpl<StringRef> *MacroNames = 0){ |
| 212 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 213 | StringRef Macro = PPOpts.Macros[I].first; |
| 214 | bool IsUndef = PPOpts.Macros[I].second; |
| 215 | |
| 216 | std::pair<StringRef, StringRef> MacroPair = Macro.split('='); |
| 217 | StringRef MacroName = MacroPair.first; |
| 218 | StringRef MacroBody = MacroPair.second; |
| 219 | |
| 220 | // For an #undef'd macro, we only care about the name. |
| 221 | if (IsUndef) { |
| 222 | if (MacroNames && !Macros.count(MacroName)) |
| 223 | MacroNames->push_back(MacroName); |
| 224 | |
| 225 | Macros[MacroName] = std::make_pair("", true); |
| 226 | continue; |
| 227 | } |
| 228 | |
| 229 | // For a #define'd macro, figure out the actual definition. |
| 230 | if (MacroName.size() == Macro.size()) |
| 231 | MacroBody = "1"; |
| 232 | else { |
| 233 | // Note: GCC drops anything following an end-of-line character. |
| 234 | StringRef::size_type End = MacroBody.find_first_of("\n\r"); |
| 235 | MacroBody = MacroBody.substr(0, End); |
| 236 | } |
| 237 | |
| 238 | if (MacroNames && !Macros.count(MacroName)) |
| 239 | MacroNames->push_back(MacroName); |
| 240 | Macros[MacroName] = std::make_pair(MacroBody, false); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /// \brief Check the preprocessor options deserialized from the control block |
| 245 | /// against the preprocessor options in an existing preprocessor. |
| 246 | /// |
| 247 | /// \param Diags If non-null, produce diagnostics for any mismatches incurred. |
| 248 | static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 249 | const PreprocessorOptions &ExistingPPOpts, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 250 | DiagnosticsEngine *Diags, |
| 251 | FileManager &FileMgr, |
| 252 | std::string &SuggestedPredefines) { |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 253 | // Check macro definitions. |
| 254 | MacroDefinitionsMap ASTFileMacros; |
| 255 | collectMacroDefinitions(PPOpts, ASTFileMacros); |
| 256 | MacroDefinitionsMap ExistingMacros; |
| 257 | SmallVector<StringRef, 4> ExistingMacroNames; |
| 258 | collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames); |
| 259 | |
| 260 | for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) { |
| 261 | // Dig out the macro definition in the existing preprocessor options. |
| 262 | StringRef MacroName = ExistingMacroNames[I]; |
| 263 | std::pair<StringRef, bool> Existing = ExistingMacros[MacroName]; |
| 264 | |
| 265 | // Check whether we know anything about this macro name or not. |
| 266 | llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> >::iterator Known |
| 267 | = ASTFileMacros.find(MacroName); |
| 268 | if (Known == ASTFileMacros.end()) { |
| 269 | // FIXME: Check whether this identifier was referenced anywhere in the |
| 270 | // AST file. If so, we should reject the AST file. Unfortunately, this |
| 271 | // information isn't in the control block. What shall we do about it? |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 272 | |
| 273 | if (Existing.second) { |
| 274 | SuggestedPredefines += "#undef "; |
| 275 | SuggestedPredefines += MacroName.str(); |
| 276 | SuggestedPredefines += '\n'; |
| 277 | } else { |
| 278 | SuggestedPredefines += "#define "; |
| 279 | SuggestedPredefines += MacroName.str(); |
| 280 | SuggestedPredefines += Existing.first.str(); |
| 281 | SuggestedPredefines += '\n'; |
| 282 | } |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 283 | continue; |
| 284 | } |
| 285 | |
| 286 | // If the macro was defined in one but undef'd in the other, we have a |
| 287 | // conflict. |
| 288 | if (Existing.second != Known->second.second) { |
| 289 | if (Diags) { |
| 290 | Diags->Report(diag::err_pch_macro_def_undef) |
| 291 | << MacroName << Known->second.second; |
| 292 | } |
| 293 | return true; |
| 294 | } |
| 295 | |
| 296 | // If the macro was #undef'd in both, or if the macro bodies are identical, |
| 297 | // it's fine. |
| 298 | if (Existing.second || Existing.first == Known->second.first) |
| 299 | continue; |
| 300 | |
| 301 | // The macro bodies differ; complain. |
| 302 | if (Diags) { |
| 303 | Diags->Report(diag::err_pch_macro_def_conflict) |
| 304 | << MacroName << Known->second.first << Existing.first; |
| 305 | } |
| 306 | return true; |
| 307 | } |
| 308 | |
| 309 | // Check whether we're using predefines. |
| 310 | if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines) { |
| 311 | if (Diags) { |
| 312 | Diags->Report(diag::err_pch_undef) << ExistingPPOpts.UsePredefines; |
| 313 | } |
| 314 | return true; |
| 315 | } |
| 316 | |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 317 | // Compute the #include and #include_macros lines we need. |
| 318 | for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) { |
| 319 | StringRef File = ExistingPPOpts.Includes[I]; |
| 320 | if (File == ExistingPPOpts.ImplicitPCHInclude) |
| 321 | continue; |
| 322 | |
| 323 | if (std::find(PPOpts.Includes.begin(), PPOpts.Includes.end(), File) |
| 324 | != PPOpts.Includes.end()) |
| 325 | continue; |
| 326 | |
| 327 | SuggestedPredefines += "#include \""; |
| 328 | SuggestedPredefines += |
| 329 | HeaderSearch::NormalizeDashIncludePath(File, FileMgr); |
| 330 | SuggestedPredefines += "\"\n"; |
| 331 | } |
| 332 | |
| 333 | for (unsigned I = 0, N = ExistingPPOpts.MacroIncludes.size(); I != N; ++I) { |
| 334 | StringRef File = ExistingPPOpts.MacroIncludes[I]; |
| 335 | if (std::find(PPOpts.MacroIncludes.begin(), PPOpts.MacroIncludes.end(), |
| 336 | File) |
| 337 | != PPOpts.MacroIncludes.end()) |
| 338 | continue; |
| 339 | |
| 340 | SuggestedPredefines += "#__include_macros \""; |
| 341 | SuggestedPredefines += |
| 342 | HeaderSearch::NormalizeDashIncludePath(File, FileMgr); |
| 343 | SuggestedPredefines += "\"\n##\n"; |
| 344 | } |
| 345 | |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 346 | return false; |
| 347 | } |
| 348 | |
| 349 | bool PCHValidator::ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 350 | bool Complain, |
| 351 | std::string &SuggestedPredefines) { |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 352 | const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts(); |
| 353 | |
| 354 | return checkPreprocessorOptions(PPOpts, ExistingPPOpts, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 355 | Complain? &Reader.Diags : 0, |
| 356 | PP.getFileManager(), |
| 357 | SuggestedPredefines); |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | namespace { |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 361 | struct EmptyStringRef { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 362 | bool operator ()(StringRef r) const { return r.empty(); } |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 363 | }; |
| 364 | struct EmptyBlock { |
| 365 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 366 | }; |
| 367 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 368 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 369 | static bool EqualConcatenations(SmallVector<StringRef, 2> L, |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 370 | PCHPredefinesBlocks R) { |
| 371 | // First, sum up the lengths. |
| 372 | unsigned LL = 0, RL = 0; |
| 373 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 374 | LL += L[I].size(); |
| 375 | } |
| 376 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 377 | RL += R[I].Data.size(); |
| 378 | } |
| 379 | if (LL != RL) |
| 380 | return false; |
| 381 | if (LL == 0 && RL == 0) |
| 382 | return true; |
| 383 | |
| 384 | // Kick out empty parts, they confuse the algorithm below. |
| 385 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 386 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 387 | |
| 388 | // Do it the hard way. At this point, both vectors must be non-empty. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 389 | StringRef LR = L[0], RR = R[0].Data; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 390 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 391 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 392 | for (;;) { |
| 393 | // Compare the current pieces. |
| 394 | if (LR.size() == RR.size()) { |
| 395 | // If they're the same length, it's pretty easy. |
| 396 | if (LR != RR) |
| 397 | return false; |
| 398 | // Both pieces are done, advance. |
| 399 | ++LI; |
| 400 | ++RI; |
| 401 | // If either string is done, they're both done, since they're the same |
| 402 | // length. |
| 403 | if (LI == LN) { |
| 404 | assert(RI == RN && "Strings not the same length after all?"); |
| 405 | return true; |
| 406 | } |
| 407 | LR = L[LI]; |
| 408 | RR = R[RI].Data; |
| 409 | } else if (LR.size() < RR.size()) { |
| 410 | // Right piece is longer. |
| 411 | if (!RR.startswith(LR)) |
| 412 | return false; |
| 413 | ++LI; |
| 414 | assert(LI != LN && "Strings not the same length after all?"); |
| 415 | RR = RR.substr(LR.size()); |
| 416 | LR = L[LI]; |
| 417 | } else { |
| 418 | // Left piece is longer. |
| 419 | if (!LR.startswith(RR)) |
| 420 | return false; |
| 421 | ++RI; |
| 422 | assert(RI != RN && "Strings not the same length after all?"); |
| 423 | LR = LR.substr(RR.size()); |
| 424 | RR = R[RI].Data; |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 429 | static std::pair<FileID, StringRef::size_type> |
| 430 | FindMacro(const PCHPredefinesBlocks &Buffers, StringRef MacroDef) { |
| 431 | std::pair<FileID, StringRef::size_type> Res; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 432 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 433 | Res.second = Buffers[I].Data.find(MacroDef); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 434 | if (Res.second != StringRef::npos) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 435 | Res.first = Buffers[I].BufferID; |
| 436 | break; |
| 437 | } |
| 438 | } |
| 439 | return Res; |
| 440 | } |
| 441 | |
| 442 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 443 | StringRef OriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 444 | std::string &SuggestedPredefines, |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 445 | FileManager &FileMgr, |
| 446 | bool Complain) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 447 | // We are in the context of an implicit include, so the predefines buffer will |
| 448 | // have a #include entry for the PCH file itself (as normalized by the |
| 449 | // preprocessor initialization). Find it and skip over it in the checking |
| 450 | // below. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 451 | SmallString<256> PCHInclude; |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 452 | PCHInclude += "#include \""; |
Chandler Carruth | cb381ea | 2011-12-09 01:33:57 +0000 | [diff] [blame] | 453 | PCHInclude += HeaderSearch::NormalizeDashIncludePath(OriginalFileName, |
| 454 | FileMgr); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 455 | PCHInclude += "\"\n"; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 456 | std::pair<StringRef,StringRef> Split = |
| 457 | StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 458 | StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 459 | if (Left == PP.getPredefines()) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 460 | if (Complain) |
| 461 | Error("Missing PCH include entry!"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 462 | return true; |
| 463 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 464 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 465 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 466 | // command line, we're done. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 467 | SmallVector<StringRef, 2> CommandLine; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 468 | CommandLine.push_back(Left); |
| 469 | CommandLine.push_back(Right); |
| 470 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 471 | return false; |
| 472 | |
| 473 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 474 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 475 | // The predefines buffers are different. Determine what the differences are, |
| 476 | // and whether they require us to reject the PCH file. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 477 | SmallVector<StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 478 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 479 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 480 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 481 | SmallVector<StringRef, 8> CmdLineLines; |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 482 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 483 | |
| 484 | // Pick out implicit #includes after the PCH and don't consider them for |
| 485 | // validation; we will insert them into SuggestedPredefines so that the |
| 486 | // preprocessor includes them. |
| 487 | std::string IncludesAfterPCH; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 488 | SmallVector<StringRef, 8> AfterPCHLines; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 489 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 490 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 491 | if (AfterPCHLines[i].startswith("#include ")) { |
| 492 | IncludesAfterPCH += AfterPCHLines[i]; |
| 493 | IncludesAfterPCH += '\n'; |
| 494 | } else { |
| 495 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | // Make sure we add the includes last into SuggestedPredefines before we |
| 500 | // exit this function. |
| 501 | struct AddIncludesRAII { |
| 502 | std::string &SuggestedPredefines; |
| 503 | std::string &IncludesAfterPCH; |
| 504 | |
| 505 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 506 | std::string &IncludesAfterPCH) |
| 507 | : SuggestedPredefines(SuggestedPredefines), |
| 508 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 509 | ~AddIncludesRAII() { |
| 510 | SuggestedPredefines += IncludesAfterPCH; |
| 511 | } |
| 512 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 513 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 514 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 515 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 516 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 517 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 518 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 519 | // Determine which predefines that were used to build the PCH file are missing |
| 520 | // from the command line. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 521 | std::vector<StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 522 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 523 | CmdLineLines.begin(), CmdLineLines.end(), |
| 524 | std::back_inserter(MissingPredefines)); |
| 525 | |
| 526 | bool MissingDefines = false; |
| 527 | bool ConflictingDefines = false; |
| 528 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 529 | StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 530 | if (Missing.startswith("#include ")) { |
| 531 | // An -include was specified when generating the PCH; it is included in |
| 532 | // the PCH, just ignore it. |
| 533 | continue; |
| 534 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 535 | if (!Missing.startswith("#define ")) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 536 | if (Complain) |
| 537 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 538 | return true; |
| 539 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 540 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 541 | // This is a macro definition. Determine the name of the macro we're |
| 542 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 543 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 545 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 546 | assert(EndOfMacroName != std::string::npos && |
| 547 | "Couldn't find the end of the macro name"); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 548 | StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 549 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 550 | // Determine whether this macro was given a different definition on the |
| 551 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 552 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 553 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 554 | SmallVector<StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 555 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 556 | MacroDefStart); |
| 557 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 558 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 559 | // Different macro; we're done. |
| 560 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 561 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 562 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 563 | |
| 564 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 565 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 566 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 567 | (*ConflictPos)[MacroDefLen] != '(') |
| 568 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 569 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 570 | // We found a conflicting macro definition. |
| 571 | break; |
| 572 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 573 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 574 | if (ConflictPos != CmdLineLines.end()) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 575 | if (!Complain) |
| 576 | return true; |
| 577 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 578 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 579 | << MacroName; |
| 580 | |
| 581 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 582 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 583 | FindMacro(Buffers, Missing); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 584 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 585 | SourceLocation PCHMissingLoc = |
| 586 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
Argyrios Kyrtzidis | a64ccef | 2011-09-19 20:40:19 +0000 | [diff] [blame] | 587 | .getLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 588 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 589 | |
| 590 | ConflictingDefines = true; |
| 591 | continue; |
| 592 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 593 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 594 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 595 | // definition from the PCH file. Warn the user that they made a mistake. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 596 | if (ConflictingDefines) |
| 597 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 598 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 599 | if (!MissingDefines) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 600 | if (!Complain) |
| 601 | return true; |
| 602 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 603 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 604 | MissingDefines = true; |
| 605 | } |
| 606 | |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 607 | if (!Complain) |
| 608 | return true; |
| 609 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 610 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 611 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 612 | FindMacro(Buffers, Missing); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 613 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 614 | SourceLocation PCHMissingLoc = |
| 615 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
Argyrios Kyrtzidis | a64ccef | 2011-09-19 20:40:19 +0000 | [diff] [blame] | 616 | .getLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 617 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 618 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 619 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 620 | if (ConflictingDefines) |
| 621 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 622 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 623 | // Determine what predefines were introduced based on command-line |
| 624 | // parameters that were not present when building the PCH |
| 625 | // file. Extra #defines are okay, so long as the identifiers being |
| 626 | // defined were not used within the precompiled header. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 627 | std::vector<StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 628 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 629 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 630 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 631 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 632 | StringRef &Extra = ExtraPredefines[I]; |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 633 | if (!Extra.startswith("#define ")) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 634 | if (Complain) |
| 635 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 636 | return true; |
| 637 | } |
| 638 | |
| 639 | // This is an extra macro definition. Determine the name of the |
| 640 | // macro we're defining. |
| 641 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 642 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 643 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 644 | assert(EndOfMacroName != std::string::npos && |
| 645 | "Couldn't find the end of the macro name"); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 646 | StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 647 | |
| 648 | // Check whether this name was used somewhere in the PCH file. If |
| 649 | // so, defining it as a macro could change behavior, so we reject |
| 650 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 651 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 652 | if (Complain) |
| 653 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 654 | return true; |
| 655 | } |
| 656 | |
| 657 | // Add this definition to the suggested predefines buffer. |
| 658 | SuggestedPredefines += Extra; |
| 659 | SuggestedPredefines += '\n'; |
| 660 | } |
| 661 | |
| 662 | // If we get here, it's because the predefines buffer had compatible |
| 663 | // contents. Accept the PCH file. |
| 664 | return false; |
| 665 | } |
| 666 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 667 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 668 | unsigned ID) { |
| 669 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 670 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Argyrios Kyrtzidis | 62288ed | 2012-10-10 02:12:47 +0000 | [diff] [blame] | 673 | void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 674 | PP.setCounterValue(Value); |
| 675 | } |
| 676 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 677 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 678 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 679 | //===----------------------------------------------------------------------===// |
| 680 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 681 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 682 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 683 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 684 | } |
| 685 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 686 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 687 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 688 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 689 | return serialization::ComputeHash(Sel); |
| 690 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 691 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 693 | std::pair<unsigned, unsigned> |
| 694 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 695 | using namespace clang::io; |
| 696 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 697 | unsigned DataLen = ReadUnalignedLE16(d); |
| 698 | return std::make_pair(KeyLen, DataLen); |
| 699 | } |
| 700 | |
| 701 | ASTSelectorLookupTrait::internal_key_type |
| 702 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 703 | using namespace clang::io; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 704 | SelectorTable &SelTable = Reader.getContext().Selectors; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 705 | unsigned N = ReadUnalignedLE16(d); |
| 706 | IdentifierInfo *FirstII |
| 707 | = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 708 | if (N == 0) |
| 709 | return SelTable.getNullarySelector(FirstII); |
| 710 | else if (N == 1) |
| 711 | return SelTable.getUnarySelector(FirstII); |
| 712 | |
| 713 | SmallVector<IdentifierInfo *, 16> Args; |
| 714 | Args.push_back(FirstII); |
| 715 | for (unsigned I = 1; I != N; ++I) |
| 716 | Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d))); |
| 717 | |
| 718 | return SelTable.getSelector(N, Args.data()); |
| 719 | } |
| 720 | |
| 721 | ASTSelectorLookupTrait::data_type |
| 722 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
| 723 | unsigned DataLen) { |
| 724 | using namespace clang::io; |
| 725 | |
| 726 | data_type Result; |
| 727 | |
| 728 | Result.ID = Reader.getGlobalSelectorID(F, ReadUnalignedLE32(d)); |
| 729 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 730 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 731 | |
| 732 | // Load instance methods |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 733 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
| 734 | if (ObjCMethodDecl *Method |
| 735 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 736 | Result.Instance.push_back(Method); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 737 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 738 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 739 | // Load factory methods |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 740 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
| 741 | if (ObjCMethodDecl *Method |
| 742 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 743 | Result.Factory.push_back(Method); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 744 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 745 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 746 | return Result; |
| 747 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 748 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 749 | unsigned ASTIdentifierLookupTrait::ComputeHash(const internal_key_type& a) { |
| 750 | return llvm::HashString(StringRef(a.first, a.second)); |
| 751 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 752 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 753 | std::pair<unsigned, unsigned> |
| 754 | ASTIdentifierLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 755 | using namespace clang::io; |
| 756 | unsigned DataLen = ReadUnalignedLE16(d); |
| 757 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 758 | return std::make_pair(KeyLen, DataLen); |
| 759 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 760 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 761 | std::pair<const char*, unsigned> |
| 762 | ASTIdentifierLookupTrait::ReadKey(const unsigned char* d, unsigned n) { |
| 763 | assert(n >= 2 && d[n-1] == '\0'); |
| 764 | return std::make_pair((const char*) d, n-1); |
| 765 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 766 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 767 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 768 | const unsigned char* d, |
| 769 | unsigned DataLen) { |
| 770 | using namespace clang::io; |
| 771 | unsigned RawID = ReadUnalignedLE32(d); |
| 772 | bool IsInteresting = RawID & 0x01; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 773 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 774 | // Wipe out the "is interesting" bit. |
| 775 | RawID = RawID >> 1; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 776 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 777 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 778 | if (!IsInteresting) { |
| 779 | // For uninteresting identifiers, just build the IdentifierInfo |
| 780 | // and associate it with the persistent ID. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 781 | IdentifierInfo *II = KnownII; |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 782 | if (!II) { |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 783 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 784 | KnownII = II; |
| 785 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 786 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 787 | II->setIsFromAST(); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 788 | Reader.markIdentifierUpToDate(II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 789 | return II; |
| 790 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 791 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 792 | unsigned ObjCOrBuiltinID = ReadUnalignedLE16(d); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 793 | unsigned Bits = ReadUnalignedLE16(d); |
| 794 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 795 | Bits >>= 1; |
| 796 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 797 | Bits >>= 1; |
| 798 | bool Poisoned = Bits & 0x01; |
| 799 | Bits >>= 1; |
| 800 | bool ExtensionToken = Bits & 0x01; |
| 801 | Bits >>= 1; |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 802 | bool hadMacroDefinition = Bits & 0x01; |
| 803 | Bits >>= 1; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 804 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 805 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 806 | DataLen -= 8; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 807 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 808 | // Build the IdentifierInfo itself and link the identifier ID with |
| 809 | // the new IdentifierInfo. |
| 810 | IdentifierInfo *II = KnownII; |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 811 | if (!II) { |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 812 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 813 | KnownII = II; |
| 814 | } |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 815 | Reader.markIdentifierUpToDate(II); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 816 | II->setIsFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 817 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 818 | // Set or check the various bits in the IdentifierInfo structure. |
| 819 | // Token IDs are read-only. |
| 820 | if (HasRevertedTokenIDToIdentifier) |
| 821 | II->RevertTokenIDToIdentifier(); |
| 822 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 823 | assert(II->isExtensionToken() == ExtensionToken && |
| 824 | "Incorrect extension token flag"); |
| 825 | (void)ExtensionToken; |
| 826 | if (Poisoned) |
| 827 | II->setIsPoisoned(true); |
| 828 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 829 | "Incorrect C++ operator keyword flag"); |
| 830 | (void)CPlusPlusOperatorKeyword; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 831 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 832 | // If this identifier is a macro, deserialize the macro |
| 833 | // definition. |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 834 | if (hadMacroDefinition) { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 835 | SmallVector<MacroID, 4> MacroIDs; |
| 836 | while (uint32_t LocalID = ReadUnalignedLE32(d)) { |
| 837 | MacroIDs.push_back(Reader.getGlobalMacroID(F, LocalID)); |
| 838 | DataLen -= 4; |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 839 | } |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 840 | DataLen -= 4; |
| 841 | Reader.setIdentifierIsMacro(II, MacroIDs); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 842 | } |
| 843 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 844 | Reader.SetIdentifierInfo(ID, II); |
| 845 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 846 | // Read all of the declarations visible at global scope with this |
| 847 | // name. |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 848 | if (DataLen > 0) { |
| 849 | SmallVector<uint32_t, 4> DeclIDs; |
| 850 | for (; DataLen > 0; DataLen -= 4) |
| 851 | DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); |
| 852 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 853 | } |
| 854 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 855 | return II; |
| 856 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 857 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 858 | unsigned |
| 859 | ASTDeclContextNameLookupTrait::ComputeHash(const DeclNameKey &Key) const { |
| 860 | llvm::FoldingSetNodeID ID; |
| 861 | ID.AddInteger(Key.Kind); |
| 862 | |
| 863 | switch (Key.Kind) { |
| 864 | case DeclarationName::Identifier: |
| 865 | case DeclarationName::CXXLiteralOperatorName: |
| 866 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 867 | break; |
| 868 | case DeclarationName::ObjCZeroArgSelector: |
| 869 | case DeclarationName::ObjCOneArgSelector: |
| 870 | case DeclarationName::ObjCMultiArgSelector: |
| 871 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 872 | break; |
| 873 | case DeclarationName::CXXOperatorName: |
| 874 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 875 | break; |
| 876 | case DeclarationName::CXXConstructorName: |
| 877 | case DeclarationName::CXXDestructorName: |
| 878 | case DeclarationName::CXXConversionFunctionName: |
| 879 | case DeclarationName::CXXUsingDirective: |
| 880 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 881 | } |
| 882 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 883 | return ID.ComputeHash(); |
| 884 | } |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 885 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 886 | ASTDeclContextNameLookupTrait::internal_key_type |
| 887 | ASTDeclContextNameLookupTrait::GetInternalKey( |
| 888 | const external_key_type& Name) const { |
| 889 | DeclNameKey Key; |
| 890 | Key.Kind = Name.getNameKind(); |
| 891 | switch (Name.getNameKind()) { |
| 892 | case DeclarationName::Identifier: |
| 893 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 894 | break; |
| 895 | case DeclarationName::ObjCZeroArgSelector: |
| 896 | case DeclarationName::ObjCOneArgSelector: |
| 897 | case DeclarationName::ObjCMultiArgSelector: |
| 898 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 899 | break; |
| 900 | case DeclarationName::CXXOperatorName: |
| 901 | Key.Data = Name.getCXXOverloadedOperator(); |
| 902 | break; |
| 903 | case DeclarationName::CXXLiteralOperatorName: |
| 904 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 905 | break; |
| 906 | case DeclarationName::CXXConstructorName: |
| 907 | case DeclarationName::CXXDestructorName: |
| 908 | case DeclarationName::CXXConversionFunctionName: |
| 909 | case DeclarationName::CXXUsingDirective: |
| 910 | Key.Data = 0; |
| 911 | break; |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 914 | return Key; |
| 915 | } |
| 916 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 917 | std::pair<unsigned, unsigned> |
| 918 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 919 | using namespace clang::io; |
| 920 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 921 | unsigned DataLen = ReadUnalignedLE16(d); |
| 922 | return std::make_pair(KeyLen, DataLen); |
| 923 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 924 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 925 | ASTDeclContextNameLookupTrait::internal_key_type |
| 926 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 927 | using namespace clang::io; |
| 928 | |
| 929 | DeclNameKey Key; |
| 930 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 931 | switch (Key.Kind) { |
| 932 | case DeclarationName::Identifier: |
| 933 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 934 | break; |
| 935 | case DeclarationName::ObjCZeroArgSelector: |
| 936 | case DeclarationName::ObjCOneArgSelector: |
| 937 | case DeclarationName::ObjCMultiArgSelector: |
| 938 | Key.Data = |
| 939 | (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d)) |
| 940 | .getAsOpaquePtr(); |
| 941 | break; |
| 942 | case DeclarationName::CXXOperatorName: |
| 943 | Key.Data = *d++; // OverloadedOperatorKind |
| 944 | break; |
| 945 | case DeclarationName::CXXLiteralOperatorName: |
| 946 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 947 | break; |
| 948 | case DeclarationName::CXXConstructorName: |
| 949 | case DeclarationName::CXXDestructorName: |
| 950 | case DeclarationName::CXXConversionFunctionName: |
| 951 | case DeclarationName::CXXUsingDirective: |
| 952 | Key.Data = 0; |
| 953 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 956 | return Key; |
| 957 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 958 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 959 | ASTDeclContextNameLookupTrait::data_type |
| 960 | ASTDeclContextNameLookupTrait::ReadData(internal_key_type, |
| 961 | const unsigned char* d, |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 962 | unsigned DataLen) { |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 963 | using namespace clang::io; |
| 964 | unsigned NumDecls = ReadUnalignedLE16(d); |
Douglas Gregor | 9b8b20f | 2012-01-06 16:09:53 +0000 | [diff] [blame] | 965 | LE32DeclID *Start = (LE32DeclID *)d; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 966 | return std::make_pair(Start, Start + NumDecls); |
| 967 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 968 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 969 | bool ASTReader::ReadDeclContextStorage(ModuleFile &M, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 970 | llvm::BitstreamCursor &Cursor, |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 971 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 972 | DeclContextInfo &Info) { |
| 973 | SavedStreamPosition SavedPosition(Cursor); |
| 974 | // First the lexical decls. |
| 975 | if (Offsets.first != 0) { |
| 976 | Cursor.JumpToBit(Offsets.first); |
| 977 | |
| 978 | RecordData Record; |
| 979 | const char *Blob; |
| 980 | unsigned BlobLen; |
| 981 | unsigned Code = Cursor.ReadCode(); |
| 982 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 983 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 984 | Error("Expected lexical block"); |
| 985 | return true; |
| 986 | } |
| 987 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 988 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 989 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | // Now the lookup table. |
| 993 | if (Offsets.second != 0) { |
| 994 | Cursor.JumpToBit(Offsets.second); |
| 995 | |
| 996 | RecordData Record; |
| 997 | const char *Blob; |
| 998 | unsigned BlobLen; |
| 999 | unsigned Code = Cursor.ReadCode(); |
| 1000 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 1001 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 1002 | Error("Expected visible lookup table block"); |
| 1003 | return true; |
| 1004 | } |
| 1005 | Info.NameLookupTableData |
| 1006 | = ASTDeclContextNameLookupTable::Create( |
| 1007 | (const unsigned char *)Blob + Record[0], |
| 1008 | (const unsigned char *)Blob, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1009 | ASTDeclContextNameLookupTrait(*this, M)); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | return false; |
| 1013 | } |
| 1014 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1015 | void ASTReader::Error(StringRef Msg) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1016 | Error(diag::err_fe_pch_malformed, Msg); |
| 1017 | } |
| 1018 | |
| 1019 | void ASTReader::Error(unsigned DiagID, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1020 | StringRef Arg1, StringRef Arg2) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1021 | if (Diags.isDiagnosticInFlight()) |
| 1022 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 1023 | else |
| 1024 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1027 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1028 | bool ASTReader::CheckPredefinesBuffers(bool Complain) { |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 1029 | if (Listener) { |
| 1030 | // We only care about the primary module. |
| 1031 | ModuleFile &M = ModuleMgr.getPrimaryModule(); |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 1032 | SuggestedPredefines.clear(); |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1033 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 1034 | M.ActualOriginalSourceFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 1035 | SuggestedPredefines, |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1036 | FileMgr, |
| 1037 | Complain); |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 1038 | } |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 1039 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1042 | //===----------------------------------------------------------------------===// |
| 1043 | // Source Manager Deserialization |
| 1044 | //===----------------------------------------------------------------------===// |
| 1045 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1046 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1047 | /// \returns true if there was an error. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1048 | bool ASTReader::ParseLineTable(ModuleFile &F, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1049 | SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1050 | unsigned Idx = 0; |
| 1051 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1052 | |
| 1053 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 1054 | std::map<int, int> FileIDs; |
| 1055 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1056 | // Extract the file name |
| 1057 | unsigned FilenameLen = Record[Idx++]; |
| 1058 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 1059 | Idx += FilenameLen; |
Douglas Gregor | caed060 | 2012-10-18 21:31:35 +0000 | [diff] [blame] | 1060 | MaybeAddSystemRootToFilename(F, Filename); |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 1061 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | // Parse the line entries |
| 1065 | std::vector<LineEntry> Entries; |
| 1066 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1067 | int FID = Record[Idx++]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1068 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 1069 | // Remap FileID from 1-based old view. |
| 1070 | FID += F.SLocEntryBaseID - 1; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1071 | |
| 1072 | // Extract the line entries |
| 1073 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1074 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1075 | Entries.clear(); |
| 1076 | Entries.reserve(NumEntries); |
| 1077 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1078 | unsigned FileOffset = Record[Idx++]; |
| 1079 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1080 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1081 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1082 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1083 | unsigned IncludeOffset = Record[Idx++]; |
| 1084 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1085 | FileKind, IncludeOffset)); |
| 1086 | } |
Douglas Gregor | 47d9de6 | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 1087 | LineTable.AddEntry(FileID::get(FID), Entries); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | return false; |
| 1091 | } |
| 1092 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1093 | namespace { |
| 1094 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1095 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1096 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1097 | const ino_t ino; |
| 1098 | const dev_t dev; |
| 1099 | const mode_t mode; |
| 1100 | const time_t mtime; |
| 1101 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1103 | ASTStatData(ino_t i, dev_t d, mode_t mo, time_t m, off_t s) |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1104 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1105 | }; |
| 1106 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1107 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1108 | public: |
| 1109 | typedef const char *external_key_type; |
| 1110 | typedef const char *internal_key_type; |
| 1111 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1112 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1113 | |
| 1114 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1115 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1119 | |
| 1120 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1121 | return strcmp(a, b) == 0; |
| 1122 | } |
| 1123 | |
| 1124 | static std::pair<unsigned, unsigned> |
| 1125 | ReadKeyDataLength(const unsigned char*& d) { |
| 1126 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1127 | unsigned DataLen = (unsigned) *d++; |
| 1128 | return std::make_pair(KeyLen + 1, DataLen); |
| 1129 | } |
| 1130 | |
| 1131 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1132 | return (const char *)d; |
| 1133 | } |
| 1134 | |
| 1135 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1136 | unsigned /*DataLen*/) { |
| 1137 | using namespace clang::io; |
| 1138 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1139 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1140 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1141 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1142 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1143 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1144 | return data_type(ino, dev, mode, mtime, size); |
| 1145 | } |
| 1146 | }; |
| 1147 | |
| 1148 | /// \brief stat() cache for precompiled headers. |
| 1149 | /// |
| 1150 | /// This cache is very similar to the stat cache used by pretokenized |
| 1151 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1152 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1153 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1154 | CacheTy *Cache; |
| 1155 | |
| 1156 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1157 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1158 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1159 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1160 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1161 | Cache = CacheTy::Create(Buckets, Base); |
| 1162 | } |
| 1163 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1164 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1165 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1166 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1167 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1168 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1169 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1170 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1171 | // If we don't get a hit in the AST file just forward to 'stat'. |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1172 | if (I == Cache->end()) { |
| 1173 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1174 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1175 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1176 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1177 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1178 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1180 | StatBuf.st_ino = Data.ino; |
| 1181 | StatBuf.st_dev = Data.dev; |
| 1182 | StatBuf.st_mtime = Data.mtime; |
| 1183 | StatBuf.st_mode = Data.mode; |
| 1184 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1185 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1186 | } |
| 1187 | }; |
| 1188 | } // end anonymous namespace |
| 1189 | |
| 1190 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1191 | /// \brief Read a source manager block |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1192 | bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1193 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1194 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1195 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1196 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1197 | // Set the source-location entry cursor to the current position in |
| 1198 | // the stream. This cursor will be used to read the contents of the |
| 1199 | // source manager block initially, and then lazily read |
| 1200 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1201 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1202 | |
| 1203 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1204 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1205 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1206 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1210 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1211 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1212 | return true; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1213 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1214 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1215 | RecordData Record; |
| 1216 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1217 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1218 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1219 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1220 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1221 | return true; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1222 | } |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1223 | return false; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1224 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1225 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1226 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1227 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1228 | SLocEntryCursor.ReadSubBlockID(); |
| 1229 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1230 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1231 | return true; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1232 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1233 | continue; |
| 1234 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1235 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1236 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1237 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1238 | continue; |
| 1239 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1240 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1241 | // Read a record. |
| 1242 | const char *BlobStart; |
| 1243 | unsigned BlobLen; |
| 1244 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1245 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1246 | default: // Default behavior: ignore. |
| 1247 | break; |
| 1248 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1249 | case SM_SLOC_FILE_ENTRY: |
| 1250 | case SM_SLOC_BUFFER_ENTRY: |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1251 | case SM_SLOC_EXPANSION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1252 | // Once we hit one of the source location entries, we're done. |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1253 | return false; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1254 | } |
| 1255 | } |
| 1256 | } |
| 1257 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1258 | /// \brief If a header file is not found at the path that we expect it to be |
| 1259 | /// and the PCH file was moved from its original location, try to resolve the |
| 1260 | /// file by assuming that header+PCH were moved together and the header is in |
| 1261 | /// the same place relative to the PCH. |
| 1262 | static std::string |
| 1263 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1264 | const std::string &OriginalDir, |
| 1265 | const std::string &CurrDir) { |
| 1266 | assert(OriginalDir != CurrDir && |
| 1267 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1268 | using namespace llvm::sys; |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1269 | SmallString<128> filePath(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1270 | fs::make_absolute(filePath); |
| 1271 | assert(path::is_absolute(OriginalDir)); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1272 | SmallString<128> currPCHPath(CurrDir); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1273 | |
| 1274 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1275 | fileDirE = path::end(path::parent_path(filePath)); |
| 1276 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1277 | origDirE = path::end(OriginalDir); |
| 1278 | // Skip the common path components from filePath and OriginalDir. |
| 1279 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1280 | *fileDirI == *origDirI) { |
| 1281 | ++fileDirI; |
| 1282 | ++origDirI; |
| 1283 | } |
| 1284 | for (; origDirI != origDirE; ++origDirI) |
| 1285 | path::append(currPCHPath, ".."); |
| 1286 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1287 | path::append(currPCHPath, path::filename(Filename)); |
| 1288 | return currPCHPath.str(); |
| 1289 | } |
| 1290 | |
Douglas Gregor | 8b53d14 | 2012-10-22 22:53:10 +0000 | [diff] [blame] | 1291 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1292 | if (ID == 0) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1293 | return false; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1294 | |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1295 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1296 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1297 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1300 | ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1301 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1302 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1303 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1304 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1305 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1306 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1307 | if (Code == llvm::bitc::END_BLOCK || |
| 1308 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1309 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1310 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1311 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1314 | RecordData Record; |
| 1315 | const char *BlobStart; |
| 1316 | unsigned BlobLen; |
| 1317 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1318 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1319 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1320 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1321 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1322 | case SM_SLOC_FILE_ENTRY: { |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 1323 | // We will detect whether a file changed and return 'Failure' for it, but |
| 1324 | // we will also try to fail gracefully by setting up the SLocEntry. |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1325 | unsigned InputID = Record[4]; |
| 1326 | InputFile IF = getInputFile(*F, InputID); |
| 1327 | const FileEntry *File = IF.getPointer(); |
| 1328 | bool OverriddenBuffer = IF.getInt(); |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 1329 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1330 | if (!IF.getPointer()) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1331 | return true; |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1332 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1333 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1334 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1335 | // This is the module's main file. |
| 1336 | IncludeLoc = getImportLocation(F); |
| 1337 | } |
Argyrios Kyrtzidis | ff39896 | 2012-07-11 20:59:04 +0000 | [diff] [blame] | 1338 | SrcMgr::CharacteristicKind |
| 1339 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1340 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter, |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1341 | ID, BaseOffset + Record[0]); |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1342 | SrcMgr::FileInfo &FileInfo = |
| 1343 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1344 | FileInfo.NumCreatedFIDs = Record[5]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1345 | if (Record[3]) |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1346 | FileInfo.setHasLineDirectives(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1347 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1348 | const DeclID *FirstDecl = F->FileSortedDecls + Record[6]; |
| 1349 | unsigned NumFileDecls = Record[7]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1350 | if (NumFileDecls) { |
| 1351 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
Argyrios Kyrtzidis | 9d128d0 | 2011-10-31 07:20:08 +0000 | [diff] [blame] | 1352 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 1353 | NumFileDecls)); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1354 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1355 | |
Douglas Gregor | 35f9ae6 | 2011-11-17 01:44:33 +0000 | [diff] [blame] | 1356 | const SrcMgr::ContentCache *ContentCache |
Argyrios Kyrtzidis | ff39896 | 2012-07-11 20:59:04 +0000 | [diff] [blame] | 1357 | = SourceMgr.getOrCreateContentCache(File, |
| 1358 | /*isSystemFile=*/FileCharacter != SrcMgr::C_User); |
Douglas Gregor | 35f9ae6 | 2011-11-17 01:44:33 +0000 | [diff] [blame] | 1359 | if (OverriddenBuffer && !ContentCache->BufferOverridden && |
| 1360 | ContentCache->ContentsEntry == ContentCache->OrigEntry) { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1361 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1362 | Record.clear(); |
| 1363 | unsigned RecCode |
| 1364 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
| 1365 | |
| 1366 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
| 1367 | Error("AST record has invalid code"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1368 | return true; |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | llvm::MemoryBuffer *Buffer |
| 1372 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1373 | File->getName()); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1374 | SourceMgr.overrideFileContents(File, Buffer); |
| 1375 | } |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 1376 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1377 | break; |
| 1378 | } |
| 1379 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1380 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1381 | const char *Name = BlobStart; |
| 1382 | unsigned Offset = Record[0]; |
| 1383 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1384 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1385 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1386 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1387 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1388 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1389 | Error("AST record has invalid code"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1390 | return true; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1393 | llvm::MemoryBuffer *Buffer |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1394 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
| 1395 | Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1396 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, |
| 1397 | BaseOffset + Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | |
Douglas Gregor | 6236a29 | 2011-12-02 21:56:05 +0000 | [diff] [blame] | 1399 | if (strcmp(Name, "<built-in>") == 0 && F->Kind == MK_PCH) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1400 | PCHPredefinesBlock Block = { |
| 1401 | BufferID, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1402 | StringRef(BlobStart, BlobLen - 1) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1403 | }; |
| 1404 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1405 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1406 | |
| 1407 | break; |
| 1408 | } |
| 1409 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1410 | case SM_SLOC_EXPANSION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1411 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Chandler Carruth | bf340e4 | 2011-07-26 03:03:05 +0000 | [diff] [blame] | 1412 | SourceMgr.createExpansionLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1413 | ReadSourceLocation(*F, Record[2]), |
| 1414 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1415 | Record[4], |
| 1416 | ID, |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1417 | BaseOffset + Record[0]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1418 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1419 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1420 | } |
| 1421 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1422 | return false; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1425 | /// \brief Find the location where the module F is imported. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1426 | SourceLocation ASTReader::getImportLocation(ModuleFile *F) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1427 | if (F->ImportLoc.isValid()) |
| 1428 | return F->ImportLoc; |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1429 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1430 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1431 | // location of its includer. |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1432 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1433 | // Main file is the importer. We assume that it is the first entry in the |
| 1434 | // entry table. We can't ask the manager, because at the time of PCH loading |
| 1435 | // the main file entry doesn't exist yet. |
| 1436 | // The very first entry is the invalid instantiation loc, which takes up |
| 1437 | // offsets 0 and 1. |
| 1438 | return SourceLocation::getFromRawEncoding(2U); |
| 1439 | } |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1440 | //return F->Loaders[0]->FirstLoc; |
| 1441 | return F->ImportedBy[0]->FirstLoc; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1444 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1445 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1446 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1447 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1448 | unsigned BlockID) { |
| 1449 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1450 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1451 | return Failure; |
| 1452 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1453 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1454 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1455 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1456 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1457 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1458 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1459 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1460 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1461 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1462 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1463 | Cursor.ReadAbbrevRecord(); |
| 1464 | } |
| 1465 | } |
| 1466 | |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 1467 | void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset, |
| 1468 | MacroInfo *Hint) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1469 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1470 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1471 | // Keep track of where we are in the stream, then jump back there |
| 1472 | // after reading this macro. |
| 1473 | SavedStreamPosition SavedPosition(Stream); |
| 1474 | |
| 1475 | Stream.JumpToBit(Offset); |
| 1476 | RecordData Record; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1477 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1478 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1479 | |
Douglas Gregor | e8219a6 | 2012-10-11 21:07:39 +0000 | [diff] [blame] | 1480 | // RAII object to add the loaded macro information once we're done |
| 1481 | // adding tokens. |
| 1482 | struct AddLoadedMacroInfoRAII { |
| 1483 | Preprocessor &PP; |
| 1484 | MacroInfo *Hint; |
| 1485 | MacroInfo *MI; |
| 1486 | IdentifierInfo *II; |
| 1487 | |
| 1488 | AddLoadedMacroInfoRAII(Preprocessor &PP, MacroInfo *Hint) |
| 1489 | : PP(PP), Hint(Hint), MI(), II() { } |
| 1490 | ~AddLoadedMacroInfoRAII( ) { |
| 1491 | if (MI) { |
| 1492 | // Finally, install the macro. |
| 1493 | PP.addLoadedMacroInfo(II, MI, Hint); |
| 1494 | } |
| 1495 | } |
| 1496 | } AddLoadedMacroInfo(PP, Hint); |
| 1497 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1498 | while (true) { |
| 1499 | unsigned Code = Stream.ReadCode(); |
| 1500 | switch (Code) { |
| 1501 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1502 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1503 | |
| 1504 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1505 | // No known subblocks, always skip them. |
| 1506 | Stream.ReadSubBlockID(); |
| 1507 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1508 | Error("malformed block record in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1509 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1510 | } |
| 1511 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1512 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1513 | case llvm::bitc::DEFINE_ABBREV: |
| 1514 | Stream.ReadAbbrevRecord(); |
| 1515 | continue; |
| 1516 | default: break; |
| 1517 | } |
| 1518 | |
| 1519 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1520 | const char *BlobStart = 0; |
| 1521 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1522 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1523 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1524 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1525 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1526 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1527 | case PP_MACRO_OBJECT_LIKE: |
| 1528 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1529 | // If we already have a macro, that means that we've hit the end |
| 1530 | // of the definition of the macro we were looking for. We're |
| 1531 | // done. |
| 1532 | if (Macro) |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1533 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1534 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1535 | IdentifierInfo *II = getLocalIdentifier(F, Record[0]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1536 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1537 | Error("macro must have a name in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1538 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1539 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1540 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1541 | unsigned GlobalID = getGlobalMacroID(F, Record[1]); |
| 1542 | |
| 1543 | // If this macro has already been loaded, don't do so again. |
| 1544 | if (MacrosLoaded[GlobalID - NUM_PREDEF_MACRO_IDS]) |
| 1545 | return; |
| 1546 | |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1547 | SubmoduleID GlobalSubmoduleID = getGlobalSubmoduleID(F, Record[2]); |
| 1548 | unsigned NextIndex = 3; |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1549 | SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1550 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1551 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1552 | // Record this macro. |
| 1553 | MacrosLoaded[GlobalID - NUM_PREDEF_MACRO_IDS] = MI; |
| 1554 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1555 | SourceLocation UndefLoc = ReadSourceLocation(F, Record, NextIndex); |
| 1556 | if (UndefLoc.isValid()) |
| 1557 | MI->setUndefLoc(UndefLoc); |
| 1558 | |
| 1559 | MI->setIsUsed(Record[NextIndex++]); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1560 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1561 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1562 | bool IsPublic = Record[NextIndex++]; |
Douglas Gregor | aa93a87 | 2011-10-17 15:32:29 +0000 | [diff] [blame] | 1563 | MI->setVisibility(IsPublic, ReadSourceLocation(F, Record, NextIndex)); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1564 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1565 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1566 | // Decode function-like macro info. |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1567 | bool isC99VarArgs = Record[NextIndex++]; |
| 1568 | bool isGNUVarArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1569 | MacroArgs.clear(); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1570 | unsigned NumArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1571 | for (unsigned i = 0; i != NumArgs; ++i) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1572 | MacroArgs.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1573 | |
| 1574 | // Install function-like macro info. |
| 1575 | MI->setIsFunctionLike(); |
| 1576 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1577 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1578 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1579 | PP.getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1582 | if (DeserializationListener) |
| 1583 | DeserializationListener->MacroRead(GlobalID, MI); |
| 1584 | |
| 1585 | // If an update record marked this as undefined, do so now. |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1586 | // FIXME: Only if the submodule this update came from is visible? |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1587 | MacroUpdatesMap::iterator Update = MacroUpdates.find(GlobalID); |
| 1588 | if (Update != MacroUpdates.end()) { |
| 1589 | if (MI->getUndefLoc().isInvalid()) { |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 1590 | for (unsigned I = 0, N = Update->second.size(); I != N; ++I) { |
| 1591 | bool Hidden = false; |
| 1592 | if (unsigned SubmoduleID = Update->second[I].first) { |
| 1593 | if (Module *Owner = getSubmodule(SubmoduleID)) { |
| 1594 | if (Owner->NameVisibility == Module::Hidden) { |
| 1595 | // Note that this #undef is hidden. |
| 1596 | Hidden = true; |
| 1597 | |
| 1598 | // Record this hiding for later. |
| 1599 | HiddenNamesMap[Owner].push_back( |
| 1600 | HiddenName(II, MI, Update->second[I].second.UndefLoc)); |
| 1601 | } |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | if (!Hidden) { |
| 1606 | MI->setUndefLoc(Update->second[I].second.UndefLoc); |
| 1607 | if (PPMutationListener *Listener = PP.getPPMutationListener()) |
| 1608 | Listener->UndefinedMacro(MI); |
| 1609 | break; |
| 1610 | } |
| 1611 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1612 | } |
| 1613 | MacroUpdates.erase(Update); |
| 1614 | } |
| 1615 | |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1616 | // Determine whether this macro definition is visible. |
| 1617 | bool Hidden = !MI->isPublic(); |
| 1618 | if (!Hidden && GlobalSubmoduleID) { |
| 1619 | if (Module *Owner = getSubmodule(GlobalSubmoduleID)) { |
| 1620 | if (Owner->NameVisibility == Module::Hidden) { |
| 1621 | // The owning module is not visible, and this macro definition |
| 1622 | // should not be, either. |
| 1623 | Hidden = true; |
| 1624 | |
| 1625 | // Note that this macro definition was hidden because its owning |
| 1626 | // module is not yet visible. |
| 1627 | HiddenNamesMap[Owner].push_back(HiddenName(II, MI)); |
| 1628 | } |
| 1629 | } |
| 1630 | } |
| 1631 | MI->setHidden(Hidden); |
| 1632 | |
Douglas Gregor | e8219a6 | 2012-10-11 21:07:39 +0000 | [diff] [blame] | 1633 | // Make sure we install the macro once we're done. |
| 1634 | AddLoadedMacroInfo.MI = MI; |
| 1635 | AddLoadedMacroInfo.II = II; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1636 | |
| 1637 | // Remember that we saw this macro last so that we add the tokens that |
| 1638 | // form its body to it. |
| 1639 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1640 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1641 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1642 | Record[NextIndex]) { |
| 1643 | // We have a macro definition. Register the association |
| 1644 | PreprocessedEntityID |
| 1645 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1646 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 1647 | PPRec.RegisterMacroDefinition(Macro, |
| 1648 | PPRec.getPPEntityID(GlobalID-1, /*isLoaded=*/true)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1649 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1650 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1651 | ++NumMacrosRead; |
| 1652 | break; |
| 1653 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1654 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1655 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1656 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1657 | // erroneous, just pretend we didn't see this. |
| 1658 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1659 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1660 | Token Tok; |
| 1661 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1662 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1663 | Tok.setLength(Record[1]); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1664 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[2])) |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1665 | Tok.setIdentifierInfo(II); |
| 1666 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1667 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1668 | Macro->AddTokenToBody(Tok); |
| 1669 | break; |
| 1670 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 1671 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1672 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1675 | PreprocessedEntityID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1676 | ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const { |
Argyrios Kyrtzidis | 1f6d225 | 2011-09-19 20:40:02 +0000 | [diff] [blame] | 1677 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1678 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1679 | assert(I != M.PreprocessedEntityRemap.end() |
| 1680 | && "Invalid index into preprocessed entity index remap"); |
| 1681 | |
| 1682 | return LocalID + I->second; |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1685 | unsigned HeaderFileInfoTrait::ComputeHash(const char *path) { |
| 1686 | return llvm::HashString(llvm::sys::path::filename(path)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1687 | } |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1688 | |
| 1689 | HeaderFileInfoTrait::internal_key_type |
| 1690 | HeaderFileInfoTrait::GetInternalKey(const char *path) { return path; } |
| 1691 | |
| 1692 | bool HeaderFileInfoTrait::EqualKey(internal_key_type a, internal_key_type b) { |
| 1693 | if (strcmp(a, b) == 0) |
| 1694 | return true; |
| 1695 | |
| 1696 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1697 | return false; |
Douglas Gregor | 99a922b | 2011-12-09 16:22:07 +0000 | [diff] [blame] | 1698 | |
| 1699 | // Determine whether the actual files are equivalent. |
| 1700 | bool Result = false; |
| 1701 | if (llvm::sys::fs::equivalent(a, b, Result)) |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1702 | return false; |
| 1703 | |
Douglas Gregor | 99a922b | 2011-12-09 16:22:07 +0000 | [diff] [blame] | 1704 | return Result; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | std::pair<unsigned, unsigned> |
| 1708 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 1709 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1710 | unsigned DataLen = (unsigned) *d++; |
| 1711 | return std::make_pair(KeyLen + 1, DataLen); |
| 1712 | } |
| 1713 | |
| 1714 | HeaderFileInfoTrait::data_type |
| 1715 | HeaderFileInfoTrait::ReadData(const internal_key_type, const unsigned char *d, |
| 1716 | unsigned DataLen) { |
| 1717 | const unsigned char *End = d + DataLen; |
| 1718 | using namespace clang::io; |
| 1719 | HeaderFileInfo HFI; |
| 1720 | unsigned Flags = *d++; |
| 1721 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1722 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1723 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1724 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1725 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
| 1726 | HFI.NumIncludes = ReadUnalignedLE16(d); |
Douglas Gregor | 541ba16 | 2011-10-17 18:53:12 +0000 | [diff] [blame] | 1727 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID(M, |
| 1728 | ReadUnalignedLE32(d)); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1729 | if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { |
| 1730 | // The framework offset is 1 greater than the actual offset, |
| 1731 | // since 0 is used as an indicator for "no framework name". |
| 1732 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1733 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1734 | } |
| 1735 | |
| 1736 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1737 | (void)End; |
| 1738 | |
| 1739 | // This HeaderFileInfo was externally loaded. |
| 1740 | HFI.External = true; |
| 1741 | return HFI; |
| 1742 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1743 | |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1744 | void ASTReader::setIdentifierIsMacro(IdentifierInfo *II, ArrayRef<MacroID> IDs){ |
| 1745 | II->setHadMacroDefinition(true); |
| 1746 | assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard"); |
| 1747 | PendingMacroIDs[II].append(IDs.begin(), IDs.end()); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1750 | void ASTReader::ReadDefinedMacros() { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1751 | // Note that we are loading defined macros. |
| 1752 | Deserializing Macros(this); |
| 1753 | |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1754 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1755 | E = ModuleMgr.rend(); I != E; ++I) { |
| 1756 | llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1757 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1758 | // If there was no preprocessor block, skip this file. |
| 1759 | if (!MacroCursor.getBitStreamReader()) |
| 1760 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1761 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1762 | llvm::BitstreamCursor Cursor = MacroCursor; |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1763 | Cursor.JumpToBit((*I)->MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1764 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1765 | RecordData Record; |
| 1766 | while (true) { |
| 1767 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1768 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1769 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1770 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1771 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1772 | // No known subblocks, always skip them. |
| 1773 | Cursor.ReadSubBlockID(); |
| 1774 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1775 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1776 | return; |
| 1777 | } |
| 1778 | continue; |
| 1779 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1780 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1781 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1782 | Cursor.ReadAbbrevRecord(); |
| 1783 | continue; |
| 1784 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1785 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1786 | // Read a record. |
| 1787 | const char *BlobStart; |
| 1788 | unsigned BlobLen; |
| 1789 | Record.clear(); |
| 1790 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1791 | default: // Default behavior: ignore. |
| 1792 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1793 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1794 | case PP_MACRO_OBJECT_LIKE: |
| 1795 | case PP_MACRO_FUNCTION_LIKE: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1796 | getLocalIdentifier(**I, Record[0]); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1797 | break; |
| 1798 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1799 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1800 | // Ignore tokens. |
| 1801 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1802 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1803 | } |
| 1804 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1805 | } |
| 1806 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1807 | namespace { |
| 1808 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 1809 | class IdentifierLookupVisitor { |
| 1810 | StringRef Name; |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1811 | unsigned PriorGeneration; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1812 | IdentifierInfo *Found; |
| 1813 | public: |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1814 | IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration) |
| 1815 | : Name(Name), PriorGeneration(PriorGeneration), Found() { } |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1816 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1817 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1818 | IdentifierLookupVisitor *This |
| 1819 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 1820 | |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1821 | // If we've already searched this module file, skip it now. |
| 1822 | if (M.Generation <= This->PriorGeneration) |
| 1823 | return true; |
| 1824 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1825 | ASTIdentifierLookupTable *IdTable |
| 1826 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 1827 | if (!IdTable) |
| 1828 | return false; |
| 1829 | |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1830 | ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), |
| 1831 | M, This->Found); |
| 1832 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1833 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 1834 | This->Name.size()); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1835 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Trait); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1836 | if (Pos == IdTable->end()) |
| 1837 | return false; |
| 1838 | |
| 1839 | // Dereferencing the iterator has the effect of building the |
| 1840 | // IdentifierInfo node and populating it with the various |
| 1841 | // declarations it needs. |
| 1842 | This->Found = *Pos; |
| 1843 | return true; |
| 1844 | } |
| 1845 | |
| 1846 | // \brief Retrieve the identifier info found within the module |
| 1847 | // files. |
| 1848 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 1849 | }; |
| 1850 | } |
| 1851 | |
| 1852 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1853 | // Note that we are loading an identifier. |
| 1854 | Deserializing AnIdentifier(this); |
| 1855 | |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1856 | unsigned PriorGeneration = 0; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1857 | if (getContext().getLangOpts().Modules) |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1858 | PriorGeneration = IdentifierGeneration[&II]; |
| 1859 | |
| 1860 | IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration); |
| 1861 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
| 1862 | markIdentifierUpToDate(&II); |
| 1863 | } |
| 1864 | |
| 1865 | void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { |
| 1866 | if (!II) |
| 1867 | return; |
| 1868 | |
| 1869 | II->setOutOfDate(false); |
| 1870 | |
| 1871 | // Update the generation for this identifier. |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1872 | if (getContext().getLangOpts().Modules) |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1873 | IdentifierGeneration[II] = CurrentGeneration; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1876 | llvm::PointerIntPair<const FileEntry *, 1, bool> |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1877 | ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1878 | // If this ID is bogus, just return an empty input file. |
| 1879 | if (ID == 0 || ID > F.InputFilesLoaded.size()) |
| 1880 | return InputFile(); |
| 1881 | |
| 1882 | // If we've already loaded this input file, return it. |
| 1883 | if (F.InputFilesLoaded[ID-1].getPointer()) |
| 1884 | return F.InputFilesLoaded[ID-1]; |
| 1885 | |
| 1886 | // Go find this input file. |
| 1887 | llvm::BitstreamCursor &Cursor = F.InputFilesCursor; |
| 1888 | SavedStreamPosition SavedPosition(Cursor); |
| 1889 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
| 1890 | |
| 1891 | unsigned Code = Cursor.ReadCode(); |
| 1892 | RecordData Record; |
| 1893 | const char *BlobStart = 0; |
| 1894 | unsigned BlobLen = 0; |
| 1895 | switch ((InputFileRecordTypes)Cursor.ReadRecord(Code, Record, |
| 1896 | &BlobStart, &BlobLen)) { |
| 1897 | case INPUT_FILE: { |
| 1898 | unsigned StoredID = Record[0]; |
| 1899 | assert(ID == StoredID && "Bogus stored ID or offset"); |
NAKAMURA Takumi | 6b8194e | 2012-10-22 21:50:39 +0000 | [diff] [blame] | 1900 | (void)StoredID; |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1901 | off_t StoredSize = (off_t)Record[1]; |
| 1902 | time_t StoredTime = (time_t)Record[2]; |
| 1903 | bool Overridden = (bool)Record[3]; |
| 1904 | |
| 1905 | // Get the file entry for this input file. |
| 1906 | StringRef OrigFilename(BlobStart, BlobLen); |
| 1907 | std::string Filename = OrigFilename; |
| 1908 | MaybeAddSystemRootToFilename(F, Filename); |
| 1909 | const FileEntry *File |
| 1910 | = Overridden? FileMgr.getVirtualFile(Filename, StoredSize, StoredTime) |
| 1911 | : FileMgr.getFile(Filename, /*OpenFile=*/false); |
| 1912 | |
| 1913 | // If we didn't find the file, resolve it relative to the |
| 1914 | // original directory from which this AST file was created. |
| 1915 | if (File == 0 && !F.OriginalDir.empty() && !CurrentDir.empty() && |
| 1916 | F.OriginalDir != CurrentDir) { |
| 1917 | std::string Resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1918 | F.OriginalDir, |
| 1919 | CurrentDir); |
| 1920 | if (!Resolved.empty()) |
| 1921 | File = FileMgr.getFile(Resolved); |
| 1922 | } |
| 1923 | |
| 1924 | // For an overridden file, create a virtual file with the stored |
| 1925 | // size/timestamp. |
| 1926 | if (Overridden && File == 0) { |
| 1927 | File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime); |
| 1928 | } |
| 1929 | |
| 1930 | if (File == 0) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1931 | if (Complain) { |
| 1932 | std::string ErrorStr = "could not find file '"; |
| 1933 | ErrorStr += Filename; |
| 1934 | ErrorStr += "' referenced by AST file"; |
| 1935 | Error(ErrorStr.c_str()); |
| 1936 | } |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1937 | return InputFile(); |
| 1938 | } |
| 1939 | |
| 1940 | // Note that we've loaded this input file. |
| 1941 | F.InputFilesLoaded[ID-1] = InputFile(File, Overridden); |
| 1942 | |
| 1943 | // Check if there was a request to override the contents of the file |
| 1944 | // that was part of the precompiled header. Overridding such a file |
| 1945 | // can lead to problems when lexing using the source locations from the |
| 1946 | // PCH. |
| 1947 | SourceManager &SM = getSourceManager(); |
| 1948 | if (!Overridden && SM.isFileOverridden(File)) { |
| 1949 | Error(diag::err_fe_pch_file_overridden, Filename); |
| 1950 | // After emitting the diagnostic, recover by disabling the override so |
| 1951 | // that the original file will be used. |
| 1952 | SM.disableFileContentsOverride(File); |
| 1953 | // The FileEntry is a virtual file entry with the size of the contents |
| 1954 | // that would override the original contents. Set it to the original's |
| 1955 | // size/time. |
| 1956 | FileMgr.modifyFileEntry(const_cast<FileEntry*>(File), |
| 1957 | StoredSize, StoredTime); |
| 1958 | } |
| 1959 | |
| 1960 | // For an overridden file, there is nothing to validate. |
| 1961 | if (Overridden) |
| 1962 | return InputFile(File, Overridden); |
| 1963 | |
| 1964 | // The stat info from the FileEntry came from the cached stat |
| 1965 | // info of the PCH, so we cannot trust it. |
| 1966 | struct stat StatBuf; |
| 1967 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 1968 | StatBuf.st_size = File->getSize(); |
| 1969 | StatBuf.st_mtime = File->getModificationTime(); |
| 1970 | } |
| 1971 | |
| 1972 | if ((StoredSize != StatBuf.st_size |
| 1973 | #if !defined(LLVM_ON_WIN32) |
| 1974 | // In our regression testing, the Windows file system seems to |
| 1975 | // have inconsistent modification times that sometimes |
| 1976 | // erroneously trigger this error-handling path. |
| 1977 | || StoredTime != StatBuf.st_mtime |
| 1978 | #endif |
| 1979 | )) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1980 | if (Complain) |
| 1981 | Error(diag::err_fe_pch_file_modified, Filename); |
| 1982 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1983 | return InputFile(); |
| 1984 | } |
| 1985 | |
| 1986 | return InputFile(File, Overridden); |
| 1987 | } |
| 1988 | } |
| 1989 | |
| 1990 | return InputFile(); |
| 1991 | } |
| 1992 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1993 | const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1994 | ModuleFile &M = ModuleMgr.getPrimaryModule(); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1995 | std::string Filename = filenameStrRef; |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1996 | MaybeAddSystemRootToFilename(M, Filename); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1997 | const FileEntry *File = FileMgr.getFile(Filename); |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1998 | if (File == 0 && !M.OriginalDir.empty() && !CurrentDir.empty() && |
| 1999 | M.OriginalDir != CurrentDir) { |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2000 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 2001 | M.OriginalDir, |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2002 | CurrentDir); |
| 2003 | if (!resolved.empty()) |
| 2004 | File = FileMgr.getFile(resolved); |
| 2005 | } |
| 2006 | |
| 2007 | return File; |
| 2008 | } |
| 2009 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2010 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 2011 | /// not an absolute path, add the system root to the beginning of the file |
| 2012 | /// name. |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2013 | StringRef ASTReader::MaybeAddSystemRootToFilename(ModuleFile &M, |
| 2014 | std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2015 | // If this is not a relocatable PCH file, there's nothing to do. |
Douglas Gregor | caed060 | 2012-10-18 21:31:35 +0000 | [diff] [blame] | 2016 | if (!M.RelocatablePCH) |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2017 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2018 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 2019 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2020 | return Filename; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2021 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 2022 | if (isysroot.empty()) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2023 | // If no system root was given, default to '/' |
| 2024 | Filename.insert(Filename.begin(), '/'); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2025 | return Filename; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2026 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2027 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 2028 | unsigned Length = isysroot.size(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2029 | if (isysroot[Length - 1] != '/') |
| 2030 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2031 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 2032 | Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end()); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2033 | return Filename; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2036 | ASTReader::ASTReadResult |
| 2037 | ASTReader::ReadControlBlock(ModuleFile &F, |
| 2038 | llvm::SmallVectorImpl<ModuleFile *> &Loaded, |
| 2039 | unsigned ClientLoadCapabilities) { |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2040 | llvm::BitstreamCursor &Stream = F.Stream; |
| 2041 | |
| 2042 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
| 2043 | Error("malformed block record in AST file"); |
| 2044 | return Failure; |
| 2045 | } |
| 2046 | |
| 2047 | // Read all of the records and blocks in the control block. |
| 2048 | RecordData Record; |
| 2049 | while (!Stream.AtEndOfStream()) { |
| 2050 | unsigned Code = Stream.ReadCode(); |
| 2051 | if (Code == llvm::bitc::END_BLOCK) { |
| 2052 | if (Stream.ReadBlockEnd()) { |
| 2053 | Error("error at end of control block in AST file"); |
| 2054 | return Failure; |
| 2055 | } |
| 2056 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2057 | // Validate all of the input files. |
| 2058 | if (!DisableValidation) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2059 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2060 | for (unsigned I = 0, N = Record[0]; I < N; ++I) |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2061 | if (!getInputFile(F, I+1, Complain).getPointer()) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2062 | return OutOfDate; |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2063 | } |
| 2064 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2065 | return Success; |
| 2066 | } |
| 2067 | |
| 2068 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 2069 | switch (Stream.ReadSubBlockID()) { |
| 2070 | case INPUT_FILES_BLOCK_ID: |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2071 | F.InputFilesCursor = Stream; |
| 2072 | if (Stream.SkipBlock() || // Skip with the main cursor |
| 2073 | // Read the abbreviations |
| 2074 | ReadBlockAbbrevs(F.InputFilesCursor, INPUT_FILES_BLOCK_ID)) { |
| 2075 | Error("malformed block record in AST file"); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 2076 | return Failure; |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 2077 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2078 | continue; |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 2079 | |
| 2080 | default: |
| 2081 | if (!Stream.SkipBlock()) |
| 2082 | continue; |
| 2083 | break; |
| 2084 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2085 | |
| 2086 | Error("malformed block record in AST file"); |
| 2087 | return Failure; |
| 2088 | } |
| 2089 | |
| 2090 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2091 | Stream.ReadAbbrevRecord(); |
| 2092 | continue; |
| 2093 | } |
| 2094 | |
| 2095 | // Read and process a record. |
| 2096 | Record.clear(); |
| 2097 | const char *BlobStart = 0; |
| 2098 | unsigned BlobLen = 0; |
| 2099 | switch ((ControlRecordTypes)Stream.ReadRecord(Code, Record, |
| 2100 | &BlobStart, &BlobLen)) { |
| 2101 | case METADATA: { |
| 2102 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2103 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
| 2104 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
| 2105 | : diag::warn_pch_version_too_new); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2106 | return VersionMismatch; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | bool hasErrors = Record[5]; |
| 2110 | if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) { |
| 2111 | Diag(diag::err_pch_with_compiler_errors); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2112 | return HadErrors; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2113 | } |
| 2114 | |
Douglas Gregor | caed060 | 2012-10-18 21:31:35 +0000 | [diff] [blame] | 2115 | F.RelocatablePCH = Record[4]; |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 2116 | |
| 2117 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
| 2118 | StringRef ASTBranch(BlobStart, BlobLen); |
| 2119 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2120 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
| 2121 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2122 | return VersionMismatch; |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 2123 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2124 | break; |
| 2125 | } |
| 2126 | |
| 2127 | case IMPORTS: { |
| 2128 | // Load each of the imported PCH files. |
| 2129 | unsigned Idx = 0, N = Record.size(); |
| 2130 | while (Idx < N) { |
| 2131 | // Read information about the AST file. |
| 2132 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 2133 | unsigned Length = Record[Idx++]; |
| 2134 | SmallString<128> ImportedFile(Record.begin() + Idx, |
| 2135 | Record.begin() + Idx + Length); |
| 2136 | Idx += Length; |
| 2137 | |
| 2138 | // Load the AST file. |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2139 | switch(ReadASTCore(ImportedFile, ImportedKind, &F, Loaded, |
| 2140 | ClientLoadCapabilities)) { |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2141 | case Failure: return Failure; |
| 2142 | // If we have to ignore the dependency, we'll have to ignore this too. |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2143 | case OutOfDate: return OutOfDate; |
| 2144 | case VersionMismatch: return VersionMismatch; |
| 2145 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 2146 | case HadErrors: return HadErrors; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2147 | case Success: break; |
| 2148 | } |
| 2149 | } |
| 2150 | break; |
| 2151 | } |
| 2152 | |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2153 | case LANGUAGE_OPTIONS: { |
| 2154 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2155 | if (Listener && &F == *ModuleMgr.begin() && |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 2156 | ParseLanguageOptions(Record, Complain, *Listener) && |
| 2157 | !DisableValidation) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2158 | return ConfigurationMismatch; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2159 | break; |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2160 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2161 | |
Douglas Gregor | ee097c1 | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 2162 | case TARGET_OPTIONS: { |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 2163 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 2164 | if (Listener && &F == *ModuleMgr.begin() && |
| 2165 | ParseTargetOptions(Record, Complain, *Listener) && |
| 2166 | !DisableValidation) |
| 2167 | return ConfigurationMismatch; |
Douglas Gregor | ee097c1 | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 2168 | break; |
| 2169 | } |
| 2170 | |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 2171 | case DIAGNOSTIC_OPTIONS: { |
| 2172 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 2173 | if (Listener && &F == *ModuleMgr.begin() && |
| 2174 | ParseDiagnosticOptions(Record, Complain, *Listener) && |
| 2175 | !DisableValidation) |
| 2176 | return ConfigurationMismatch; |
| 2177 | break; |
| 2178 | } |
Douglas Gregor | 1b2c3c0 | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 2179 | |
| 2180 | case FILE_SYSTEM_OPTIONS: { |
| 2181 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 2182 | if (Listener && &F == *ModuleMgr.begin() && |
| 2183 | ParseFileSystemOptions(Record, Complain, *Listener) && |
| 2184 | !DisableValidation) |
| 2185 | return ConfigurationMismatch; |
| 2186 | break; |
| 2187 | } |
| 2188 | |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 2189 | case HEADER_SEARCH_OPTIONS: { |
| 2190 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 2191 | if (Listener && &F == *ModuleMgr.begin() && |
| 2192 | ParseHeaderSearchOptions(Record, Complain, *Listener) && |
| 2193 | !DisableValidation) |
| 2194 | return ConfigurationMismatch; |
| 2195 | break; |
| 2196 | } |
| 2197 | |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 2198 | case PREPROCESSOR_OPTIONS: { |
| 2199 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 2200 | if (Listener && &F == *ModuleMgr.begin() && |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 2201 | ParsePreprocessorOptions(Record, Complain, *Listener, |
| 2202 | SuggestedPredefines) && |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 2203 | !DisableValidation) |
| 2204 | return ConfigurationMismatch; |
| 2205 | break; |
| 2206 | } |
| 2207 | |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 2208 | case ORIGINAL_FILE: |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 2209 | F.OriginalSourceFileID = FileID::get(Record[0]); |
| 2210 | F.ActualOriginalSourceFileName.assign(BlobStart, BlobLen); |
| 2211 | F.OriginalSourceFileName = F.ActualOriginalSourceFileName; |
| 2212 | MaybeAddSystemRootToFilename(F, F.OriginalSourceFileName); |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2213 | break; |
| 2214 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2215 | case ORIGINAL_PCH_DIR: |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 2216 | F.OriginalDir.assign(BlobStart, BlobLen); |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2217 | break; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2218 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2219 | case INPUT_FILE_OFFSETS: |
| 2220 | F.InputFileOffsets = (const uint32_t *)BlobStart; |
| 2221 | F.InputFilesLoaded.resize(Record[0]); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 2222 | break; |
| 2223 | } |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | Error("premature end of bitstream in AST file"); |
| 2227 | return Failure; |
| 2228 | } |
| 2229 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2230 | bool ASTReader::ReadASTBlock(ModuleFile &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2231 | llvm::BitstreamCursor &Stream = F.Stream; |
| 2232 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2233 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2234 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2235 | return true; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2236 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2237 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2238 | // Read all of the records and blocks for the AST file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2239 | RecordData Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2240 | while (!Stream.AtEndOfStream()) { |
| 2241 | unsigned Code = Stream.ReadCode(); |
| 2242 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2243 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2244 | Error("error at end of module block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2245 | return true; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2246 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2247 | |
Argyrios Kyrtzidis | 1f94124 | 2012-09-21 01:30:00 +0000 | [diff] [blame] | 2248 | DeclContext *DC = Context.getTranslationUnitDecl(); |
| 2249 | if (!DC->hasExternalVisibleStorage() && DC->hasExternalLexicalStorage()) |
| 2250 | DC->setMustBuildLookupTable(); |
| 2251 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2252 | return false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2256 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2257 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 2258 | // We lazily load the decls block, but we want to set up the |
| 2259 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 2260 | // cursor to it, enter the block and read the abbrevs in that block. |
| 2261 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2262 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 2263 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 2264 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2265 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2266 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2267 | return true; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 2268 | } |
| 2269 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2270 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2271 | case DECL_UPDATES_BLOCK_ID: |
| 2272 | if (Stream.SkipBlock()) { |
| 2273 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2274 | return true; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2275 | } |
| 2276 | break; |
| 2277 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2278 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2279 | F.MacroCursor = Stream; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2280 | if (!PP.getExternalSource()) |
| 2281 | PP.setExternalSource(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2282 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2283 | if (Stream.SkipBlock() || |
| 2284 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2285 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2286 | return true; |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2287 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2288 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 2289 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2290 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2291 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 2292 | F.PreprocessorDetailCursor = Stream; |
| 2293 | if (Stream.SkipBlock() || |
| 2294 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 2295 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 2296 | Error("malformed preprocessor detail record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2297 | return true; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2298 | } |
| 2299 | F.PreprocessorDetailStartOffset |
| 2300 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2301 | |
| 2302 | if (!PP.getPreprocessingRecord()) |
Argyrios Kyrtzidis | c6c5452 | 2012-03-05 05:48:17 +0000 | [diff] [blame] | 2303 | PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2304 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2305 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2306 | break; |
| 2307 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2308 | case SOURCE_MANAGER_BLOCK_ID: |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2309 | if (ReadSourceManagerBlock(F)) |
| 2310 | return true; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2311 | break; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2312 | |
| 2313 | case SUBMODULE_BLOCK_ID: |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2314 | if (ReadSubmoduleBlock(F)) |
| 2315 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2316 | break; |
| 2317 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2318 | case COMMENTS_BLOCK_ID: { |
| 2319 | llvm::BitstreamCursor C = Stream; |
| 2320 | if (Stream.SkipBlock() || |
| 2321 | ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) { |
| 2322 | Error("malformed comments block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2323 | return true; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2324 | } |
| 2325 | CommentsCursors.push_back(std::make_pair(C, &F)); |
| 2326 | break; |
| 2327 | } |
| 2328 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2329 | default: |
| 2330 | if (!Stream.SkipBlock()) |
| 2331 | break; |
| 2332 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2333 | return true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2334 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2335 | continue; |
| 2336 | } |
| 2337 | |
| 2338 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2339 | Stream.ReadAbbrevRecord(); |
| 2340 | continue; |
| 2341 | } |
| 2342 | |
| 2343 | // Read and process a record. |
| 2344 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2345 | const char *BlobStart = 0; |
| 2346 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2347 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2348 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2349 | default: // Default behavior: ignore. |
| 2350 | break; |
| 2351 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2352 | case TYPE_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2353 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2354 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2355 | return true; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2356 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2357 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 2358 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2359 | unsigned LocalBaseTypeIndex = Record[1]; |
| 2360 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 2361 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2362 | if (F.LocalNumTypes > 0) { |
| 2363 | // Introduce the global -> local mapping for types within this module. |
| 2364 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 2365 | |
| 2366 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2367 | F.TypeRemap.insertOrReplace( |
| 2368 | std::make_pair(LocalBaseTypeIndex, |
| 2369 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2370 | |
| 2371 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 2372 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2373 | break; |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2376 | case DECL_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2377 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2378 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2379 | return true; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2380 | } |
Argyrios Kyrtzidis | 9d31fa7 | 2011-10-27 18:47:35 +0000 | [diff] [blame] | 2381 | F.DeclOffsets = (const DeclOffset *)BlobStart; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2382 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2383 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2384 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 96e973f | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 2385 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2386 | if (F.LocalNumDecls > 0) { |
| 2387 | // Introduce the global -> local mapping for declarations within this |
| 2388 | // module. |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2389 | GlobalDeclMap.insert( |
| 2390 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2391 | |
| 2392 | // Introduce the local -> global mapping for declarations within this |
| 2393 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2394 | F.DeclRemap.insertOrReplace( |
| 2395 | std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2396 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2397 | // Introduce the global -> local mapping for declarations within this |
| 2398 | // module. |
| 2399 | F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID; |
| 2400 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2401 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 2402 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2403 | break; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2404 | } |
| 2405 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2406 | case TU_UPDATE_LEXICAL: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2407 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 2408 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
| 2409 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); |
| 2410 | Info.NumLexicalDecls |
| 2411 | = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2412 | TU->setHasExternalLexicalStorage(true); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2413 | break; |
| 2414 | } |
| 2415 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2416 | case UPDATE_VISIBLE: { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2417 | unsigned Idx = 0; |
| 2418 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 2419 | ASTDeclContextNameLookupTable *Table = |
| 2420 | ASTDeclContextNameLookupTable::Create( |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2421 | (const unsigned char *)BlobStart + Record[Idx++], |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2422 | (const unsigned char *)BlobStart, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 2423 | ASTDeclContextNameLookupTrait(*this, F)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2424 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID) { // Is it the TU? |
| 2425 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 2426 | F.DeclContextInfos[TU].NameLookupTableData = Table; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2427 | TU->setHasExternalVisibleStorage(true); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2428 | } else |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2429 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2430 | break; |
| 2431 | } |
| 2432 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2433 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2434 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2435 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2436 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2437 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2438 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2439 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2440 | ASTIdentifierLookupTrait(*this, F)); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2441 | |
| 2442 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2443 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2444 | break; |
| 2445 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2446 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2447 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2448 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2449 | return true; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2450 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2451 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2452 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2453 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2454 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 2455 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2456 | if (F.LocalNumIdentifiers > 0) { |
| 2457 | // Introduce the global -> local mapping for identifiers within this |
| 2458 | // module. |
| 2459 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 2460 | &F)); |
| 2461 | |
| 2462 | // Introduce the local -> global mapping for identifiers within this |
| 2463 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2464 | F.IdentifierRemap.insertOrReplace( |
| 2465 | std::make_pair(LocalBaseIdentifierID, |
| 2466 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2467 | |
| 2468 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2469 | + F.LocalNumIdentifiers); |
| 2470 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2471 | break; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2472 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2473 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2474 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2475 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2476 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2477 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2478 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2479 | case SPECIAL_TYPES: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 2480 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2481 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2482 | break; |
| 2483 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2484 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2485 | TotalNumStatements += Record[0]; |
| 2486 | TotalNumMacros += Record[1]; |
| 2487 | TotalLexicalDeclContexts += Record[2]; |
| 2488 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2489 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2490 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2491 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2492 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2493 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2494 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2495 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2496 | case DELEGATING_CTORS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2497 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2498 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2499 | break; |
| 2500 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2501 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 2502 | if (Record.size() % 4 != 0) { |
| 2503 | Error("invalid weak identifiers record"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2504 | return true; |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 2505 | } |
| 2506 | |
| 2507 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 2508 | // files. This isn't the way to do it :) |
| 2509 | WeakUndeclaredIdentifiers.clear(); |
| 2510 | |
| 2511 | // Translate the weak, undeclared identifiers into global IDs. |
| 2512 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2513 | WeakUndeclaredIdentifiers.push_back( |
| 2514 | getGlobalIdentifierID(F, Record[I++])); |
| 2515 | WeakUndeclaredIdentifiers.push_back( |
| 2516 | getGlobalIdentifierID(F, Record[I++])); |
| 2517 | WeakUndeclaredIdentifiers.push_back( |
| 2518 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2519 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2520 | } |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2521 | break; |
| 2522 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2523 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2524 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2525 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2526 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2527 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2528 | case SELECTOR_OFFSETS: { |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2529 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2530 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2531 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2532 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 2533 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2534 | if (F.LocalNumSelectors > 0) { |
| 2535 | // Introduce the global -> local mapping for selectors within this |
| 2536 | // module. |
| 2537 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 2538 | |
| 2539 | // Introduce the local -> global mapping for selectors within this |
| 2540 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2541 | F.SelectorRemap.insertOrReplace( |
| 2542 | std::make_pair(LocalBaseSelectorID, |
| 2543 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2544 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2545 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 2546 | } |
| 2547 | break; |
| 2548 | } |
| 2549 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2550 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2551 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2552 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2553 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2554 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2555 | F.SelectorLookupTableData + Record[0], |
| 2556 | F.SelectorLookupTableData, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2557 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2558 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2559 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2560 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2561 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 2562 | if (!Record.empty()) { |
| 2563 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2564 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 2565 | Record[Idx++])); |
| 2566 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2567 | getRawEncoding()); |
| 2568 | } |
| 2569 | } |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2570 | break; |
| 2571 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2572 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2573 | if (!Record.empty() && Listener) |
Argyrios Kyrtzidis | 62288ed | 2012-10-10 02:12:47 +0000 | [diff] [blame] | 2574 | Listener->ReadCounter(F, Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2575 | break; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2576 | |
| 2577 | case FILE_SORTED_DECLS: |
| 2578 | F.FileSortedDecls = (const DeclID *)BlobStart; |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2579 | F.NumFileSortedDecls = Record[0]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2580 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2581 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2582 | case SOURCE_LOCATION_OFFSETS: { |
| 2583 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2584 | F.LocalNumSLocEntries = Record[0]; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2585 | unsigned SLocSpaceSize = Record[1]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2586 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2587 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
| 2588 | SLocSpaceSize); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2589 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2590 | // we invert it. Because we invert it, though, we need the other end of |
| 2591 | // the range. |
| 2592 | unsigned RangeStart = |
| 2593 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2594 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2595 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2596 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2597 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 2598 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 2599 | GlobalSLocOffsetMap.insert( |
| 2600 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 2601 | - SLocSpaceSize,&F)); |
| 2602 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2603 | // Initialize the remapping table. |
| 2604 | // Invalid stays invalid. |
| 2605 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2606 | // This module. Base was 2 when being compiled. |
| 2607 | F.SLocRemap.insert(std::make_pair(2U, |
| 2608 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2609 | |
| 2610 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2611 | break; |
| 2612 | } |
| 2613 | |
Douglas Gregor | 5d51a1d | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 2614 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2615 | // Additional remapping information. |
| 2616 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2617 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2618 | |
| 2619 | // Continuous range maps we may be updating in our module. |
| 2620 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2621 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2622 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2623 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2624 | MacroRemap(F.MacroRemap); |
| 2625 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2626 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2627 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2628 | SubmoduleRemap(F.SubmoduleRemap); |
| 2629 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2630 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2631 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2632 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 2633 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2634 | while(Data < DataEnd) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2635 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2636 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2637 | Data += Len; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2638 | ModuleFile *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2639 | if (!OM) { |
| 2640 | Error("SourceLocation remap refers to unknown module"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2641 | return true; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2642 | } |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2643 | |
| 2644 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 2645 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2646 | uint32_t MacroIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2647 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2648 | uint32_t SubmoduleIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2649 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 2650 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2651 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2652 | |
| 2653 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 2654 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 2655 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2656 | IdentifierRemap.insert( |
| 2657 | std::make_pair(IdentifierIDOffset, |
| 2658 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2659 | MacroRemap.insert(std::make_pair(MacroIDOffset, |
| 2660 | OM->BaseMacroID - MacroIDOffset)); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2661 | PreprocessedEntityRemap.insert( |
| 2662 | std::make_pair(PreprocessedEntityIDOffset, |
| 2663 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2664 | SubmoduleRemap.insert(std::make_pair(SubmoduleIDOffset, |
| 2665 | OM->BaseSubmoduleID - SubmoduleIDOffset)); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2666 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 2667 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2668 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 2669 | OM->BaseDeclID - DeclIDOffset)); |
| 2670 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2671 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2672 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2673 | |
| 2674 | // Global -> local mappings. |
| 2675 | F.GlobalToLocalDeclIDs[OM] = DeclIDOffset; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2676 | } |
| 2677 | break; |
| 2678 | } |
| 2679 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2680 | case SOURCE_MANAGER_LINE_TABLE: |
| 2681 | if (ParseLineTable(F, Record)) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2682 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2683 | break; |
| 2684 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2685 | case SOURCE_LOCATION_PRELOADS: { |
| 2686 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2687 | // which is based off F.SLocEntryBaseID. |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2688 | if (!F.PreloadSLocEntries.empty()) { |
| 2689 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2690 | return true; |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | F.PreloadSLocEntries.swap(Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2694 | break; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2695 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2696 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2697 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2698 | if (!DisableStatCache) { |
| 2699 | ASTStatCache *MyStatCache = |
| 2700 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2701 | (const unsigned char *)BlobStart, |
| 2702 | NumStatHits, NumStatMisses); |
| 2703 | FileMgr.addStatCache(MyStatCache); |
| 2704 | F.StatCache = MyStatCache; |
| 2705 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2706 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2707 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2708 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2709 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2710 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2711 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2712 | break; |
| 2713 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2714 | case VTABLE_USES: |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2715 | if (Record.size() % 3 != 0) { |
| 2716 | Error("Invalid VTABLE_USES record"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2717 | return true; |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2718 | } |
| 2719 | |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2720 | // Later tables overwrite earlier ones. |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2721 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2722 | // the right way to do this. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2723 | VTableUses.clear(); |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2724 | |
| 2725 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2726 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2727 | VTableUses.push_back( |
| 2728 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2729 | VTableUses.push_back(Record[Idx++]); |
| 2730 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2731 | break; |
| 2732 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2733 | case DYNAMIC_CLASSES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2734 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2735 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2736 | break; |
| 2737 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2738 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2739 | if (PendingInstantiations.size() % 2 != 0) { |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 2740 | Error("Invalid existing PendingInstantiations"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2741 | return true; |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | if (Record.size() % 2 != 0) { |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2745 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2746 | return true; |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2747 | } |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 2748 | |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2749 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2750 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2751 | PendingInstantiations.push_back( |
| 2752 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2753 | } |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2754 | break; |
| 2755 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2756 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2757 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2758 | // FIXME: Modules will have some trouble with this. |
| 2759 | SemaDeclRefs.clear(); |
| 2760 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2761 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2762 | break; |
| 2763 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2764 | case PPD_ENTITIES_OFFSETS: { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2765 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)BlobStart; |
| 2766 | assert(BlobLen % sizeof(PPEntityOffset) == 0); |
| 2767 | F.NumPreprocessedEntities = BlobLen / sizeof(PPEntityOffset); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2768 | |
| 2769 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2770 | |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2771 | unsigned StartingID; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2772 | if (!PP.getPreprocessingRecord()) |
Argyrios Kyrtzidis | c6c5452 | 2012-03-05 05:48:17 +0000 | [diff] [blame] | 2773 | PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2774 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2775 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2776 | StartingID |
| 2777 | = PP.getPreprocessingRecord() |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2778 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2779 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2780 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2781 | if (F.NumPreprocessedEntities > 0) { |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2782 | // Introduce the global -> local mapping for preprocessed entities in |
| 2783 | // this module. |
| 2784 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2785 | |
| 2786 | // Introduce the local -> global mapping for preprocessed entities in |
| 2787 | // this module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2788 | F.PreprocessedEntityRemap.insertOrReplace( |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2789 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2790 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2791 | } |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2792 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2793 | break; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2794 | } |
| 2795 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2796 | case DECL_UPDATE_OFFSETS: { |
| 2797 | if (Record.size() % 2 != 0) { |
| 2798 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2799 | return true; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2800 | } |
| 2801 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2802 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2803 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2804 | break; |
| 2805 | } |
| 2806 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2807 | case DECL_REPLACEMENTS: { |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2808 | if (Record.size() % 3 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2809 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2810 | return true; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2811 | } |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2812 | for (unsigned I = 0, N = Record.size(); I != N; I += 3) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2813 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2814 | = ReplacedDeclInfo(&F, Record[I+1], Record[I+2]); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2815 | break; |
| 2816 | } |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2817 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2818 | case OBJC_CATEGORIES_MAP: { |
| 2819 | if (F.LocalNumObjCCategoriesInMap != 0) { |
| 2820 | Error("duplicate OBJC_CATEGORIES_MAP record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2821 | return true; |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2822 | } |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2823 | |
| 2824 | F.LocalNumObjCCategoriesInMap = Record[0]; |
| 2825 | F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)BlobStart; |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2826 | break; |
| 2827 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2828 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2829 | case OBJC_CATEGORIES: |
| 2830 | F.ObjCCategories.swap(Record); |
| 2831 | break; |
| 2832 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2833 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2834 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2835 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2836 | return true; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2840 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2841 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2842 | break; |
| 2843 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2844 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2845 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2846 | if (Record.size() % 2 != 0) { |
| 2847 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2848 | return true; |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2849 | } |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2850 | |
| 2851 | if (F.PragmaDiagMappings.empty()) |
| 2852 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2853 | else |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2854 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2855 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2856 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2857 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2858 | case CUDA_SPECIAL_DECL_REFS: |
| 2859 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2860 | // FIXME: Modules will have trouble with this. |
| 2861 | CUDASpecialDeclRefs.clear(); |
| 2862 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2863 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2864 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2865 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2866 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2867 | F.HeaderFileInfoTableData = BlobStart; |
| 2868 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2869 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2870 | if (Record[0]) { |
| 2871 | F.HeaderFileInfoTable |
| 2872 | = HeaderFileInfoLookupTable::Create( |
| 2873 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2874 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2875 | HeaderFileInfoTrait(*this, F, |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2876 | &PP.getHeaderSearchInfo(), |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2877 | BlobStart + Record[2])); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2878 | |
| 2879 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 2880 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 2881 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2882 | } |
| 2883 | break; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2884 | } |
| 2885 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2886 | case FP_PRAGMA_OPTIONS: |
| 2887 | // Later tables overwrite earlier ones. |
| 2888 | FPPragmaOptions.swap(Record); |
| 2889 | break; |
| 2890 | |
| 2891 | case OPENCL_EXTENSIONS: |
| 2892 | // Later tables overwrite earlier ones. |
| 2893 | OpenCLExtensions.swap(Record); |
| 2894 | break; |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2895 | |
| 2896 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2897 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2898 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2899 | break; |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2900 | |
| 2901 | case KNOWN_NAMESPACES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2902 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2903 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2904 | break; |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2905 | |
| 2906 | case IMPORTED_MODULES: { |
| 2907 | if (F.Kind != MK_Module) { |
| 2908 | // If we aren't loading a module (which has its own exports), make |
| 2909 | // all of the imported modules visible. |
| 2910 | // FIXME: Deal with macros-only imports. |
| 2911 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 2912 | if (unsigned GlobalID = getGlobalSubmoduleID(F, Record[I])) |
| 2913 | ImportedModules.push_back(GlobalID); |
| 2914 | } |
| 2915 | } |
| 2916 | break; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2917 | } |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2918 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2919 | case LOCAL_REDECLARATIONS: { |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2920 | F.RedeclarationChains.swap(Record); |
| 2921 | break; |
| 2922 | } |
| 2923 | |
| 2924 | case LOCAL_REDECLARATIONS_MAP: { |
| 2925 | if (F.LocalNumRedeclarationsInMap != 0) { |
| 2926 | Error("duplicate LOCAL_REDECLARATIONS_MAP record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2927 | return true; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2928 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2929 | |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2930 | F.LocalNumRedeclarationsInMap = Record[0]; |
| 2931 | F.RedeclarationsMap = (const LocalRedeclarationsInfo *)BlobStart; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2932 | break; |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2933 | } |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 2934 | |
| 2935 | case MERGED_DECLARATIONS: { |
| 2936 | for (unsigned Idx = 0; Idx < Record.size(); /* increment in loop */) { |
| 2937 | GlobalDeclID CanonID = getGlobalDeclID(F, Record[Idx++]); |
| 2938 | SmallVectorImpl<GlobalDeclID> &Decls = StoredMergedDecls[CanonID]; |
| 2939 | for (unsigned N = Record[Idx++]; N > 0; --N) |
| 2940 | Decls.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2941 | } |
| 2942 | break; |
| 2943 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2944 | |
| 2945 | case MACRO_OFFSET: { |
| 2946 | if (F.LocalNumMacros != 0) { |
| 2947 | Error("duplicate MACRO_OFFSET record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2948 | return true; |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2949 | } |
| 2950 | F.MacroOffsets = (const uint32_t *)BlobStart; |
| 2951 | F.LocalNumMacros = Record[0]; |
| 2952 | unsigned LocalBaseMacroID = Record[1]; |
| 2953 | F.BaseMacroID = getTotalNumMacros(); |
| 2954 | |
| 2955 | if (F.LocalNumMacros > 0) { |
| 2956 | // Introduce the global -> local mapping for macros within this module. |
| 2957 | GlobalMacroMap.insert(std::make_pair(getTotalNumMacros() + 1, &F)); |
| 2958 | |
| 2959 | // Introduce the local -> global mapping for macros within this module. |
| 2960 | F.MacroRemap.insertOrReplace( |
| 2961 | std::make_pair(LocalBaseMacroID, |
| 2962 | F.BaseMacroID - LocalBaseMacroID)); |
| 2963 | |
| 2964 | MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros); |
| 2965 | } |
| 2966 | break; |
| 2967 | } |
| 2968 | |
| 2969 | case MACRO_UPDATES: { |
| 2970 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2971 | MacroID ID = getGlobalMacroID(F, Record[I++]); |
| 2972 | if (I == N) |
| 2973 | break; |
| 2974 | |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 2975 | SourceLocation UndefLoc = ReadSourceLocation(F, Record, I); |
| 2976 | SubmoduleID SubmoduleID = getGlobalSubmoduleID(F, Record[I++]);; |
| 2977 | MacroUpdate Update; |
| 2978 | Update.UndefLoc = UndefLoc; |
| 2979 | MacroUpdates[ID].push_back(std::make_pair(SubmoduleID, Update)); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2980 | } |
| 2981 | break; |
| 2982 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2983 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2984 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2985 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2986 | return true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2987 | } |
| 2988 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2989 | void ASTReader::makeNamesVisible(const HiddenNames &Names) { |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2990 | for (unsigned I = 0, N = Names.size(); I != N; ++I) { |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 2991 | switch (Names[I].getKind()) { |
| 2992 | case HiddenName::Declaration: |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 2993 | Names[I].getDecl()->Hidden = false; |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 2994 | break; |
| 2995 | |
| 2996 | case HiddenName::MacroVisibility: { |
| 2997 | std::pair<IdentifierInfo *, MacroInfo *> Macro = Names[I].getMacro(); |
| 2998 | Macro.second->setHidden(!Macro.second->isPublic()); |
| 2999 | if (Macro.second->isDefined()) { |
| 3000 | PP.makeLoadedMacroInfoVisible(Macro.first, Macro.second); |
| 3001 | } |
| 3002 | break; |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 3005 | case HiddenName::MacroUndef: { |
| 3006 | std::pair<IdentifierInfo *, MacroInfo *> Macro = Names[I].getMacro(); |
| 3007 | if (Macro.second->isDefined()) { |
| 3008 | Macro.second->setUndefLoc(Names[I].getMacroUndefLoc()); |
| 3009 | if (PPMutationListener *Listener = PP.getPPMutationListener()) |
| 3010 | Listener->UndefinedMacro(Macro.second); |
| 3011 | PP.makeLoadedMacroInfoVisible(Macro.first, Macro.second); |
| 3012 | } |
| 3013 | break; |
| 3014 | } |
Douglas Gregor | 1d4c113 | 2011-12-20 22:06:13 +0000 | [diff] [blame] | 3015 | } |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 3016 | } |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 3017 | } |
| 3018 | |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 3019 | void ASTReader::makeModuleVisible(Module *Mod, |
| 3020 | Module::NameVisibilityKind NameVisibility) { |
| 3021 | llvm::SmallPtrSet<Module *, 4> Visited; |
| 3022 | llvm::SmallVector<Module *, 4> Stack; |
| 3023 | Stack.push_back(Mod); |
| 3024 | while (!Stack.empty()) { |
| 3025 | Mod = Stack.back(); |
| 3026 | Stack.pop_back(); |
| 3027 | |
| 3028 | if (NameVisibility <= Mod->NameVisibility) { |
| 3029 | // This module already has this level of visibility (or greater), so |
| 3030 | // there is nothing more to do. |
| 3031 | continue; |
| 3032 | } |
| 3033 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3034 | if (!Mod->isAvailable()) { |
| 3035 | // Modules that aren't available cannot be made visible. |
| 3036 | continue; |
| 3037 | } |
| 3038 | |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 3039 | // Update the module's name visibility. |
| 3040 | Mod->NameVisibility = NameVisibility; |
| 3041 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 3042 | // If we've already deserialized any names from this module, |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 3043 | // mark them as visible. |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 3044 | HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod); |
| 3045 | if (Hidden != HiddenNamesMap.end()) { |
| 3046 | makeNamesVisible(Hidden->second); |
| 3047 | HiddenNamesMap.erase(Hidden); |
| 3048 | } |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 3049 | |
| 3050 | // Push any non-explicit submodules onto the stack to be marked as |
| 3051 | // visible. |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 3052 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 3053 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 3054 | Sub != SubEnd; ++Sub) { |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 3055 | if (!(*Sub)->IsExplicit && Visited.insert(*Sub)) |
| 3056 | Stack.push_back(*Sub); |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 3057 | } |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 3058 | |
| 3059 | // Push any exported modules onto the stack to be marked as visible. |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 3060 | bool AnyWildcard = false; |
| 3061 | bool UnrestrictedWildcard = false; |
| 3062 | llvm::SmallVector<Module *, 4> WildcardRestrictions; |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 3063 | for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { |
| 3064 | Module *Exported = Mod->Exports[I].getPointer(); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 3065 | if (!Mod->Exports[I].getInt()) { |
| 3066 | // Export a named module directly; no wildcards involved. |
| 3067 | if (Visited.insert(Exported)) |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 3068 | Stack.push_back(Exported); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 3069 | |
| 3070 | continue; |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 3071 | } |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 3072 | |
| 3073 | // Wildcard export: export all of the imported modules that match |
| 3074 | // the given pattern. |
| 3075 | AnyWildcard = true; |
| 3076 | if (UnrestrictedWildcard) |
| 3077 | continue; |
| 3078 | |
| 3079 | if (Module *Restriction = Mod->Exports[I].getPointer()) |
| 3080 | WildcardRestrictions.push_back(Restriction); |
| 3081 | else { |
| 3082 | WildcardRestrictions.clear(); |
| 3083 | UnrestrictedWildcard = true; |
| 3084 | } |
| 3085 | } |
| 3086 | |
| 3087 | // If there were any wildcards, push any imported modules that were |
| 3088 | // re-exported by the wildcard restriction. |
| 3089 | if (!AnyWildcard) |
| 3090 | continue; |
| 3091 | |
| 3092 | for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { |
| 3093 | Module *Imported = Mod->Imports[I]; |
Benjamin Kramer | d48bcb2 | 2012-08-22 15:37:55 +0000 | [diff] [blame] | 3094 | if (!Visited.insert(Imported)) |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 3095 | continue; |
| 3096 | |
| 3097 | bool Acceptable = UnrestrictedWildcard; |
| 3098 | if (!Acceptable) { |
| 3099 | // Check whether this module meets one of the restrictions. |
| 3100 | for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) { |
| 3101 | Module *Restriction = WildcardRestrictions[R]; |
| 3102 | if (Imported == Restriction || Imported->isSubModuleOf(Restriction)) { |
| 3103 | Acceptable = true; |
| 3104 | break; |
| 3105 | } |
| 3106 | } |
| 3107 | } |
| 3108 | |
| 3109 | if (!Acceptable) |
| 3110 | continue; |
| 3111 | |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 3112 | Stack.push_back(Imported); |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 3113 | } |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 3114 | } |
| 3115 | } |
| 3116 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 3117 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 3118 | ModuleKind Type, |
| 3119 | unsigned ClientLoadCapabilities) { |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 3120 | // Bump the generation number. |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3121 | unsigned PreviousGeneration = CurrentGeneration++; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3122 | |
| 3123 | // Load the core of the AST files. |
| 3124 | llvm::SmallVector<ModuleFile *, 4> Loaded; |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 3125 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0, Loaded, |
| 3126 | ClientLoadCapabilities)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 3127 | case Failure: return Failure; |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3128 | case OutOfDate: return OutOfDate; |
| 3129 | case VersionMismatch: return VersionMismatch; |
| 3130 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 3131 | case HadErrors: return HadErrors; |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 3132 | case Success: break; |
| 3133 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 3134 | |
| 3135 | // Here comes stuff that we only do once the entire chain is loaded. |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 3136 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3137 | // Load the AST blocks of all of the modules that we loaded. |
| 3138 | for (llvm::SmallVectorImpl<ModuleFile *>::iterator M = Loaded.begin(), |
| 3139 | MEnd = Loaded.end(); |
| 3140 | M != MEnd; ++M) { |
| 3141 | ModuleFile &F = **M; |
| 3142 | |
| 3143 | // Read the AST block. |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3144 | if (ReadASTBlock(F)) |
| 3145 | return Failure; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3146 | |
| 3147 | // Once read, set the ModuleFile bit base offset and update the size in |
| 3148 | // bits of all files we've seen. |
| 3149 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 3150 | TotalModulesSizeInBits += F.SizeInBits; |
| 3151 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
| 3152 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3153 | // Preload SLocEntries. |
| 3154 | for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) { |
| 3155 | int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
Douglas Gregor | 8b53d14 | 2012-10-22 22:53:10 +0000 | [diff] [blame] | 3156 | // Load it through the SourceManager and don't call ReadSLocEntry() |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3157 | // directly because the entry may have already been loaded in which case |
Douglas Gregor | 8b53d14 | 2012-10-22 22:53:10 +0000 | [diff] [blame] | 3158 | // calling ReadSLocEntry() directly would trigger an assertion in |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3159 | // SourceManager. |
| 3160 | SourceMgr.getLoadedSLocEntryByID(Index); |
| 3161 | } |
| 3162 | } |
| 3163 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 3164 | // Check the predefines buffers. |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 3165 | bool ConfigComplain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
Douglas Gregor | 6236a29 | 2011-12-02 21:56:05 +0000 | [diff] [blame] | 3166 | if (!DisableValidation && Type == MK_PCH && |
Argyrios Kyrtzidis | 26d43cd | 2011-09-12 18:09:38 +0000 | [diff] [blame] | 3167 | // FIXME: CheckPredefinesBuffers also sets the SuggestedPredefines; |
| 3168 | // if DisableValidation is true, defines that were set on command-line |
| 3169 | // but not in the PCH file will not be added to SuggestedPredefines. |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 3170 | CheckPredefinesBuffers(ConfigComplain)) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3171 | return ConfigurationMismatch; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 3172 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3173 | // Mark all of the identifiers in the identifier table as being out of date, |
| 3174 | // so that various accessors know to check the loaded modules when the |
| 3175 | // identifier is used. |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 3176 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 3177 | IdEnd = PP.getIdentifierTable().end(); |
| 3178 | Id != IdEnd; ++Id) |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3179 | Id->second->setOutOfDate(true); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 3180 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3181 | // Resolve any unresolved module exports. |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3182 | for (unsigned I = 0, N = UnresolvedModuleImportExports.size(); I != N; ++I) { |
| 3183 | UnresolvedModuleImportExport &Unresolved = UnresolvedModuleImportExports[I]; |
| 3184 | SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 3185 | Module *ResolvedMod = getSubmodule(GlobalID); |
| 3186 | |
| 3187 | if (Unresolved.IsImport) { |
| 3188 | if (ResolvedMod) |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3189 | Unresolved.Mod->Imports.push_back(ResolvedMod); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 3190 | continue; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3191 | } |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 3192 | |
| 3193 | if (ResolvedMod || Unresolved.IsWildcard) |
| 3194 | Unresolved.Mod->Exports.push_back( |
| 3195 | Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard)); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3196 | } |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3197 | UnresolvedModuleImportExports.clear(); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3198 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3199 | InitializeContext(); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 3200 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3201 | if (DeserializationListener) |
| 3202 | DeserializationListener->ReaderInitialized(this); |
| 3203 | |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 3204 | ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule(); |
| 3205 | if (!PrimaryModule.OriginalSourceFileID.isInvalid()) { |
| 3206 | PrimaryModule.OriginalSourceFileID |
| 3207 | = FileID::get(PrimaryModule.SLocEntryBaseID |
| 3208 | + PrimaryModule.OriginalSourceFileID.getOpaqueValue() - 1); |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 3209 | |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 3210 | // If this AST file is a precompiled preamble, then set the |
| 3211 | // preamble file ID of the source manager to the file source file |
| 3212 | // from which the preamble was built. |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 3213 | if (Type == MK_Preamble) { |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 3214 | SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID); |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 3215 | } else if (Type == MK_MainFile) { |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 3216 | SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3217 | } |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3220 | // For any Objective-C class definitions we have already loaded, make sure |
| 3221 | // that we load any additional categories. |
| 3222 | for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { |
| 3223 | loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), |
| 3224 | ObjCClassesLoaded[I], |
| 3225 | PreviousGeneration); |
| 3226 | } |
| 3227 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 3228 | return Success; |
| 3229 | } |
| 3230 | |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 3231 | ASTReader::ASTReadResult |
| 3232 | ASTReader::ReadASTCore(StringRef FileName, |
| 3233 | ModuleKind Type, |
| 3234 | ModuleFile *ImportedBy, |
| 3235 | llvm::SmallVectorImpl<ModuleFile *> &Loaded, |
| 3236 | unsigned ClientLoadCapabilities) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3237 | ModuleFile *M; |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 3238 | bool NewModule; |
| 3239 | std::string ErrorStr; |
| 3240 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 3241 | CurrentGeneration, ErrorStr); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 3242 | |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 3243 | if (!M) { |
| 3244 | // We couldn't load the module. |
| 3245 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 3246 | + ErrorStr; |
| 3247 | Error(Msg); |
| 3248 | return Failure; |
| 3249 | } |
| 3250 | |
| 3251 | if (!NewModule) { |
| 3252 | // We've already loaded this module. |
| 3253 | return Success; |
| 3254 | } |
| 3255 | |
| 3256 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 3257 | // module? |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 3258 | if (FileName != "-") { |
| 3259 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 3260 | if (CurrentDir.empty()) CurrentDir = "."; |
| 3261 | } |
| 3262 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3263 | ModuleFile &F = *M; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3264 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 3265 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 3266 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3267 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 3268 | // Sniff for the signature. |
| 3269 | if (Stream.Read(8) != 'C' || |
| 3270 | Stream.Read(8) != 'P' || |
| 3271 | Stream.Read(8) != 'C' || |
| 3272 | Stream.Read(8) != 'H') { |
| 3273 | Diag(diag::err_not_a_pch_file) << FileName; |
| 3274 | return Failure; |
| 3275 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3276 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3277 | while (!Stream.AtEndOfStream()) { |
| 3278 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3279 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 3280 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3281 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 3282 | return Failure; |
| 3283 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3284 | |
| 3285 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3286 | |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 3287 | // We only know the control subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3288 | switch (BlockID) { |
| 3289 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 3290 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3291 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 3292 | return Failure; |
| 3293 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3294 | break; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3295 | case CONTROL_BLOCK_ID: |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 3296 | switch (ReadControlBlock(F, Loaded, ClientLoadCapabilities)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3297 | case Success: |
| 3298 | break; |
| 3299 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3300 | case Failure: return Failure; |
| 3301 | case OutOfDate: return OutOfDate; |
| 3302 | case VersionMismatch: return VersionMismatch; |
| 3303 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 3304 | case HadErrors: return HadErrors; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3305 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3306 | break; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3307 | case AST_BLOCK_ID: |
| 3308 | // Record that we've loaded this module. |
| 3309 | Loaded.push_back(M); |
| 3310 | return Success; |
| 3311 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3312 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 3313 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3314 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 3315 | return Failure; |
| 3316 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3317 | break; |
| 3318 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3319 | } |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3320 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 3321 | return Success; |
| 3322 | } |
| 3323 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 3324 | void ASTReader::InitializeContext() { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3325 | // If there's a listener, notify them that we "read" the translation unit. |
| 3326 | if (DeserializationListener) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3327 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 3328 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 3329 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3330 | // Make sure we load the declaration update records for the translation unit, |
| 3331 | // if there are any. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3332 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 3333 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3334 | |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 3335 | // FIXME: Find a better way to deal with collisions between these |
| 3336 | // built-in types. Right now, we just ignore the problem. |
| 3337 | |
| 3338 | // Load the special types. |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 3339 | if (SpecialTypes.size() >= NumSpecialTypeIDs) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 3340 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 3341 | if (!Context.CFConstantStringTypeDecl) |
| 3342 | Context.setCFConstantStringType(GetType(String)); |
| 3343 | } |
| 3344 | |
| 3345 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 3346 | QualType FileType = GetType(File); |
| 3347 | if (FileType.isNull()) { |
| 3348 | Error("FILE type is NULL"); |
| 3349 | return; |
| 3350 | } |
| 3351 | |
| 3352 | if (!Context.FILEDecl) { |
| 3353 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 3354 | Context.setFILEDecl(Typedef->getDecl()); |
| 3355 | else { |
| 3356 | const TagType *Tag = FileType->getAs<TagType>(); |
| 3357 | if (!Tag) { |
| 3358 | Error("Invalid FILE type in AST file"); |
| 3359 | return; |
| 3360 | } |
| 3361 | Context.setFILEDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3362 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3363 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 3364 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 3365 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 3366 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 3367 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 3368 | if (Jmp_bufType.isNull()) { |
| 3369 | Error("jmp_buf type is NULL"); |
| 3370 | return; |
| 3371 | } |
| 3372 | |
| 3373 | if (!Context.jmp_bufDecl) { |
| 3374 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 3375 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 3376 | else { |
| 3377 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 3378 | if (!Tag) { |
| 3379 | Error("Invalid jmp_buf type in AST file"); |
| 3380 | return; |
| 3381 | } |
| 3382 | Context.setjmp_bufDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3383 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3384 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 3385 | } |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 3386 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 3387 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 3388 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 3389 | if (Sigjmp_bufType.isNull()) { |
| 3390 | Error("sigjmp_buf type is NULL"); |
| 3391 | return; |
| 3392 | } |
| 3393 | |
| 3394 | if (!Context.sigjmp_bufDecl) { |
| 3395 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 3396 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 3397 | else { |
| 3398 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 3399 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 3400 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 3401 | } |
| 3402 | } |
| 3403 | } |
| 3404 | |
| 3405 | if (unsigned ObjCIdRedef |
| 3406 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 3407 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 3408 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 3409 | } |
| 3410 | |
| 3411 | if (unsigned ObjCClassRedef |
| 3412 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 3413 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 3414 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 3415 | } |
| 3416 | |
| 3417 | if (unsigned ObjCSelRedef |
| 3418 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 3419 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 3420 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 3421 | } |
Rafael Espindola | e2d4f4e | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 3422 | |
| 3423 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 3424 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 3425 | if (Ucontext_tType.isNull()) { |
| 3426 | Error("ucontext_t type is NULL"); |
| 3427 | return; |
| 3428 | } |
| 3429 | |
| 3430 | if (!Context.ucontext_tDecl) { |
| 3431 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| 3432 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 3433 | else { |
| 3434 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| 3435 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 3436 | Context.setucontext_tDecl(Tag->getDecl()); |
| 3437 | } |
| 3438 | } |
| 3439 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 3440 | } |
| 3441 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3442 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3443 | |
| 3444 | // If there were any CUDA special declarations, deserialize them. |
| 3445 | if (!CUDASpecialDeclRefs.empty()) { |
| 3446 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3447 | Context.setcudaConfigureCallDecl( |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3448 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 3449 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 3450 | |
| 3451 | // Re-export any modules that were imported by a non-module AST file. |
| 3452 | for (unsigned I = 0, N = ImportedModules.size(); I != N; ++I) { |
| 3453 | if (Module *Imported = getSubmodule(ImportedModules[I])) |
| 3454 | makeModuleVisible(Imported, Module::AllVisible); |
| 3455 | } |
| 3456 | ImportedModules.clear(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3457 | } |
| 3458 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 3459 | void ASTReader::finalizeForWriting() { |
| 3460 | for (HiddenNamesMapType::iterator Hidden = HiddenNamesMap.begin(), |
| 3461 | HiddenEnd = HiddenNamesMap.end(); |
| 3462 | Hidden != HiddenEnd; ++Hidden) { |
| 3463 | makeNamesVisible(Hidden->second); |
| 3464 | } |
| 3465 | HiddenNamesMap.clear(); |
| 3466 | } |
| 3467 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3468 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3469 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3470 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3471 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 3472 | FileManager &FileMgr, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 3473 | DiagnosticsEngine &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3474 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3475 | std::string ErrStr; |
Dylan Noblesmith | 6f42b62 | 2012-02-05 02:12:40 +0000 | [diff] [blame] | 3476 | OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 3477 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3478 | if (!Buffer) { |
Kaelyn Uhrain | da01f62 | 2012-06-20 00:36:03 +0000 | [diff] [blame] | 3479 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ASTFileName << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3480 | return std::string(); |
| 3481 | } |
| 3482 | |
| 3483 | // Initialize the stream |
| 3484 | llvm::BitstreamReader StreamFile; |
| 3485 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3486 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3487 | (const unsigned char *)Buffer->getBufferEnd()); |
| 3488 | Stream.init(StreamFile); |
| 3489 | |
| 3490 | // Sniff for the signature. |
| 3491 | if (Stream.Read(8) != 'C' || |
| 3492 | Stream.Read(8) != 'P' || |
| 3493 | Stream.Read(8) != 'C' || |
| 3494 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3495 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3496 | return std::string(); |
| 3497 | } |
| 3498 | |
| 3499 | RecordData Record; |
| 3500 | while (!Stream.AtEndOfStream()) { |
| 3501 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3502 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3503 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3504 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3505 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3506 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3507 | switch (BlockID) { |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3508 | case CONTROL_BLOCK_ID: |
| 3509 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3510 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3511 | return std::string(); |
| 3512 | } |
| 3513 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3514 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3515 | default: |
| 3516 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3517 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3518 | return std::string(); |
| 3519 | } |
| 3520 | break; |
| 3521 | } |
| 3522 | continue; |
| 3523 | } |
| 3524 | |
| 3525 | if (Code == llvm::bitc::END_BLOCK) { |
| 3526 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3527 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3528 | return std::string(); |
| 3529 | } |
| 3530 | continue; |
| 3531 | } |
| 3532 | |
| 3533 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3534 | Stream.ReadAbbrevRecord(); |
| 3535 | continue; |
| 3536 | } |
| 3537 | |
| 3538 | Record.clear(); |
| 3539 | const char *BlobStart = 0; |
| 3540 | unsigned BlobLen = 0; |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 3541 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) == ORIGINAL_FILE) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3542 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3543 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3544 | |
| 3545 | return std::string(); |
| 3546 | } |
| 3547 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3548 | namespace { |
| 3549 | class SimplePCHValidator : public ASTReaderListener { |
| 3550 | const LangOptions &ExistingLangOpts; |
| 3551 | const TargetOptions &ExistingTargetOpts; |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3552 | const PreprocessorOptions &ExistingPPOpts; |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 3553 | FileManager &FileMgr; |
| 3554 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3555 | public: |
| 3556 | SimplePCHValidator(const LangOptions &ExistingLangOpts, |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3557 | const TargetOptions &ExistingTargetOpts, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 3558 | const PreprocessorOptions &ExistingPPOpts, |
| 3559 | FileManager &FileMgr) |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3560 | : ExistingLangOpts(ExistingLangOpts), |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3561 | ExistingTargetOpts(ExistingTargetOpts), |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 3562 | ExistingPPOpts(ExistingPPOpts), |
| 3563 | FileMgr(FileMgr) |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3564 | { |
| 3565 | } |
| 3566 | |
| 3567 | virtual bool ReadLanguageOptions(const LangOptions &LangOpts, |
| 3568 | bool Complain) { |
| 3569 | return checkLanguageOptions(ExistingLangOpts, LangOpts, 0); |
| 3570 | } |
| 3571 | virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, |
| 3572 | bool Complain) { |
| 3573 | return checkTargetOptions(ExistingTargetOpts, TargetOpts, 0); |
| 3574 | } |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3575 | virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 3576 | bool Complain, |
| 3577 | std::string &SuggestedPredefines) { |
| 3578 | return checkPreprocessorOptions(ExistingPPOpts, PPOpts, 0, FileMgr, |
| 3579 | SuggestedPredefines); |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3580 | } |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3581 | }; |
| 3582 | } |
| 3583 | |
| 3584 | bool ASTReader::isAcceptableASTFile(StringRef Filename, |
| 3585 | FileManager &FileMgr, |
| 3586 | const LangOptions &LangOpts, |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3587 | const TargetOptions &TargetOpts, |
| 3588 | const PreprocessorOptions &PPOpts) { |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3589 | // Open the AST file. |
| 3590 | std::string ErrStr; |
| 3591 | OwningPtr<llvm::MemoryBuffer> Buffer; |
| 3592 | Buffer.reset(FileMgr.getBufferForFile(Filename, &ErrStr)); |
| 3593 | if (!Buffer) { |
| 3594 | return false; |
| 3595 | } |
| 3596 | |
| 3597 | // Initialize the stream |
| 3598 | llvm::BitstreamReader StreamFile; |
| 3599 | llvm::BitstreamCursor Stream; |
| 3600 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
| 3601 | (const unsigned char *)Buffer->getBufferEnd()); |
| 3602 | Stream.init(StreamFile); |
| 3603 | |
| 3604 | // Sniff for the signature. |
| 3605 | if (Stream.Read(8) != 'C' || |
| 3606 | Stream.Read(8) != 'P' || |
| 3607 | Stream.Read(8) != 'C' || |
| 3608 | Stream.Read(8) != 'H') { |
| 3609 | return false; |
| 3610 | } |
| 3611 | |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 3612 | SimplePCHValidator Validator(LangOpts, TargetOpts, PPOpts, FileMgr); |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3613 | RecordData Record; |
| 3614 | bool InControlBlock = false; |
| 3615 | while (!Stream.AtEndOfStream()) { |
| 3616 | unsigned Code = Stream.ReadCode(); |
| 3617 | |
| 3618 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3619 | unsigned BlockID = Stream.ReadSubBlockID(); |
| 3620 | |
| 3621 | // We only know the control subblock ID. |
| 3622 | switch (BlockID) { |
| 3623 | case CONTROL_BLOCK_ID: |
| 3624 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
| 3625 | return false; |
| 3626 | } else { |
| 3627 | InControlBlock = true; |
| 3628 | } |
| 3629 | break; |
| 3630 | |
| 3631 | default: |
| 3632 | if (Stream.SkipBlock()) |
| 3633 | return false; |
| 3634 | break; |
| 3635 | } |
| 3636 | continue; |
| 3637 | } |
| 3638 | |
| 3639 | if (Code == llvm::bitc::END_BLOCK) { |
| 3640 | if (Stream.ReadBlockEnd()) { |
| 3641 | return false; |
| 3642 | } |
| 3643 | InControlBlock = false; |
| 3644 | continue; |
| 3645 | } |
| 3646 | |
| 3647 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3648 | Stream.ReadAbbrevRecord(); |
| 3649 | continue; |
| 3650 | } |
| 3651 | |
| 3652 | Record.clear(); |
| 3653 | const char *BlobStart = 0; |
| 3654 | unsigned BlobLen = 0; |
| 3655 | unsigned RecCode = Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
| 3656 | if (InControlBlock) { |
| 3657 | switch ((ControlRecordTypes)RecCode) { |
| 3658 | case METADATA: { |
| 3659 | if (Record[0] != VERSION_MAJOR) { |
| 3660 | return false; |
| 3661 | } |
| 3662 | |
| 3663 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
| 3664 | StringRef ASTBranch(BlobStart, BlobLen); |
| 3665 | if (StringRef(CurBranch) != ASTBranch) |
| 3666 | return false; |
| 3667 | |
| 3668 | break; |
| 3669 | } |
| 3670 | case LANGUAGE_OPTIONS: |
| 3671 | if (ParseLanguageOptions(Record, false, Validator)) |
| 3672 | return false; |
| 3673 | break; |
| 3674 | |
| 3675 | case TARGET_OPTIONS: |
| 3676 | if (ParseTargetOptions(Record, false, Validator)) |
| 3677 | return false; |
| 3678 | break; |
| 3679 | |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 3680 | case DIAGNOSTIC_OPTIONS: |
| 3681 | if (ParseDiagnosticOptions(Record, false, Validator)) |
| 3682 | return false; |
| 3683 | break; |
| 3684 | |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 3685 | case FILE_SYSTEM_OPTIONS: |
| 3686 | if (ParseFileSystemOptions(Record, false, Validator)) |
| 3687 | return false; |
| 3688 | break; |
| 3689 | |
| 3690 | case HEADER_SEARCH_OPTIONS: |
| 3691 | if (ParseHeaderSearchOptions(Record, false, Validator)) |
| 3692 | return false; |
| 3693 | break; |
| 3694 | |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 3695 | case PREPROCESSOR_OPTIONS: { |
| 3696 | std::string IgnoredSuggestedPredefines; |
| 3697 | if (ParsePreprocessorOptions(Record, false, Validator, |
| 3698 | IgnoredSuggestedPredefines)) |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3699 | return false; |
| 3700 | break; |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 3701 | } |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3702 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3703 | default: |
| 3704 | // No other validation to perform. |
| 3705 | break; |
| 3706 | } |
| 3707 | } |
| 3708 | } |
| 3709 | |
| 3710 | return true; |
| 3711 | } |
| 3712 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3713 | bool ASTReader::ReadSubmoduleBlock(ModuleFile &F) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3714 | // Enter the submodule block. |
| 3715 | if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) { |
| 3716 | Error("malformed submodule block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3717 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3718 | } |
| 3719 | |
| 3720 | ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3721 | bool First = true; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3722 | Module *CurrentModule = 0; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3723 | RecordData Record; |
| 3724 | while (true) { |
| 3725 | unsigned Code = F.Stream.ReadCode(); |
| 3726 | if (Code == llvm::bitc::END_BLOCK) { |
| 3727 | if (F.Stream.ReadBlockEnd()) { |
| 3728 | Error("error at end of submodule block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3729 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3730 | } |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3731 | return false; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3735 | // No known subblocks, always skip them. |
| 3736 | F.Stream.ReadSubBlockID(); |
| 3737 | if (F.Stream.SkipBlock()) { |
| 3738 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3739 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3740 | } |
| 3741 | continue; |
| 3742 | } |
| 3743 | |
| 3744 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3745 | F.Stream.ReadAbbrevRecord(); |
| 3746 | continue; |
| 3747 | } |
| 3748 | |
| 3749 | // Read a record. |
| 3750 | const char *BlobStart; |
| 3751 | unsigned BlobLen; |
| 3752 | Record.clear(); |
| 3753 | switch (F.Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 3754 | default: // Default behavior: ignore. |
| 3755 | break; |
| 3756 | |
| 3757 | case SUBMODULE_DEFINITION: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3758 | if (First) { |
| 3759 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3760 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3761 | } |
| 3762 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3763 | if (Record.size() < 7) { |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3764 | Error("malformed module definition"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3765 | return true; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3766 | } |
| 3767 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3768 | StringRef Name(BlobStart, BlobLen); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3769 | SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[0]); |
| 3770 | SubmoduleID Parent = getGlobalSubmoduleID(F, Record[1]); |
| 3771 | bool IsFramework = Record[2]; |
| 3772 | bool IsExplicit = Record[3]; |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 3773 | bool IsSystem = Record[4]; |
| 3774 | bool InferSubmodules = Record[5]; |
| 3775 | bool InferExplicitSubmodules = Record[6]; |
| 3776 | bool InferExportWildcard = Record[7]; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3777 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3778 | Module *ParentModule = 0; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3779 | if (Parent) |
| 3780 | ParentModule = getSubmodule(Parent); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3781 | |
| 3782 | // Retrieve this (sub)module from the module map, creating it if |
| 3783 | // necessary. |
| 3784 | CurrentModule = ModMap.findOrCreateModule(Name, ParentModule, |
| 3785 | IsFramework, |
| 3786 | IsExplicit).first; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3787 | SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS; |
| 3788 | if (GlobalIndex >= SubmodulesLoaded.size() || |
| 3789 | SubmodulesLoaded[GlobalIndex]) { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3790 | Error("too many submodules"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3791 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3792 | } |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3793 | |
Argyrios Kyrtzidis | d64c26f | 2012-10-03 01:58:42 +0000 | [diff] [blame] | 3794 | CurrentModule->setASTFile(F.File); |
Douglas Gregor | 305dc3e | 2011-12-20 00:28:52 +0000 | [diff] [blame] | 3795 | CurrentModule->IsFromModuleFile = true; |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 3796 | CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3797 | CurrentModule->InferSubmodules = InferSubmodules; |
| 3798 | CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; |
| 3799 | CurrentModule->InferExportWildcard = InferExportWildcard; |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3800 | if (DeserializationListener) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3801 | DeserializationListener->ModuleRead(GlobalID, CurrentModule); |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3802 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3803 | SubmodulesLoaded[GlobalIndex] = CurrentModule; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3804 | break; |
| 3805 | } |
| 3806 | |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3807 | case SUBMODULE_UMBRELLA_HEADER: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3808 | if (First) { |
| 3809 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3810 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3811 | } |
| 3812 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3813 | if (!CurrentModule) |
| 3814 | break; |
| 3815 | |
| 3816 | StringRef FileName(BlobStart, BlobLen); |
| 3817 | if (const FileEntry *Umbrella = PP.getFileManager().getFile(FileName)) { |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 3818 | if (!CurrentModule->getUmbrellaHeader()) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3819 | ModMap.setUmbrellaHeader(CurrentModule, Umbrella); |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 3820 | else if (CurrentModule->getUmbrellaHeader() != Umbrella) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3821 | Error("mismatched umbrella headers in submodule"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3822 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3823 | } |
| 3824 | } |
| 3825 | break; |
| 3826 | } |
| 3827 | |
| 3828 | case SUBMODULE_HEADER: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3829 | if (First) { |
| 3830 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3831 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3834 | if (!CurrentModule) |
| 3835 | break; |
| 3836 | |
| 3837 | // FIXME: Be more lazy about this! |
| 3838 | StringRef FileName(BlobStart, BlobLen); |
| 3839 | if (const FileEntry *File = PP.getFileManager().getFile(FileName)) { |
| 3840 | if (std::find(CurrentModule->Headers.begin(), |
| 3841 | CurrentModule->Headers.end(), |
| 3842 | File) == CurrentModule->Headers.end()) |
Douglas Gregor | 2b49d1f | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 3843 | ModMap.addHeader(CurrentModule, File, false); |
| 3844 | } |
| 3845 | break; |
| 3846 | } |
| 3847 | |
| 3848 | case SUBMODULE_EXCLUDED_HEADER: { |
| 3849 | if (First) { |
| 3850 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3851 | return true; |
Douglas Gregor | 2b49d1f | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 3852 | } |
| 3853 | |
| 3854 | if (!CurrentModule) |
| 3855 | break; |
| 3856 | |
| 3857 | // FIXME: Be more lazy about this! |
| 3858 | StringRef FileName(BlobStart, BlobLen); |
| 3859 | if (const FileEntry *File = PP.getFileManager().getFile(FileName)) { |
| 3860 | if (std::find(CurrentModule->Headers.begin(), |
| 3861 | CurrentModule->Headers.end(), |
| 3862 | File) == CurrentModule->Headers.end()) |
| 3863 | ModMap.addHeader(CurrentModule, File, true); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3864 | } |
| 3865 | break; |
| 3866 | } |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 3867 | |
| 3868 | case SUBMODULE_TOPHEADER: { |
| 3869 | if (First) { |
| 3870 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3871 | return true; |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | if (!CurrentModule) |
| 3875 | break; |
| 3876 | |
| 3877 | // FIXME: Be more lazy about this! |
| 3878 | StringRef FileName(BlobStart, BlobLen); |
| 3879 | if (const FileEntry *File = PP.getFileManager().getFile(FileName)) |
| 3880 | CurrentModule->TopHeaders.insert(File); |
| 3881 | break; |
| 3882 | } |
| 3883 | |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3884 | case SUBMODULE_UMBRELLA_DIR: { |
| 3885 | if (First) { |
| 3886 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3887 | return true; |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3888 | } |
| 3889 | |
| 3890 | if (!CurrentModule) |
| 3891 | break; |
| 3892 | |
| 3893 | StringRef DirName(BlobStart, BlobLen); |
| 3894 | if (const DirectoryEntry *Umbrella |
| 3895 | = PP.getFileManager().getDirectory(DirName)) { |
| 3896 | if (!CurrentModule->getUmbrellaDir()) |
| 3897 | ModMap.setUmbrellaDir(CurrentModule, Umbrella); |
| 3898 | else if (CurrentModule->getUmbrellaDir() != Umbrella) { |
| 3899 | Error("mismatched umbrella directories in submodule"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3900 | return true; |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3901 | } |
| 3902 | } |
| 3903 | break; |
| 3904 | } |
| 3905 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3906 | case SUBMODULE_METADATA: { |
| 3907 | if (!First) { |
| 3908 | Error("submodule metadata record not at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3909 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3910 | } |
| 3911 | First = false; |
| 3912 | |
| 3913 | F.BaseSubmoduleID = getTotalNumSubmodules(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3914 | F.LocalNumSubmodules = Record[0]; |
| 3915 | unsigned LocalBaseSubmoduleID = Record[1]; |
| 3916 | if (F.LocalNumSubmodules > 0) { |
| 3917 | // Introduce the global -> local mapping for submodules within this |
| 3918 | // module. |
| 3919 | GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F)); |
| 3920 | |
| 3921 | // Introduce the local -> global mapping for submodules within this |
| 3922 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 3923 | F.SubmoduleRemap.insertOrReplace( |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3924 | std::make_pair(LocalBaseSubmoduleID, |
| 3925 | F.BaseSubmoduleID - LocalBaseSubmoduleID)); |
| 3926 | |
| 3927 | SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules); |
| 3928 | } |
| 3929 | break; |
| 3930 | } |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3931 | |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3932 | case SUBMODULE_IMPORTS: { |
| 3933 | if (First) { |
| 3934 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3935 | return true; |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3936 | } |
| 3937 | |
| 3938 | if (!CurrentModule) |
| 3939 | break; |
| 3940 | |
| 3941 | for (unsigned Idx = 0; Idx != Record.size(); ++Idx) { |
| 3942 | UnresolvedModuleImportExport Unresolved; |
| 3943 | Unresolved.File = &F; |
| 3944 | Unresolved.Mod = CurrentModule; |
| 3945 | Unresolved.ID = Record[Idx]; |
| 3946 | Unresolved.IsImport = true; |
| 3947 | Unresolved.IsWildcard = false; |
| 3948 | UnresolvedModuleImportExports.push_back(Unresolved); |
| 3949 | } |
| 3950 | break; |
| 3951 | } |
| 3952 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3953 | case SUBMODULE_EXPORTS: { |
| 3954 | if (First) { |
| 3955 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3956 | return true; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | if (!CurrentModule) |
| 3960 | break; |
| 3961 | |
| 3962 | for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3963 | UnresolvedModuleImportExport Unresolved; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3964 | Unresolved.File = &F; |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3965 | Unresolved.Mod = CurrentModule; |
| 3966 | Unresolved.ID = Record[Idx]; |
| 3967 | Unresolved.IsImport = false; |
| 3968 | Unresolved.IsWildcard = Record[Idx + 1]; |
| 3969 | UnresolvedModuleImportExports.push_back(Unresolved); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | // Once we've loaded the set of exports, there's no reason to keep |
| 3973 | // the parsed, unresolved exports around. |
| 3974 | CurrentModule->UnresolvedExports.clear(); |
| 3975 | break; |
| 3976 | } |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3977 | case SUBMODULE_REQUIRES: { |
| 3978 | if (First) { |
| 3979 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3980 | return true; |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | if (!CurrentModule) |
| 3984 | break; |
| 3985 | |
| 3986 | CurrentModule->addRequirement(StringRef(BlobStart, BlobLen), |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3987 | Context.getLangOpts(), |
Douglas Gregor | dc58aa7 | 2012-01-30 06:01:29 +0000 | [diff] [blame] | 3988 | Context.getTargetInfo()); |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3989 | break; |
| 3990 | } |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3991 | } |
| 3992 | } |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3993 | } |
| 3994 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3995 | /// \brief Parse the record that corresponds to a LangOptions data |
| 3996 | /// structure. |
| 3997 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3998 | /// This routine parses the language options from the AST file and then gives |
| 3999 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4000 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4001 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 4002 | bool ASTReader::ParseLanguageOptions(const RecordData &Record, |
| 4003 | bool Complain, |
| 4004 | ASTReaderListener &Listener) { |
| 4005 | LangOptions LangOpts; |
| 4006 | unsigned Idx = 0; |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 4007 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 4008 | LangOpts.Name = Record[Idx++]; |
| 4009 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 4010 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 4011 | #include "clang/Basic/LangOptions.def" |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 4012 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 4013 | ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++]; |
| 4014 | VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx); |
| 4015 | LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion); |
| 4016 | |
| 4017 | unsigned Length = Record[Idx++]; |
| 4018 | LangOpts.CurrentModule.assign(Record.begin() + Idx, |
| 4019 | Record.begin() + Idx + Length); |
| 4020 | return Listener.ReadLanguageOptions(LangOpts, Complain); |
| 4021 | } |
| 4022 | |
| 4023 | bool ASTReader::ParseTargetOptions(const RecordData &Record, |
| 4024 | bool Complain, |
| 4025 | ASTReaderListener &Listener) { |
| 4026 | unsigned Idx = 0; |
| 4027 | TargetOptions TargetOpts; |
| 4028 | TargetOpts.Triple = ReadString(Record, Idx); |
| 4029 | TargetOpts.CPU = ReadString(Record, Idx); |
| 4030 | TargetOpts.ABI = ReadString(Record, Idx); |
| 4031 | TargetOpts.CXXABI = ReadString(Record, Idx); |
| 4032 | TargetOpts.LinkerVersion = ReadString(Record, Idx); |
| 4033 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4034 | TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx)); |
| 4035 | } |
| 4036 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4037 | TargetOpts.Features.push_back(ReadString(Record, Idx)); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4038 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4039 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 4040 | return Listener.ReadTargetOptions(TargetOpts, Complain); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4041 | } |
| 4042 | |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 4043 | bool ASTReader::ParseDiagnosticOptions(const RecordData &Record, bool Complain, |
| 4044 | ASTReaderListener &Listener) { |
| 4045 | DiagnosticOptions DiagOpts; |
| 4046 | unsigned Idx = 0; |
| 4047 | #define DIAGOPT(Name, Bits, Default) DiagOpts.Name = Record[Idx++]; |
| 4048 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 4049 | DiagOpts.set##Name(static_cast<Type>(Record[Idx++])); |
| 4050 | #include "clang/Basic/DiagnosticOptions.def" |
| 4051 | |
| 4052 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4053 | DiagOpts.Warnings.push_back(ReadString(Record, Idx)); |
| 4054 | } |
| 4055 | |
| 4056 | return Listener.ReadDiagnosticOptions(DiagOpts, Complain); |
| 4057 | } |
| 4058 | |
Douglas Gregor | 1b2c3c0 | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 4059 | bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain, |
| 4060 | ASTReaderListener &Listener) { |
| 4061 | FileSystemOptions FSOpts; |
| 4062 | unsigned Idx = 0; |
| 4063 | FSOpts.WorkingDir = ReadString(Record, Idx); |
| 4064 | return Listener.ReadFileSystemOptions(FSOpts, Complain); |
| 4065 | } |
| 4066 | |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 4067 | bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record, |
| 4068 | bool Complain, |
| 4069 | ASTReaderListener &Listener) { |
| 4070 | HeaderSearchOptions HSOpts; |
| 4071 | unsigned Idx = 0; |
| 4072 | HSOpts.Sysroot = ReadString(Record, Idx); |
| 4073 | |
| 4074 | // Include entries. |
| 4075 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4076 | std::string Path = ReadString(Record, Idx); |
| 4077 | frontend::IncludeDirGroup Group |
| 4078 | = static_cast<frontend::IncludeDirGroup>(Record[Idx++]); |
| 4079 | bool IsUserSupplied = Record[Idx++]; |
| 4080 | bool IsFramework = Record[Idx++]; |
| 4081 | bool IgnoreSysRoot = Record[Idx++]; |
| 4082 | bool IsInternal = Record[Idx++]; |
| 4083 | bool ImplicitExternC = Record[Idx++]; |
| 4084 | HSOpts.UserEntries.push_back( |
| 4085 | HeaderSearchOptions::Entry(Path, Group, IsUserSupplied, IsFramework, |
| 4086 | IgnoreSysRoot, IsInternal, ImplicitExternC)); |
| 4087 | } |
| 4088 | |
| 4089 | // System header prefixes. |
| 4090 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4091 | std::string Prefix = ReadString(Record, Idx); |
| 4092 | bool IsSystemHeader = Record[Idx++]; |
| 4093 | HSOpts.SystemHeaderPrefixes.push_back( |
| 4094 | HeaderSearchOptions::SystemHeaderPrefix(Prefix, IsSystemHeader)); |
| 4095 | } |
| 4096 | |
| 4097 | HSOpts.ResourceDir = ReadString(Record, Idx); |
| 4098 | HSOpts.ModuleCachePath = ReadString(Record, Idx); |
| 4099 | HSOpts.DisableModuleHash = Record[Idx++]; |
| 4100 | HSOpts.UseBuiltinIncludes = Record[Idx++]; |
| 4101 | HSOpts.UseStandardSystemIncludes = Record[Idx++]; |
| 4102 | HSOpts.UseStandardCXXIncludes = Record[Idx++]; |
| 4103 | HSOpts.UseLibcxx = Record[Idx++]; |
| 4104 | |
| 4105 | return Listener.ReadHeaderSearchOptions(HSOpts, Complain); |
| 4106 | } |
| 4107 | |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 4108 | bool ASTReader::ParsePreprocessorOptions(const RecordData &Record, |
| 4109 | bool Complain, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 4110 | ASTReaderListener &Listener, |
| 4111 | std::string &SuggestedPredefines) { |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 4112 | PreprocessorOptions PPOpts; |
| 4113 | unsigned Idx = 0; |
| 4114 | |
| 4115 | // Macro definitions/undefs |
| 4116 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4117 | std::string Macro = ReadString(Record, Idx); |
| 4118 | bool IsUndef = Record[Idx++]; |
| 4119 | PPOpts.Macros.push_back(std::make_pair(Macro, IsUndef)); |
| 4120 | } |
| 4121 | |
| 4122 | // Includes |
| 4123 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4124 | PPOpts.Includes.push_back(ReadString(Record, Idx)); |
| 4125 | } |
| 4126 | |
| 4127 | // Macro Includes |
| 4128 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4129 | PPOpts.MacroIncludes.push_back(ReadString(Record, Idx)); |
| 4130 | } |
| 4131 | |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 4132 | PPOpts.UsePredefines = Record[Idx++]; |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 4133 | PPOpts.ImplicitPCHInclude = ReadString(Record, Idx); |
| 4134 | PPOpts.ImplicitPTHInclude = ReadString(Record, Idx); |
| 4135 | PPOpts.ObjCXXARCStandardLibrary = |
| 4136 | static_cast<ObjCXXARCStandardLibraryKind>(Record[Idx++]); |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame^] | 4137 | SuggestedPredefines.clear(); |
| 4138 | return Listener.ReadPreprocessorOptions(PPOpts, Complain, |
| 4139 | SuggestedPredefines); |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 4140 | } |
| 4141 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4142 | std::pair<ModuleFile *, unsigned> |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 4143 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 4144 | GlobalPreprocessedEntityMapType::iterator |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 4145 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 4146 | assert(I != GlobalPreprocessedEntityMap.end() && |
| 4147 | "Corrupted global preprocessed entity map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4148 | ModuleFile *M = I->second; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 4149 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 4150 | return std::make_pair(M, LocalIndex); |
| 4151 | } |
| 4152 | |
Argyrios Kyrtzidis | 632dcc9 | 2012-10-02 16:10:51 +0000 | [diff] [blame] | 4153 | std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator> |
| 4154 | ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const { |
| 4155 | if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord()) |
| 4156 | return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID, |
| 4157 | Mod.NumPreprocessedEntities); |
| 4158 | |
| 4159 | return std::make_pair(PreprocessingRecord::iterator(), |
| 4160 | PreprocessingRecord::iterator()); |
| 4161 | } |
| 4162 | |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 4163 | std::pair<ASTReader::ModuleDeclIterator, ASTReader::ModuleDeclIterator> |
| 4164 | ASTReader::getModuleFileLevelDecls(ModuleFile &Mod) { |
| 4165 | return std::make_pair(ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls), |
| 4166 | ModuleDeclIterator(this, &Mod, |
| 4167 | Mod.FileSortedDecls + Mod.NumFileSortedDecls)); |
| 4168 | } |
| 4169 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 4170 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 4171 | PreprocessedEntityID PPID = Index+1; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4172 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 4173 | ModuleFile &M = *PPInfo.first; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 4174 | unsigned LocalIndex = PPInfo.second; |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 4175 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 4176 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 4177 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 4178 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 4179 | |
| 4180 | unsigned Code = M.PreprocessorDetailCursor.ReadCode(); |
| 4181 | switch (Code) { |
| 4182 | case llvm::bitc::END_BLOCK: |
| 4183 | return 0; |
| 4184 | |
| 4185 | case llvm::bitc::ENTER_SUBBLOCK: |
| 4186 | Error("unexpected subblock record in preprocessor detail block"); |
| 4187 | return 0; |
| 4188 | |
| 4189 | case llvm::bitc::DEFINE_ABBREV: |
| 4190 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 4191 | return 0; |
| 4192 | |
| 4193 | default: |
| 4194 | break; |
| 4195 | } |
| 4196 | |
| 4197 | if (!PP.getPreprocessingRecord()) { |
| 4198 | Error("no preprocessing record"); |
| 4199 | return 0; |
| 4200 | } |
| 4201 | |
| 4202 | // Read the record. |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 4203 | SourceRange Range(ReadSourceLocation(M, PPOffs.Begin), |
| 4204 | ReadSourceLocation(M, PPOffs.End)); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 4205 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 4206 | const char *BlobStart = 0; |
| 4207 | unsigned BlobLen = 0; |
| 4208 | RecordData Record; |
| 4209 | PreprocessorDetailRecordTypes RecType = |
| 4210 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.ReadRecord( |
| 4211 | Code, Record, BlobStart, BlobLen); |
| 4212 | switch (RecType) { |
| 4213 | case PPD_MACRO_EXPANSION: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 4214 | bool isBuiltin = Record[0]; |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 4215 | IdentifierInfo *Name = 0; |
| 4216 | MacroDefinition *Def = 0; |
| 4217 | if (isBuiltin) |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 4218 | Name = getLocalIdentifier(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 4219 | else { |
| 4220 | PreprocessedEntityID |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 4221 | GlobalID = getGlobalPreprocessedEntityID(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 4222 | Def =cast<MacroDefinition>(PPRec.getLoadedPreprocessedEntity(GlobalID-1)); |
| 4223 | } |
| 4224 | |
| 4225 | MacroExpansion *ME; |
| 4226 | if (isBuiltin) |
| 4227 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 4228 | else |
| 4229 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 4230 | |
| 4231 | return ME; |
| 4232 | } |
| 4233 | |
| 4234 | case PPD_MACRO_DEFINITION: { |
| 4235 | // Decode the identifier info and then check again; if the macro is |
| 4236 | // still defined and associated with the identifier, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 4237 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 4238 | MacroDefinition *MD |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 4239 | = new (PPRec) MacroDefinition(II, Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 4240 | |
| 4241 | if (DeserializationListener) |
| 4242 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 4243 | |
| 4244 | return MD; |
| 4245 | } |
| 4246 | |
| 4247 | case PPD_INCLUSION_DIRECTIVE: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 4248 | const char *FullFileNameStart = BlobStart + Record[0]; |
Argyrios Kyrtzidis | 29f98b4 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 4249 | StringRef FullFileName(FullFileNameStart, BlobLen - Record[0]); |
| 4250 | const FileEntry *File = 0; |
| 4251 | if (!FullFileName.empty()) |
| 4252 | File = PP.getFileManager().getFile(FullFileName); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 4253 | |
| 4254 | // FIXME: Stable encoding |
| 4255 | InclusionDirective::InclusionKind Kind |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 4256 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 4257 | InclusionDirective *ID |
| 4258 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 4259 | StringRef(BlobStart, Record[0]), |
Argyrios Kyrtzidis | 8dd927c | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 4260 | Record[1], Record[3], |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 4261 | File, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 4262 | Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 4263 | return ID; |
| 4264 | } |
| 4265 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 4266 | |
| 4267 | llvm_unreachable("Invalid PreprocessorDetailRecordTypes"); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 4268 | } |
| 4269 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 4270 | /// \brief \arg SLocMapI points at a chunk of a module that contains no |
| 4271 | /// preprocessed entities or the entities it contains are not the ones we are |
| 4272 | /// looking for. Find the next module that contains entities and return the ID |
| 4273 | /// of the first entry. |
| 4274 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 4275 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 4276 | ++SLocMapI; |
| 4277 | for (GlobalSLocOffsetMapType::const_iterator |
| 4278 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4279 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 4280 | if (M.NumPreprocessedEntities) |
| 4281 | return getGlobalPreprocessedEntityID(M, M.BasePreprocessedEntityID); |
| 4282 | } |
| 4283 | |
| 4284 | return getTotalNumPreprocessedEntities(); |
| 4285 | } |
| 4286 | |
| 4287 | namespace { |
| 4288 | |
| 4289 | template <unsigned PPEntityOffset::*PPLoc> |
| 4290 | struct PPEntityComp { |
| 4291 | const ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4292 | ModuleFile &M; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 4293 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4294 | PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) { } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 4295 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 4296 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 4297 | SourceLocation LHS = getLoc(L); |
| 4298 | SourceLocation RHS = getLoc(R); |
| 4299 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4300 | } |
| 4301 | |
| 4302 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 4303 | SourceLocation LHS = getLoc(L); |
| 4304 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4305 | } |
| 4306 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 4307 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 4308 | SourceLocation RHS = getLoc(R); |
| 4309 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4310 | } |
| 4311 | |
| 4312 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
| 4313 | return Reader.ReadSourceLocation(M, PPE.*PPLoc); |
| 4314 | } |
| 4315 | }; |
| 4316 | |
| 4317 | } |
| 4318 | |
| 4319 | /// \brief Returns the first preprocessed entity ID that ends after \arg BLoc. |
| 4320 | PreprocessedEntityID |
| 4321 | ASTReader::findBeginPreprocessedEntity(SourceLocation BLoc) const { |
| 4322 | if (SourceMgr.isLocalSourceLocation(BLoc)) |
| 4323 | return getTotalNumPreprocessedEntities(); |
| 4324 | |
| 4325 | GlobalSLocOffsetMapType::const_iterator |
| 4326 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 4327 | BLoc.getOffset()); |
| 4328 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 4329 | "Corrupted global sloc offset map"); |
| 4330 | |
| 4331 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 4332 | return findNextPreprocessedEntity(SLocMapI); |
| 4333 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4334 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 4335 | typedef const PPEntityOffset *pp_iterator; |
| 4336 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 4337 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
Argyrios Kyrtzidis | 4cd0634 | 2011-09-22 21:17:02 +0000 | [diff] [blame] | 4338 | |
| 4339 | size_t Count = M.NumPreprocessedEntities; |
| 4340 | size_t Half; |
| 4341 | pp_iterator First = pp_begin; |
| 4342 | pp_iterator PPI; |
| 4343 | |
| 4344 | // Do a binary search manually instead of using std::lower_bound because |
| 4345 | // The end locations of entities may be unordered (when a macro expansion |
| 4346 | // is inside another macro argument), but for this case it is not important |
| 4347 | // whether we get the first macro expansion or its containing macro. |
| 4348 | while (Count > 0) { |
| 4349 | Half = Count/2; |
| 4350 | PPI = First; |
| 4351 | std::advance(PPI, Half); |
| 4352 | if (SourceMgr.isBeforeInTranslationUnit(ReadSourceLocation(M, PPI->End), |
| 4353 | BLoc)){ |
| 4354 | First = PPI; |
| 4355 | ++First; |
| 4356 | Count = Count - Half - 1; |
| 4357 | } else |
| 4358 | Count = Half; |
| 4359 | } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 4360 | |
| 4361 | if (PPI == pp_end) |
| 4362 | return findNextPreprocessedEntity(SLocMapI); |
| 4363 | |
| 4364 | return getGlobalPreprocessedEntityID(M, |
| 4365 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 4366 | } |
| 4367 | |
| 4368 | /// \brief Returns the first preprocessed entity ID that begins after \arg ELoc. |
| 4369 | PreprocessedEntityID |
| 4370 | ASTReader::findEndPreprocessedEntity(SourceLocation ELoc) const { |
| 4371 | if (SourceMgr.isLocalSourceLocation(ELoc)) |
| 4372 | return getTotalNumPreprocessedEntities(); |
| 4373 | |
| 4374 | GlobalSLocOffsetMapType::const_iterator |
| 4375 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 4376 | ELoc.getOffset()); |
| 4377 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 4378 | "Corrupted global sloc offset map"); |
| 4379 | |
| 4380 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 4381 | return findNextPreprocessedEntity(SLocMapI); |
| 4382 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4383 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 4384 | typedef const PPEntityOffset *pp_iterator; |
| 4385 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 4386 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 4387 | pp_iterator PPI = |
| 4388 | std::upper_bound(pp_begin, pp_end, ELoc, |
| 4389 | PPEntityComp<&PPEntityOffset::Begin>(*this, M)); |
| 4390 | |
| 4391 | if (PPI == pp_end) |
| 4392 | return findNextPreprocessedEntity(SLocMapI); |
| 4393 | |
| 4394 | return getGlobalPreprocessedEntityID(M, |
| 4395 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 4396 | } |
| 4397 | |
| 4398 | /// \brief Returns a pair of [Begin, End) indices of preallocated |
| 4399 | /// preprocessed entities that \arg Range encompasses. |
| 4400 | std::pair<unsigned, unsigned> |
| 4401 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 4402 | if (Range.isInvalid()) |
| 4403 | return std::make_pair(0,0); |
| 4404 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 4405 | |
| 4406 | PreprocessedEntityID BeginID = findBeginPreprocessedEntity(Range.getBegin()); |
| 4407 | PreprocessedEntityID EndID = findEndPreprocessedEntity(Range.getEnd()); |
| 4408 | return std::make_pair(BeginID, EndID); |
| 4409 | } |
| 4410 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 4411 | /// \brief Optionally returns true or false if the preallocated preprocessed |
| 4412 | /// entity with index \arg Index came from file \arg FID. |
| 4413 | llvm::Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
| 4414 | FileID FID) { |
| 4415 | if (FID.isInvalid()) |
| 4416 | return false; |
| 4417 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4418 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 4419 | ModuleFile &M = *PPInfo.first; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 4420 | unsigned LocalIndex = PPInfo.second; |
| 4421 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 4422 | |
| 4423 | SourceLocation Loc = ReadSourceLocation(M, PPOffs.Begin); |
| 4424 | if (Loc.isInvalid()) |
| 4425 | return false; |
| 4426 | |
| 4427 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 4428 | return true; |
| 4429 | else |
| 4430 | return false; |
| 4431 | } |
| 4432 | |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 4433 | namespace { |
| 4434 | /// \brief Visitor used to search for information about a header file. |
| 4435 | class HeaderFileInfoVisitor { |
| 4436 | ASTReader &Reader; |
| 4437 | const FileEntry *FE; |
| 4438 | |
| 4439 | llvm::Optional<HeaderFileInfo> HFI; |
| 4440 | |
| 4441 | public: |
| 4442 | HeaderFileInfoVisitor(ASTReader &Reader, const FileEntry *FE) |
| 4443 | : Reader(Reader), FE(FE) { } |
| 4444 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4445 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 4446 | HeaderFileInfoVisitor *This |
| 4447 | = static_cast<HeaderFileInfoVisitor *>(UserData); |
| 4448 | |
| 4449 | HeaderFileInfoTrait Trait(This->Reader, M, |
| 4450 | &This->Reader.getPreprocessor().getHeaderSearchInfo(), |
| 4451 | M.HeaderFileFrameworkStrings, |
| 4452 | This->FE->getName()); |
| 4453 | |
| 4454 | HeaderFileInfoLookupTable *Table |
| 4455 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 4456 | if (!Table) |
| 4457 | return false; |
| 4458 | |
| 4459 | // Look in the on-disk hash table for an entry for this file name. |
| 4460 | HeaderFileInfoLookupTable::iterator Pos = Table->find(This->FE->getName(), |
| 4461 | &Trait); |
| 4462 | if (Pos == Table->end()) |
| 4463 | return false; |
| 4464 | |
| 4465 | This->HFI = *Pos; |
| 4466 | return true; |
| 4467 | } |
| 4468 | |
| 4469 | llvm::Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| 4470 | }; |
| 4471 | } |
| 4472 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4473 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 4474 | HeaderFileInfoVisitor Visitor(*this, FE); |
| 4475 | ModuleMgr.visit(&HeaderFileInfoVisitor::visit, &Visitor); |
| 4476 | if (llvm::Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4477 | if (Listener) |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 4478 | Listener->ReadHeaderFileInfo(*HFI, FE->getUID()); |
| 4479 | return *HFI; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4480 | } |
| 4481 | |
| 4482 | return HeaderFileInfo(); |
| 4483 | } |
| 4484 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 4485 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4486 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4487 | ModuleFile &F = *(*I); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4488 | unsigned Idx = 0; |
| 4489 | while (Idx < F.PragmaDiagMappings.size()) { |
| 4490 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 4491 | Diag.DiagStates.push_back(*Diag.GetCurDiagState()); |
| 4492 | Diag.DiagStatePoints.push_back( |
| 4493 | DiagnosticsEngine::DiagStatePoint(&Diag.DiagStates.back(), |
| 4494 | FullSourceLoc(Loc, SourceMgr))); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4495 | while (1) { |
| 4496 | assert(Idx < F.PragmaDiagMappings.size() && |
| 4497 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 4498 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 4499 | break; // Something is messed up but at least avoid infinite loop in |
| 4500 | // release build. |
| 4501 | } |
| 4502 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 4503 | if (DiagID == (unsigned)-1) { |
| 4504 | break; // no more diag/map pairs for this location. |
| 4505 | } |
| 4506 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 4507 | DiagnosticMappingInfo MappingInfo = Diag.makeMappingInfo(Map, Loc); |
| 4508 | Diag.GetCurDiagState()->setMappingInfo(DiagID, MappingInfo); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4509 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 4510 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 4511 | } |
| 4512 | } |
| 4513 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4514 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4515 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4516 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | e9b76c1 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 4517 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4518 | ModuleFile *M = I->second; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 4519 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4520 | } |
| 4521 | |
| 4522 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4523 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4524 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 4525 | /// routine actually reads the record corresponding to the type at the given |
| 4526 | /// location. It is a helper routine for GetType, which deals with reading type |
| 4527 | /// IDs. |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4528 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4529 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4530 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 4531 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 4532 | // Keep track of where we are in the stream, then jump back there |
| 4533 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4534 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 4535 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4536 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 4537 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4538 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4539 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4540 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4541 | unsigned Idx = 0; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4542 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4543 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4544 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4545 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 4546 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4547 | if (Record.size() != 2) { |
| 4548 | Error("Incorrect encoding of extended qualifier type"); |
| 4549 | return QualType(); |
| 4550 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4551 | QualType Base = readType(*Loc.F, Record, Idx); |
| 4552 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4553 | return Context.getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 4554 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4555 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4556 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4557 | if (Record.size() != 1) { |
| 4558 | Error("Incorrect encoding of complex type"); |
| 4559 | return QualType(); |
| 4560 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4561 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4562 | return Context.getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4563 | } |
| 4564 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4565 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4566 | if (Record.size() != 1) { |
| 4567 | Error("Incorrect encoding of pointer type"); |
| 4568 | return QualType(); |
| 4569 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4570 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4571 | return Context.getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4572 | } |
| 4573 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4574 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4575 | if (Record.size() != 1) { |
| 4576 | Error("Incorrect encoding of block pointer type"); |
| 4577 | return QualType(); |
| 4578 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4579 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4580 | return Context.getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4583 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 4584 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4585 | Error("Incorrect encoding of lvalue reference type"); |
| 4586 | return QualType(); |
| 4587 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4588 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4589 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4590 | } |
| 4591 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4592 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4593 | if (Record.size() != 1) { |
| 4594 | Error("Incorrect encoding of rvalue reference type"); |
| 4595 | return QualType(); |
| 4596 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4597 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4598 | return Context.getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4599 | } |
| 4600 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4601 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 4602 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4603 | Error("Incorrect encoding of member pointer type"); |
| 4604 | return QualType(); |
| 4605 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4606 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 4607 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 4608 | if (PointeeType.isNull() || ClassType.isNull()) |
| 4609 | return QualType(); |
| 4610 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4611 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4612 | } |
| 4613 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4614 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4615 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4616 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 4617 | unsigned IndexTypeQuals = Record[2]; |
| 4618 | unsigned Idx = 3; |
| 4619 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4620 | return Context.getConstantArrayType(ElementType, Size, |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 4621 | ASM, IndexTypeQuals); |
| 4622 | } |
| 4623 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4624 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4625 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4626 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 4627 | unsigned IndexTypeQuals = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4628 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4629 | } |
| 4630 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4631 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4632 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 4633 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 4634 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4635 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 4636 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4637 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 4638 | ASM, IndexTypeQuals, |
| 4639 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4640 | } |
| 4641 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4642 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 4643 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4644 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4645 | return QualType(); |
| 4646 | } |
| 4647 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4648 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4649 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4650 | unsigned VecKind = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4651 | return Context.getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4652 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4653 | } |
| 4654 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4655 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 4656 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4657 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4658 | return QualType(); |
| 4659 | } |
| 4660 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4661 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4662 | unsigned NumElements = Record[1]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4663 | return Context.getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4664 | } |
| 4665 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4666 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4667 | if (Record.size() != 6) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4668 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4669 | return QualType(); |
| 4670 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4671 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4672 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 4673 | (CallingConv)Record[4], Record[5]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4674 | return Context.getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4675 | } |
| 4676 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4677 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4678 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4679 | |
| 4680 | FunctionProtoType::ExtProtoInfo EPI; |
| 4681 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 4682 | /*hasregparm*/ Record[2], |
| 4683 | /*regparm*/ Record[3], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4684 | static_cast<CallingConv>(Record[4]), |
| 4685 | /*produces*/ Record[5]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4686 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4687 | unsigned Idx = 6; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4688 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4689 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4690 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4691 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4692 | |
| 4693 | EPI.Variadic = Record[Idx++]; |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 4694 | EPI.HasTrailingReturn = Record[Idx++]; |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4695 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 4696 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4697 | ExceptionSpecificationType EST = |
| 4698 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 4699 | EPI.ExceptionSpecType = EST; |
Douglas Gregor | b0d06e2 | 2012-04-04 00:34:49 +0000 | [diff] [blame] | 4700 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4701 | if (EST == EST_Dynamic) { |
| 4702 | EPI.NumExceptions = Record[Idx++]; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4703 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4704 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4705 | EPI.Exceptions = Exceptions.data(); |
| 4706 | } else if (EST == EST_ComputedNoexcept) { |
| 4707 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
Richard Smith | 7bb698a | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 4708 | } else if (EST == EST_Uninstantiated) { |
| 4709 | EPI.ExceptionSpecDecl = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
| 4710 | EPI.ExceptionSpecTemplate = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
Richard Smith | b9d0b76 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 4711 | } else if (EST == EST_Unevaluated) { |
| 4712 | EPI.ExceptionSpecDecl = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4713 | } |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4714 | return Context.getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4715 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4716 | } |
| 4717 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4718 | case TYPE_UNRESOLVED_USING: { |
| 4719 | unsigned Idx = 0; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4720 | return Context.getTypeDeclType( |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4721 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 4722 | } |
| 4723 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4724 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 4725 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4726 | Error("incorrect encoding of typedef type"); |
| 4727 | return QualType(); |
| 4728 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4729 | unsigned Idx = 0; |
| 4730 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4731 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 4732 | if (!Canonical.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4733 | Canonical = Context.getCanonicalType(Canonical); |
| 4734 | return Context.getTypedefType(Decl, Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 4735 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4736 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4737 | case TYPE_TYPEOF_EXPR: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4738 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4739 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4740 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4741 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4742 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4743 | return QualType(); |
| 4744 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4745 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4746 | return Context.getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4747 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4748 | |
Douglas Gregor | f8af982 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 4749 | case TYPE_DECLTYPE: { |
| 4750 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 4751 | return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType); |
| 4752 | } |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 4753 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4754 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4755 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 4756 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4757 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4758 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4759 | } |
| 4760 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4761 | case TYPE_AUTO: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4762 | return Context.getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4763 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4764 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4765 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4766 | Error("incorrect encoding of record type"); |
| 4767 | return QualType(); |
| 4768 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4769 | unsigned Idx = 0; |
| 4770 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 4771 | RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx); |
| 4772 | RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl()); |
| 4773 | QualType T = Context.getRecordType(RD); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4774 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4775 | return T; |
| 4776 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4777 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4778 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4779 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4780 | Error("incorrect encoding of enum type"); |
| 4781 | return QualType(); |
| 4782 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4783 | unsigned Idx = 0; |
| 4784 | bool IsDependent = Record[Idx++]; |
| 4785 | QualType T |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4786 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4787 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4788 | return T; |
| 4789 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4790 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4791 | case TYPE_ATTRIBUTED: { |
| 4792 | if (Record.size() != 3) { |
| 4793 | Error("incorrect encoding of attributed type"); |
| 4794 | return QualType(); |
| 4795 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4796 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 4797 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4798 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4799 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4800 | } |
| 4801 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4802 | case TYPE_PAREN: { |
| 4803 | if (Record.size() != 1) { |
| 4804 | Error("incorrect encoding of paren type"); |
| 4805 | return QualType(); |
| 4806 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4807 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4808 | return Context.getParenType(InnerType); |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4809 | } |
| 4810 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4811 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 4812 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4813 | Error("incorrect encoding of pack expansion type"); |
| 4814 | return QualType(); |
| 4815 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4816 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4817 | if (Pattern.isNull()) |
| 4818 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4819 | llvm::Optional<unsigned> NumExpansions; |
| 4820 | if (Record[1]) |
| 4821 | NumExpansions = Record[1] - 1; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4822 | return Context.getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4823 | } |
| 4824 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4825 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4826 | unsigned Idx = 0; |
| 4827 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4828 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4829 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4830 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4831 | } |
| 4832 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4833 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4834 | unsigned Idx = 0; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4835 | ObjCInterfaceDecl *ItfD |
| 4836 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 4837 | return Context.getObjCInterfaceType(ItfD->getCanonicalDecl()); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4838 | } |
| 4839 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4840 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4841 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4842 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4843 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4844 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4845 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4846 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4847 | return Context.getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4848 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4849 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4850 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 4851 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4852 | QualType Pointee = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4853 | return Context.getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 4854 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4855 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4856 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4857 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4858 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 4859 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4860 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4861 | Context.getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4862 | Replacement); |
| 4863 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4864 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4865 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 4866 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4867 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4868 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4869 | return Context.getSubstTemplateTypeParmPackType( |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4870 | cast<TemplateTypeParmType>(Parm), |
| 4871 | ArgPack); |
| 4872 | } |
| 4873 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4874 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4875 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4876 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 4877 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4878 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 4879 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4880 | QualType(new (Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4881 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4882 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4883 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4884 | unsigned Idx = 0; |
| 4885 | unsigned Depth = Record[Idx++]; |
| 4886 | unsigned Index = Record[Idx++]; |
| 4887 | bool Pack = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4888 | TemplateTypeParmDecl *D |
| 4889 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4890 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4891 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4892 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4893 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 4894 | unsigned Idx = 0; |
| 4895 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4896 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4897 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4898 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 4899 | if (!Canon.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4900 | Canon = Context.getCanonicalType(Canon); |
| 4901 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 4902 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4903 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4904 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4905 | unsigned Idx = 0; |
| 4906 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4907 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4908 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4909 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4910 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4911 | Args.reserve(NumArgs); |
| 4912 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4913 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4914 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4915 | Args.size(), Args.data()); |
| 4916 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4917 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4918 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4919 | unsigned Idx = 0; |
| 4920 | |
| 4921 | // ArrayType |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4922 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4923 | ArrayType::ArraySizeModifier ASM |
| 4924 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 4925 | unsigned IndexTypeQuals = Record[Idx++]; |
| 4926 | |
| 4927 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4928 | Expr *NumElts = ReadExpr(*Loc.F); |
| 4929 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4930 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4931 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4932 | IndexTypeQuals, Brackets); |
| 4933 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4934 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4935 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4936 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4937 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4938 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4939 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4940 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4941 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4942 | QualType T; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4943 | if (Underlying.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4944 | T = Context.getCanonicalTemplateSpecializationType(Name, Args.data(), |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4945 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 4946 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4947 | T = Context.getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4948 | Args.size(), Underlying); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4949 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4950 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4951 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4952 | |
| 4953 | case TYPE_ATOMIC: { |
| 4954 | if (Record.size() != 1) { |
| 4955 | Error("Incorrect encoding of atomic type"); |
| 4956 | return QualType(); |
| 4957 | } |
| 4958 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 4959 | return Context.getAtomicType(ValueType); |
| 4960 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4961 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 4962 | llvm_unreachable("Invalid TypeCode!"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4963 | } |
| 4964 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4965 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4966 | ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4967 | ModuleFile &F; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4968 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4969 | unsigned &Idx; |
| 4970 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4971 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 4972 | unsigned &I) { |
| 4973 | return Reader.ReadSourceLocation(F, R, I); |
| 4974 | } |
| 4975 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4976 | template<typename T> |
| 4977 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 4978 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 4979 | } |
| 4980 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4981 | public: |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4982 | TypeLocReader(ASTReader &Reader, ModuleFile &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4983 | const ASTReader::RecordData &Record, unsigned &Idx) |
Benjamin Kramer | facde17 | 2012-06-06 17:32:50 +0000 | [diff] [blame] | 4984 | : Reader(Reader), F(F), Record(Record), Idx(Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4985 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4986 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4987 | // We want compile-time assurance that we've enumerated all of |
| 4988 | // these, so unfortunately we have to declare them first, then |
| 4989 | // define them out-of-line. |
| 4990 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4991 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4992 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4993 | #include "clang/AST/TypeLocNodes.def" |
| 4994 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4995 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 4996 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4997 | }; |
| 4998 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4999 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5000 | // nothing to do |
| 5001 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5002 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5003 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 5004 | if (TL.needsExtraLocalData()) { |
| 5005 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 5006 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 5007 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 5008 | TL.setModeAttr(Record[Idx++]); |
| 5009 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5010 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5011 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5012 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5013 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5014 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5015 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5016 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5017 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5018 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5019 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5020 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5021 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5022 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5023 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5024 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5025 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5026 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5027 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 5028 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5029 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5030 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5031 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 5032 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5033 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5034 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 5035 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5036 | TL.setSizeExpr(0); |
| 5037 | } |
| 5038 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 5039 | VisitArrayTypeLoc(TL); |
| 5040 | } |
| 5041 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 5042 | VisitArrayTypeLoc(TL); |
| 5043 | } |
| 5044 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 5045 | VisitArrayTypeLoc(TL); |
| 5046 | } |
| 5047 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 5048 | DependentSizedArrayTypeLoc TL) { |
| 5049 | VisitArrayTypeLoc(TL); |
| 5050 | } |
| 5051 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 5052 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5053 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5054 | } |
| 5055 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5056 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5057 | } |
| 5058 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5059 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5060 | } |
| 5061 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5062 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 5063 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 5064 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5065 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5066 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5067 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5068 | } |
| 5069 | } |
| 5070 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 5071 | VisitFunctionTypeLoc(TL); |
| 5072 | } |
| 5073 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 5074 | VisitFunctionTypeLoc(TL); |
| 5075 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5076 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5077 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5078 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5079 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5080 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5081 | } |
| 5082 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5083 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 5084 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 5085 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5086 | } |
| 5087 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5088 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 5089 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 5090 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 5091 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5092 | } |
| 5093 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5094 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5095 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 5096 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 5097 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 5098 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 5099 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 5100 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 5101 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 5102 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 5103 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5104 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5105 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5106 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5107 | } |
| 5108 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5109 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5110 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 5111 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 5112 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 5113 | if (TL.hasAttrOperand()) { |
| 5114 | SourceRange range; |
| 5115 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 5116 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 5117 | TL.setAttrOperandParensRange(range); |
| 5118 | } |
| 5119 | if (TL.hasAttrExprOperand()) { |
| 5120 | if (Record[Idx++]) |
| 5121 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 5122 | else |
| 5123 | TL.setAttrExprOperand(0); |
| 5124 | } else if (TL.hasAttrEnumOperand()) |
| 5125 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 5126 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5127 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5128 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5129 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5130 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 5131 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5132 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5133 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 5134 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 5135 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 5136 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5137 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5138 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 5139 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5140 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5141 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 5142 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 5143 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5144 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 5145 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5146 | Reader.GetTemplateArgumentLocInfo(F, |
| 5147 | TL.getTypePtr()->getArg(i).getKind(), |
| 5148 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5149 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 5150 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 5151 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 5152 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 5153 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5154 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5155 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5156 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5157 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5158 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5159 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5160 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 5161 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5162 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5163 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5164 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5165 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5166 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 5167 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5168 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5169 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5170 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5171 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5172 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 5173 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5174 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 5175 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5176 | Reader.GetTemplateArgumentLocInfo(F, |
| 5177 | TL.getTypePtr()->getArg(I).getKind(), |
| 5178 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5179 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5180 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 5181 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 5182 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5183 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5184 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5185 | } |
| 5186 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 5187 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5188 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 5189 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 5190 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5191 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5192 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 5193 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5194 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 5195 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 5196 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 5197 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 5198 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 5199 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 5200 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5201 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5202 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 5203 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5204 | unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5205 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5206 | if (InfoTy.isNull()) |
| 5207 | return 0; |
| 5208 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5209 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5210 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5211 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5212 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5213 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5214 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5215 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5216 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5217 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 5218 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5219 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5220 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5221 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5222 | switch ((PredefinedTypeIDs)Index) { |
| 5223 | case PREDEF_TYPE_NULL_ID: return QualType(); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5224 | case PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; |
| 5225 | case PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5226 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5227 | case PREDEF_TYPE_CHAR_U_ID: |
| 5228 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5229 | // FIXME: Check that the signedness of CharTy is correct! |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5230 | T = Context.CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5231 | break; |
| 5232 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5233 | case PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; |
| 5234 | case PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; |
| 5235 | case PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; |
| 5236 | case PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; |
| 5237 | case PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; |
| 5238 | case PREDEF_TYPE_UINT128_ID: T = Context.UnsignedInt128Ty; break; |
| 5239 | case PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; |
| 5240 | case PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; |
| 5241 | case PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; |
| 5242 | case PREDEF_TYPE_INT_ID: T = Context.IntTy; break; |
| 5243 | case PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; |
| 5244 | case PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; |
| 5245 | case PREDEF_TYPE_INT128_ID: T = Context.Int128Ty; break; |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 5246 | case PREDEF_TYPE_HALF_ID: T = Context.HalfTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5247 | case PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; |
| 5248 | case PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; |
| 5249 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; |
| 5250 | case PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; |
| 5251 | case PREDEF_TYPE_BOUND_MEMBER: T = Context.BoundMemberTy; break; |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 5252 | case PREDEF_TYPE_PSEUDO_OBJECT: T = Context.PseudoObjectTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5253 | case PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; |
| 5254 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context.UnknownAnyTy; break; |
| 5255 | case PREDEF_TYPE_NULLPTR_ID: T = Context.NullPtrTy; break; |
| 5256 | case PREDEF_TYPE_CHAR16_ID: T = Context.Char16Ty; break; |
| 5257 | case PREDEF_TYPE_CHAR32_ID: T = Context.Char32Ty; break; |
| 5258 | case PREDEF_TYPE_OBJC_ID: T = Context.ObjCBuiltinIdTy; break; |
| 5259 | case PREDEF_TYPE_OBJC_CLASS: T = Context.ObjCBuiltinClassTy; break; |
| 5260 | case PREDEF_TYPE_OBJC_SEL: T = Context.ObjCBuiltinSelTy; break; |
| 5261 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 5262 | |
| 5263 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5264 | T = Context.getAutoRRefDeductType(); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 5265 | break; |
John McCall | 0ddaeb9 | 2011-10-17 18:09:15 +0000 | [diff] [blame] | 5266 | |
| 5267 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 5268 | T = Context.ARCUnbridgedCastTy; |
| 5269 | break; |
| 5270 | |
Meador Inge | fb40e3f | 2012-07-01 15:57:25 +0000 | [diff] [blame] | 5271 | case PREDEF_TYPE_VA_LIST_TAG: |
| 5272 | T = Context.getVaListTagType(); |
| 5273 | break; |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 5274 | |
| 5275 | case PREDEF_TYPE_BUILTIN_FN: |
| 5276 | T = Context.BuiltinFnTy; |
| 5277 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5278 | } |
| 5279 | |
| 5280 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5281 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5282 | } |
| 5283 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5284 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 5285 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 5286 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5287 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5288 | if (TypesLoaded[Index].isNull()) |
| 5289 | return QualType(); |
| 5290 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5291 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5292 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 5293 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 5294 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 5295 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5296 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5297 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5298 | } |
| 5299 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5300 | QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5301 | return GetType(getGlobalTypeID(F, LocalID)); |
| 5302 | } |
| 5303 | |
| 5304 | serialization::TypeID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5305 | ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 5306 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 5307 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 5308 | |
| 5309 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 5310 | return LocalID; |
| 5311 | |
| 5312 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5313 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 5314 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 5315 | |
| 5316 | unsigned GlobalIndex = LocalIndex + I->second; |
| 5317 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 5318 | } |
| 5319 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5320 | TemplateArgumentLocInfo |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5321 | ASTReader::GetTemplateArgumentLocInfo(ModuleFile &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5322 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5323 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 5324 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5325 | switch (Kind) { |
| 5326 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5327 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5328 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5329 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5330 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 5331 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 5332 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5333 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 5334 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5335 | SourceLocation()); |
| 5336 | } |
| 5337 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 5338 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 5339 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5340 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 5341 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 5342 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 5343 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5344 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5345 | case TemplateArgument::Null: |
| 5346 | case TemplateArgument::Integral: |
| 5347 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5348 | case TemplateArgument::NullPtr: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5349 | case TemplateArgument::Pack: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5350 | // FIXME: Is this right? |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5351 | return TemplateArgumentLocInfo(); |
| 5352 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 5353 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5354 | } |
| 5355 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5356 | TemplateArgumentLoc |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5357 | ASTReader::ReadTemplateArgumentLoc(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 5358 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5359 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5360 | |
| 5361 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 5362 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 5363 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 5364 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5365 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 5366 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5367 | } |
| 5368 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5369 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5370 | return GetDecl(ID); |
| 5371 | } |
| 5372 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5373 | uint64_t ASTReader::readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 5374 | unsigned &Idx){ |
| 5375 | if (Idx >= Record.size()) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5376 | return 0; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5377 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 5378 | unsigned LocalID = Record[Idx++]; |
| 5379 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5383 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 5384 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5385 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5386 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5387 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 5388 | RecordData Record; |
| 5389 | unsigned Code = Cursor.ReadCode(); |
| 5390 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 5391 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 5392 | Error("Malformed AST file: missing C++ base specifiers"); |
| 5393 | return 0; |
| 5394 | } |
| 5395 | |
| 5396 | unsigned Idx = 0; |
| 5397 | unsigned NumBases = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5398 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5399 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 5400 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5401 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5402 | return Bases; |
| 5403 | } |
| 5404 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5405 | serialization::DeclID |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 5406 | ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5407 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5408 | return LocalID; |
| 5409 | |
| 5410 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5411 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5412 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 5413 | |
| 5414 | return LocalID + I->second; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5415 | } |
| 5416 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5417 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5418 | ModuleFile &M) const { |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5419 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(ID); |
| 5420 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 5421 | return &M == I->second; |
| 5422 | } |
| 5423 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 5424 | ModuleFile *ASTReader::getOwningModuleFile(Decl *D) { |
| 5425 | if (!D->isFromASTFile()) |
| 5426 | return 0; |
| 5427 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID()); |
| 5428 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 5429 | return I->second; |
| 5430 | } |
| 5431 | |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5432 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 5433 | if (ID < NUM_PREDEF_DECL_IDS) |
| 5434 | return SourceLocation(); |
| 5435 | |
| 5436 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 5437 | |
| 5438 | if (Index > DeclsLoaded.size()) { |
| 5439 | Error("declaration ID out-of-range for AST file"); |
| 5440 | return SourceLocation(); |
| 5441 | } |
| 5442 | |
| 5443 | if (Decl *D = DeclsLoaded[Index]) |
| 5444 | return D->getLocation(); |
| 5445 | |
| 5446 | unsigned RawLocation = 0; |
| 5447 | RecordLocation Rec = DeclCursorForID(ID, RawLocation); |
| 5448 | return ReadSourceLocation(*Rec.F, RawLocation); |
| 5449 | } |
| 5450 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5451 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5452 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 5453 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5454 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5455 | return 0; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5456 | |
| 5457 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5458 | return Context.getTranslationUnitDecl(); |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 5459 | |
| 5460 | case PREDEF_DECL_OBJC_ID_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5461 | return Context.getObjCIdDecl(); |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 5462 | |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 5463 | case PREDEF_DECL_OBJC_SEL_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5464 | return Context.getObjCSelDecl(); |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 5465 | |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 5466 | case PREDEF_DECL_OBJC_CLASS_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5467 | return Context.getObjCClassDecl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 5468 | |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 5469 | case PREDEF_DECL_OBJC_PROTOCOL_ID: |
| 5470 | return Context.getObjCProtocolDecl(); |
| 5471 | |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 5472 | case PREDEF_DECL_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5473 | return Context.getInt128Decl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 5474 | |
| 5475 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5476 | return Context.getUInt128Decl(); |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 5477 | |
| 5478 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5479 | return Context.getObjCInstanceTypeDecl(); |
Meador Inge | c5613b2 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 5480 | |
| 5481 | case PREDEF_DECL_BUILTIN_VA_LIST_ID: |
| 5482 | return Context.getBuiltinVaListDecl(); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5483 | } |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5484 | } |
| 5485 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5486 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 5487 | |
Richard Smith | 2fbf373 | 2011-12-20 04:39:57 +0000 | [diff] [blame] | 5488 | if (Index >= DeclsLoaded.size()) { |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5489 | assert(0 && "declaration ID out-of-range for AST file"); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5490 | Error("declaration ID out-of-range for AST file"); |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5491 | return 0; |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5492 | } |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5493 | |
Douglas Gregor | fd002a7 | 2011-12-16 22:37:11 +0000 | [diff] [blame] | 5494 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5495 | ReadDeclRecord(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5496 | if (DeserializationListener) |
| 5497 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 5498 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5499 | |
| 5500 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5501 | } |
| 5502 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 5503 | DeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
| 5504 | DeclID GlobalID) { |
| 5505 | if (GlobalID < NUM_PREDEF_DECL_IDS) |
| 5506 | return GlobalID; |
| 5507 | |
| 5508 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID); |
| 5509 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 5510 | ModuleFile *Owner = I->second; |
| 5511 | |
| 5512 | llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos |
| 5513 | = M.GlobalToLocalDeclIDs.find(Owner); |
| 5514 | if (Pos == M.GlobalToLocalDeclIDs.end()) |
| 5515 | return 0; |
| 5516 | |
| 5517 | return GlobalID - Owner->BaseDeclID + Pos->second; |
| 5518 | } |
| 5519 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5520 | serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5521 | const RecordData &Record, |
| 5522 | unsigned &Idx) { |
| 5523 | if (Idx >= Record.size()) { |
| 5524 | Error("Corrupted AST file"); |
| 5525 | return 0; |
| 5526 | } |
| 5527 | |
| 5528 | return getGlobalDeclID(F, Record[Idx++]); |
| 5529 | } |
| 5530 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 5531 | /// \brief Resolve the offset of a statement into a statement. |
| 5532 | /// |
| 5533 | /// This operation will read a new statement from the external |
| 5534 | /// source each time it is called, and is meant to be used via a |
| 5535 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5536 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 5537 | // Switch case IDs are per Decl. |
| 5538 | ClearSwitchCaseIDs(); |
| 5539 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 5540 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5541 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 5542 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 5543 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 5544 | } |
| 5545 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5546 | namespace { |
| 5547 | class FindExternalLexicalDeclsVisitor { |
| 5548 | ASTReader &Reader; |
| 5549 | const DeclContext *DC; |
| 5550 | bool (*isKindWeWant)(Decl::Kind); |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 5551 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5552 | SmallVectorImpl<Decl*> &Decls; |
| 5553 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 5554 | |
| 5555 | public: |
| 5556 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 5557 | bool (*isKindWeWant)(Decl::Kind), |
| 5558 | SmallVectorImpl<Decl*> &Decls) |
| 5559 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 5560 | { |
| 5561 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 5562 | PredefsVisited[I] = false; |
| 5563 | } |
| 5564 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5565 | static bool visit(ModuleFile &M, bool Preorder, void *UserData) { |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5566 | if (Preorder) |
| 5567 | return false; |
| 5568 | |
| 5569 | FindExternalLexicalDeclsVisitor *This |
| 5570 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 5571 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5572 | ModuleFile::DeclContextInfosMap::iterator Info |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5573 | = M.DeclContextInfos.find(This->DC); |
| 5574 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 5575 | return false; |
| 5576 | |
| 5577 | // Load all of the declaration IDs |
| 5578 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 5579 | *IDE = ID + Info->second.NumLexicalDecls; |
| 5580 | ID != IDE; ++ID) { |
| 5581 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 5582 | continue; |
| 5583 | |
| 5584 | // Don't add predefined declarations to the lexical context more |
| 5585 | // than once. |
| 5586 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 5587 | if (This->PredefsVisited[ID->second]) |
| 5588 | continue; |
| 5589 | |
| 5590 | This->PredefsVisited[ID->second] = true; |
| 5591 | } |
| 5592 | |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 5593 | if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) { |
| 5594 | if (!This->DC->isDeclInLexicalTraversal(D)) |
| 5595 | This->Decls.push_back(D); |
| 5596 | } |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5597 | } |
| 5598 | |
| 5599 | return false; |
| 5600 | } |
| 5601 | }; |
| 5602 | } |
| 5603 | |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 5604 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 5605 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5606 | SmallVectorImpl<Decl*> &Decls) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5607 | // There might be lexical decls in multiple modules, for the TU at |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5608 | // least. Walk all of the modules in the order they were loaded. |
| 5609 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 5610 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 5611 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 5612 | return ELR_Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5613 | } |
| 5614 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5615 | namespace { |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5616 | |
| 5617 | class DeclIDComp { |
| 5618 | ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5619 | ModuleFile &Mod; |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5620 | |
| 5621 | public: |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5622 | DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {} |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5623 | |
| 5624 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 5625 | SourceLocation LHS = getLocation(L); |
| 5626 | SourceLocation RHS = getLocation(R); |
| 5627 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5628 | } |
| 5629 | |
| 5630 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 5631 | SourceLocation RHS = getLocation(R); |
| 5632 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5633 | } |
| 5634 | |
| 5635 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 5636 | SourceLocation LHS = getLocation(L); |
| 5637 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5638 | } |
| 5639 | |
| 5640 | SourceLocation getLocation(LocalDeclID ID) const { |
| 5641 | return Reader.getSourceManager().getFileLoc( |
| 5642 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 5643 | } |
| 5644 | }; |
| 5645 | |
| 5646 | } |
| 5647 | |
| 5648 | void ASTReader::FindFileRegionDecls(FileID File, |
| 5649 | unsigned Offset, unsigned Length, |
| 5650 | SmallVectorImpl<Decl *> &Decls) { |
| 5651 | SourceManager &SM = getSourceManager(); |
| 5652 | |
| 5653 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 5654 | if (I == FileDeclIDs.end()) |
| 5655 | return; |
| 5656 | |
| 5657 | FileDeclsInfo &DInfo = I->second; |
| 5658 | if (DInfo.Decls.empty()) |
| 5659 | return; |
| 5660 | |
| 5661 | SourceLocation |
| 5662 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 5663 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 5664 | |
| 5665 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 5666 | ArrayRef<serialization::LocalDeclID>::iterator |
| 5667 | BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 5668 | BeginLoc, DIDComp); |
| 5669 | if (BeginIt != DInfo.Decls.begin()) |
| 5670 | --BeginIt; |
| 5671 | |
Argyrios Kyrtzidis | c14a03d | 2011-11-23 20:27:36 +0000 | [diff] [blame] | 5672 | // If we are pointing at a top-level decl inside an objc container, we need |
| 5673 | // to backtrack until we find it otherwise we will fail to report that the |
| 5674 | // region overlaps with an objc container. |
| 5675 | while (BeginIt != DInfo.Decls.begin() && |
| 5676 | GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt)) |
| 5677 | ->isTopLevelDeclInObjCContainer()) |
| 5678 | --BeginIt; |
| 5679 | |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5680 | ArrayRef<serialization::LocalDeclID>::iterator |
| 5681 | EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 5682 | EndLoc, DIDComp); |
| 5683 | if (EndIt != DInfo.Decls.end()) |
| 5684 | ++EndIt; |
| 5685 | |
| 5686 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 5687 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 5688 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 5689 | } |
| 5690 | |
| 5691 | namespace { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5692 | /// \brief ModuleFile visitor used to perform name lookup into a |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5693 | /// declaration context. |
| 5694 | class DeclContextNameLookupVisitor { |
| 5695 | ASTReader &Reader; |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5696 | llvm::SmallVectorImpl<const DeclContext *> &Contexts; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5697 | DeclarationName Name; |
| 5698 | SmallVectorImpl<NamedDecl *> &Decls; |
| 5699 | |
| 5700 | public: |
| 5701 | DeclContextNameLookupVisitor(ASTReader &Reader, |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5702 | SmallVectorImpl<const DeclContext *> &Contexts, |
| 5703 | DeclarationName Name, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5704 | SmallVectorImpl<NamedDecl *> &Decls) |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5705 | : Reader(Reader), Contexts(Contexts), Name(Name), Decls(Decls) { } |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5706 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5707 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5708 | DeclContextNameLookupVisitor *This |
| 5709 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 5710 | |
| 5711 | // Check whether we have any visible declaration information for |
| 5712 | // this context in this module. |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5713 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 5714 | bool FoundInfo = false; |
| 5715 | for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) { |
| 5716 | Info = M.DeclContextInfos.find(This->Contexts[I]); |
| 5717 | if (Info != M.DeclContextInfos.end() && |
| 5718 | Info->second.NameLookupTableData) { |
| 5719 | FoundInfo = true; |
| 5720 | break; |
| 5721 | } |
| 5722 | } |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5723 | |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5724 | if (!FoundInfo) |
| 5725 | return false; |
| 5726 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5727 | // Look for this name within this module. |
| 5728 | ASTDeclContextNameLookupTable *LookupTable = |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 5729 | Info->second.NameLookupTableData; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5730 | ASTDeclContextNameLookupTable::iterator Pos |
| 5731 | = LookupTable->find(This->Name); |
| 5732 | if (Pos == LookupTable->end()) |
| 5733 | return false; |
| 5734 | |
| 5735 | bool FoundAnything = false; |
| 5736 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 5737 | for (; Data.first != Data.second; ++Data.first) { |
| 5738 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 5739 | if (!ND) |
| 5740 | continue; |
| 5741 | |
| 5742 | if (ND->getDeclName() != This->Name) { |
Axel Naumann | 3dd82f7 | 2012-10-01 09:51:27 +0000 | [diff] [blame] | 5743 | // A name might be null because the decl's redeclarable part is |
| 5744 | // currently read before reading its name. The lookup is triggered by |
| 5745 | // building that decl (likely indirectly), and so it is later in the |
| 5746 | // sense of "already existing" and can be ignored here. |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5747 | continue; |
| 5748 | } |
| 5749 | |
| 5750 | // Record this declaration. |
| 5751 | FoundAnything = true; |
| 5752 | This->Decls.push_back(ND); |
| 5753 | } |
| 5754 | |
| 5755 | return FoundAnything; |
| 5756 | } |
| 5757 | }; |
| 5758 | } |
| 5759 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5760 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5761 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5762 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5763 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5764 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 5765 | if (!Name) |
| 5766 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 5767 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 5768 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5769 | SmallVector<NamedDecl *, 64> Decls; |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5770 | |
| 5771 | // Compute the declaration contexts we need to look into. Multiple such |
| 5772 | // declaration contexts occur when two declaration contexts from disjoint |
| 5773 | // modules get merged, e.g., when two namespaces with the same name are |
| 5774 | // independently defined in separate modules. |
| 5775 | SmallVector<const DeclContext *, 2> Contexts; |
| 5776 | Contexts.push_back(DC); |
| 5777 | |
| 5778 | if (DC->isNamespace()) { |
| 5779 | MergedDeclsMap::iterator Merged |
| 5780 | = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
| 5781 | if (Merged != MergedDecls.end()) { |
| 5782 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 5783 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 5784 | } |
| 5785 | } |
| 5786 | |
| 5787 | DeclContextNameLookupVisitor Visitor(*this, Contexts, Name, Decls); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5788 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 5789 | ++NumVisibleDeclContextsRead; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 5790 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5791 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5792 | } |
| 5793 | |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5794 | namespace { |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5795 | /// \brief ModuleFile visitor used to retrieve all visible names in a |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5796 | /// declaration context. |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5797 | class DeclContextAllNamesVisitor { |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5798 | ASTReader &Reader; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5799 | llvm::SmallVectorImpl<const DeclContext *> &Contexts; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5800 | llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8> > &Decls; |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5801 | |
| 5802 | public: |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5803 | DeclContextAllNamesVisitor(ASTReader &Reader, |
| 5804 | SmallVectorImpl<const DeclContext *> &Contexts, |
| 5805 | llvm::DenseMap<DeclarationName, |
| 5806 | SmallVector<NamedDecl *, 8> > &Decls) |
| 5807 | : Reader(Reader), Contexts(Contexts), Decls(Decls) { } |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5808 | |
| 5809 | static bool visit(ModuleFile &M, void *UserData) { |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5810 | DeclContextAllNamesVisitor *This |
| 5811 | = static_cast<DeclContextAllNamesVisitor *>(UserData); |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5812 | |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5813 | // Check whether we have any visible declaration information for |
| 5814 | // this context in this module. |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5815 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 5816 | bool FoundInfo = false; |
| 5817 | for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) { |
| 5818 | Info = M.DeclContextInfos.find(This->Contexts[I]); |
| 5819 | if (Info != M.DeclContextInfos.end() && |
| 5820 | Info->second.NameLookupTableData) { |
| 5821 | FoundInfo = true; |
| 5822 | break; |
| 5823 | } |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5824 | } |
| 5825 | |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5826 | if (!FoundInfo) |
| 5827 | return false; |
| 5828 | |
| 5829 | ASTDeclContextNameLookupTable *LookupTable = |
| 5830 | Info->second.NameLookupTableData; |
| 5831 | bool FoundAnything = false; |
| 5832 | for (ASTDeclContextNameLookupTable::data_iterator |
| 5833 | I = LookupTable->data_begin(), E = LookupTable->data_end(); |
| 5834 | I != E; ++I) { |
| 5835 | ASTDeclContextNameLookupTrait::data_type Data = *I; |
| 5836 | for (; Data.first != Data.second; ++Data.first) { |
| 5837 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, |
| 5838 | *Data.first); |
| 5839 | if (!ND) |
| 5840 | continue; |
| 5841 | |
| 5842 | // Record this declaration. |
| 5843 | FoundAnything = true; |
| 5844 | This->Decls[ND->getDeclName()].push_back(ND); |
| 5845 | } |
| 5846 | } |
| 5847 | |
| 5848 | return FoundAnything; |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5849 | } |
| 5850 | }; |
| 5851 | } |
| 5852 | |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5853 | void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5854 | if (!DC->hasExternalVisibleStorage()) |
| 5855 | return; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5856 | llvm::DenseMap<DeclarationName, llvm::SmallVector<NamedDecl*, 8> > Decls; |
| 5857 | |
| 5858 | // Compute the declaration contexts we need to look into. Multiple such |
| 5859 | // declaration contexts occur when two declaration contexts from disjoint |
| 5860 | // modules get merged, e.g., when two namespaces with the same name are |
| 5861 | // independently defined in separate modules. |
| 5862 | SmallVector<const DeclContext *, 2> Contexts; |
| 5863 | Contexts.push_back(DC); |
| 5864 | |
| 5865 | if (DC->isNamespace()) { |
| 5866 | MergedDeclsMap::iterator Merged |
| 5867 | = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
| 5868 | if (Merged != MergedDecls.end()) { |
| 5869 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 5870 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 5871 | } |
| 5872 | } |
| 5873 | |
| 5874 | DeclContextAllNamesVisitor Visitor(*this, Contexts, Decls); |
| 5875 | ModuleMgr.visit(&DeclContextAllNamesVisitor::visit, &Visitor); |
| 5876 | ++NumVisibleDeclContextsRead; |
| 5877 | |
| 5878 | for (llvm::DenseMap<DeclarationName, |
| 5879 | llvm::SmallVector<NamedDecl*, 8> >::iterator |
| 5880 | I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
| 5881 | SetExternalVisibleDeclsForName(DC, I->first, I->second); |
| 5882 | } |
Argyrios Kyrtzidis | 394e539 | 2012-04-26 18:34:14 +0000 | [diff] [blame] | 5883 | const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false); |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5884 | } |
| 5885 | |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5886 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 5887 | /// before receiving the implementation, and codegen depends on this. |
| 5888 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 5889 | /// implementation before passing the deserialized implementation decl. |
| 5890 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 5891 | ASTConsumer *Consumer) { |
| 5892 | assert(ImplD && Consumer); |
| 5893 | |
| 5894 | for (ObjCImplDecl::method_iterator |
| 5895 | I = ImplD->meth_begin(), E = ImplD->meth_end(); I != E; ++I) |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 5896 | Consumer->HandleInterestingDecl(DeclGroupRef(*I)); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5897 | |
| 5898 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 5899 | } |
| 5900 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5901 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5902 | assert(Consumer); |
| 5903 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5904 | Decl *D = InterestingDecls.front(); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5905 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5906 | |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 5907 | PassInterestingDeclToConsumer(D); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5908 | } |
| 5909 | } |
| 5910 | |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 5911 | void ASTReader::PassInterestingDeclToConsumer(Decl *D) { |
| 5912 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 5913 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 5914 | else |
| 5915 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
| 5916 | } |
| 5917 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5918 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 5919 | this->Consumer = Consumer; |
| 5920 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5921 | if (!Consumer) |
| 5922 | return; |
| 5923 | |
| 5924 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5925 | // Force deserialization of this decl, which will cause it to be queued for |
| 5926 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 5927 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5928 | } |
Douglas Gregor | 1a995dd | 2011-09-15 18:47:32 +0000 | [diff] [blame] | 5929 | ExternalDefinitions.clear(); |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 5930 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5931 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5932 | } |
| 5933 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5934 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5935 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5936 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5937 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5938 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5939 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5940 | unsigned NumDeclsLoaded |
| 5941 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 5942 | (Decl *)0); |
| 5943 | unsigned NumIdentifiersLoaded |
| 5944 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 5945 | IdentifiersLoaded.end(), |
| 5946 | (IdentifierInfo *)0); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5947 | unsigned NumMacrosLoaded |
| 5948 | = MacrosLoaded.size() - std::count(MacrosLoaded.begin(), |
| 5949 | MacrosLoaded.end(), |
| 5950 | (MacroInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5951 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5952 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 5953 | SelectorsLoaded.end(), |
| 5954 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 5955 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 5956 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 5957 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 5958 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 5959 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 5960 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 5961 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5962 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5963 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5964 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 5965 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 5966 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5967 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5968 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 5969 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5970 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5971 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5972 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 5973 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5974 | if (!MacrosLoaded.empty()) |
| 5975 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 5976 | NumMacrosLoaded, (unsigned)MacrosLoaded.size(), |
| 5977 | ((float)NumMacrosLoaded/MacrosLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5978 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5979 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5980 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 5981 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5982 | if (TotalNumStatements) |
| 5983 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 5984 | NumStatementsRead, TotalNumStatements, |
| 5985 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 5986 | if (TotalNumMacros) |
| 5987 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 5988 | NumMacrosRead, TotalNumMacros, |
| 5989 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 5990 | if (TotalLexicalDeclContexts) |
| 5991 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 5992 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 5993 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 5994 | * 100)); |
| 5995 | if (TotalVisibleDeclContexts) |
| 5996 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 5997 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 5998 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 5999 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 6000 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 6001 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 6002 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 6003 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 6004 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 6005 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 6006 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6007 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 6008 | dump(); |
| 6009 | std::fprintf(stderr, "\n"); |
| 6010 | } |
| 6011 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6012 | template<typename Key, typename ModuleFile, unsigned InitialCapacity> |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 6013 | static void |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6014 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6015 | const ContinuousRangeMap<Key, ModuleFile *, |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 6016 | InitialCapacity> &Map) { |
| 6017 | if (Map.begin() == Map.end()) |
| 6018 | return; |
| 6019 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6020 | typedef ContinuousRangeMap<Key, ModuleFile *, InitialCapacity> MapType; |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 6021 | llvm::errs() << Name << ":\n"; |
| 6022 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 6023 | I != IEnd; ++I) { |
| 6024 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 6025 | << "\n"; |
| 6026 | } |
| 6027 | } |
| 6028 | |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 6029 | void ASTReader::dump() { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6030 | llvm::errs() << "*** PCH/ModuleFile Remappings:\n"; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 6031 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 6032 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 6033 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 6034 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 6035 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6036 | dumpModuleIDMap("Global macro map", GlobalMacroMap); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 6037 | dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 6038 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 6039 | dumpModuleIDMap("Global preprocessed entity map", |
| 6040 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 8df5c9b | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 6041 | |
| 6042 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 6043 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 6044 | MEnd = ModuleMgr.end(); |
| 6045 | M != MEnd; ++M) |
| 6046 | (*M)->dump(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6047 | } |
| 6048 | |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 6049 | /// Return the amount of memory used by memory buffers, breaking down |
| 6050 | /// by heap-backed versus mmap'ed memory. |
| 6051 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 6052 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 6053 | E = ModuleMgr.end(); I != E; ++I) { |
| 6054 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 6055 | size_t bytes = buf->getBufferSize(); |
| 6056 | switch (buf->getBufferKind()) { |
| 6057 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 6058 | sizes.malloc_bytes += bytes; |
| 6059 | break; |
| 6060 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 6061 | sizes.mmap_bytes += bytes; |
| 6062 | break; |
| 6063 | } |
| 6064 | } |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 6065 | } |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 6066 | } |
| 6067 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6068 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6069 | SemaObj = &S; |
Axel Naumann | 0ec56b7 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 6070 | S.addExternalSource(this); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 6071 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 6072 | // Makes sure any declarations that were deserialized "too early" |
| 6073 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 6074 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 6075 | SemaObj->pushExternalDeclIntoScope(PreloadedDecls[I], |
| 6076 | PreloadedDecls[I]->getDeclName()); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6077 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 6078 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 6079 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 6080 | // Load the offsets of the declarations that Sema references. |
| 6081 | // They will be lazily deserialized when needed. |
| 6082 | if (!SemaDeclRefs.empty()) { |
| 6083 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | 1e5b6f6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 6084 | if (!SemaObj->StdNamespace) |
| 6085 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 6086 | if (!SemaObj->StdBadAlloc) |
| 6087 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 6088 | } |
| 6089 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 6090 | if (!FPPragmaOptions.empty()) { |
| 6091 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 6092 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 6093 | } |
| 6094 | |
| 6095 | if (!OpenCLExtensions.empty()) { |
| 6096 | unsigned I = 0; |
| 6097 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 6098 | #include "clang/Basic/OpenCLExtensions.def" |
| 6099 | |
| 6100 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 6101 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6102 | } |
| 6103 | |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 6104 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 6105 | // Note that we are loading an identifier. |
| 6106 | Deserializing AnIdentifier(this); |
| 6107 | |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 6108 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart), |
| 6109 | /*PriorGeneration=*/0); |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 6110 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 6111 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 6112 | markIdentifierUpToDate(II); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 6113 | return II; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6114 | } |
| 6115 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 6116 | namespace clang { |
| 6117 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 6118 | /// identifiers stored within a set of AST files. |
| 6119 | class ASTIdentifierIterator : public IdentifierIterator { |
| 6120 | /// \brief The AST reader whose identifiers are being enumerated. |
| 6121 | const ASTReader &Reader; |
| 6122 | |
| 6123 | /// \brief The current index into the chain of AST files stored in |
| 6124 | /// the AST reader. |
| 6125 | unsigned Index; |
| 6126 | |
| 6127 | /// \brief The current position within the identifier lookup table |
| 6128 | /// of the current AST file. |
| 6129 | ASTIdentifierLookupTable::key_iterator Current; |
| 6130 | |
| 6131 | /// \brief The end position within the identifier lookup table of |
| 6132 | /// the current AST file. |
| 6133 | ASTIdentifierLookupTable::key_iterator End; |
| 6134 | |
| 6135 | public: |
| 6136 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 6137 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6138 | virtual StringRef Next(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 6139 | }; |
| 6140 | } |
| 6141 | |
| 6142 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 6143 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 6144 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 6145 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 6146 | Current = IdTable->key_begin(); |
| 6147 | End = IdTable->key_end(); |
| 6148 | } |
| 6149 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6150 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 6151 | while (Current == End) { |
| 6152 | // If we have exhausted all of our AST files, we're done. |
| 6153 | if (Index == 0) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6154 | return StringRef(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 6155 | |
| 6156 | --Index; |
| 6157 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 6158 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 6159 | IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 6160 | Current = IdTable->key_begin(); |
| 6161 | End = IdTable->key_end(); |
| 6162 | } |
| 6163 | |
| 6164 | // We have any identifiers remaining in the current AST file; return |
| 6165 | // the next one. |
| 6166 | std::pair<const char*, unsigned> Key = *Current; |
| 6167 | ++Current; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6168 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 6172 | return new ASTIdentifierIterator(*this); |
| 6173 | } |
| 6174 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6175 | namespace clang { namespace serialization { |
| 6176 | class ReadMethodPoolVisitor { |
| 6177 | ASTReader &Reader; |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 6178 | Selector Sel; |
| 6179 | unsigned PriorGeneration; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6180 | llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 6181 | llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 6182 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6183 | public: |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 6184 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, |
| 6185 | unsigned PriorGeneration) |
| 6186 | : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration) { } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6187 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6188 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6189 | ReadMethodPoolVisitor *This |
| 6190 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 6191 | |
| 6192 | if (!M.SelectorLookupTable) |
| 6193 | return false; |
| 6194 | |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 6195 | // If we've already searched this module file, skip it now. |
| 6196 | if (M.Generation <= This->PriorGeneration) |
| 6197 | return true; |
| 6198 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6199 | ASTSelectorLookupTable *PoolTable |
| 6200 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 6201 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 6202 | if (Pos == PoolTable->end()) |
| 6203 | return false; |
| 6204 | |
| 6205 | ++This->Reader.NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 6206 | // FIXME: Not quite happy with the statistics here. We probably should |
| 6207 | // disable this tracking when called via LoadSelector. |
| 6208 | // Also, should entries without methods count as misses? |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6209 | ++This->Reader.NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 6210 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6211 | if (This->Reader.DeserializationListener) |
| 6212 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 6213 | This->Sel); |
| 6214 | |
| 6215 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 6216 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 6217 | return true; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 6218 | } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6219 | |
| 6220 | /// \brief Retrieve the instance methods found by this visitor. |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 6221 | ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { |
| 6222 | return InstanceMethods; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6223 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 6224 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6225 | /// \brief Retrieve the instance methods found by this visitor. |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 6226 | ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { |
| 6227 | return FactoryMethods; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6228 | } |
| 6229 | }; |
| 6230 | } } // end namespace clang::serialization |
| 6231 | |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 6232 | /// \brief Add the given set of methods to the method list. |
| 6233 | static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, |
| 6234 | ObjCMethodList &List) { |
| 6235 | for (unsigned I = 0, N = Methods.size(); I != N; ++I) { |
| 6236 | S.addMethodToGlobalList(&List, Methods[I]); |
| 6237 | } |
| 6238 | } |
| 6239 | |
| 6240 | void ASTReader::ReadMethodPool(Selector Sel) { |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 6241 | // Get the selector generation and update it to the current generation. |
| 6242 | unsigned &Generation = SelectorGeneration[Sel]; |
| 6243 | unsigned PriorGeneration = Generation; |
| 6244 | Generation = CurrentGeneration; |
| 6245 | |
| 6246 | // Search for methods defined with this selector. |
| 6247 | ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration); |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6248 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6249 | |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 6250 | if (Visitor.getInstanceMethods().empty() && |
| 6251 | Visitor.getFactoryMethods().empty()) { |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 6252 | ++NumMethodPoolMisses; |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 6253 | return; |
| 6254 | } |
| 6255 | |
| 6256 | if (!getSema()) |
| 6257 | return; |
| 6258 | |
| 6259 | Sema &S = *getSema(); |
| 6260 | Sema::GlobalMethodPool::iterator Pos |
| 6261 | = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; |
| 6262 | |
| 6263 | addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); |
| 6264 | addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 6265 | } |
| 6266 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 6267 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6268 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 6269 | Namespaces.clear(); |
| 6270 | |
| 6271 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 6272 | if (NamespaceDecl *Namespace |
| 6273 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 6274 | Namespaces.push_back(Namespace); |
| 6275 | } |
| 6276 | } |
| 6277 | |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 6278 | void ASTReader::ReadTentativeDefinitions( |
| 6279 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 6280 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 6281 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 6282 | if (Var) |
| 6283 | TentativeDefs.push_back(Var); |
| 6284 | } |
| 6285 | TentativeDefinitions.clear(); |
| 6286 | } |
| 6287 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 6288 | void ASTReader::ReadUnusedFileScopedDecls( |
| 6289 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 6290 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 6291 | DeclaratorDecl *D |
| 6292 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 6293 | if (D) |
| 6294 | Decls.push_back(D); |
| 6295 | } |
| 6296 | UnusedFileScopedDecls.clear(); |
| 6297 | } |
| 6298 | |
Douglas Gregor | 0129b56 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 6299 | void ASTReader::ReadDelegatingConstructors( |
| 6300 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 6301 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 6302 | CXXConstructorDecl *D |
| 6303 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 6304 | if (D) |
| 6305 | Decls.push_back(D); |
| 6306 | } |
| 6307 | DelegatingCtorDecls.clear(); |
| 6308 | } |
| 6309 | |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 6310 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 6311 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 6312 | TypedefNameDecl *D |
| 6313 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 6314 | if (D) |
| 6315 | Decls.push_back(D); |
| 6316 | } |
| 6317 | ExtVectorDecls.clear(); |
| 6318 | } |
| 6319 | |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 6320 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 6321 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 6322 | CXXRecordDecl *D |
| 6323 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 6324 | if (D) |
| 6325 | Decls.push_back(D); |
| 6326 | } |
| 6327 | DynamicClasses.clear(); |
| 6328 | } |
| 6329 | |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 6330 | void |
| 6331 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 6332 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 6333 | NamedDecl *D |
| 6334 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 6335 | if (D) |
| 6336 | Decls.push_back(D); |
| 6337 | } |
| 6338 | LocallyScopedExternalDecls.clear(); |
| 6339 | } |
| 6340 | |
Douglas Gregor | 5b9dc7c | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 6341 | void ASTReader::ReadReferencedSelectors( |
| 6342 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 6343 | if (ReferencedSelectorsData.empty()) |
| 6344 | return; |
| 6345 | |
| 6346 | // If there are @selector references added them to its pool. This is for |
| 6347 | // implementation of -Wselector. |
| 6348 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 6349 | unsigned I = 0; |
| 6350 | while (I < DataSize) { |
| 6351 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 6352 | SourceLocation SelLoc |
| 6353 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 6354 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 6355 | } |
| 6356 | ReferencedSelectorsData.clear(); |
| 6357 | } |
| 6358 | |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 6359 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 6360 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 6361 | if (WeakUndeclaredIdentifiers.empty()) |
| 6362 | return; |
| 6363 | |
| 6364 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 6365 | IdentifierInfo *WeakId |
| 6366 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 6367 | IdentifierInfo *AliasId |
| 6368 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 6369 | SourceLocation Loc |
| 6370 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 6371 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 6372 | WeakInfo WI(AliasId, Loc); |
| 6373 | WI.setUsed(Used); |
| 6374 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 6375 | } |
| 6376 | WeakUndeclaredIdentifiers.clear(); |
| 6377 | } |
| 6378 | |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 6379 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 6380 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 6381 | ExternalVTableUse VT; |
| 6382 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 6383 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 6384 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 6385 | VTables.push_back(VT); |
| 6386 | } |
| 6387 | |
| 6388 | VTableUses.clear(); |
| 6389 | } |
| 6390 | |
Douglas Gregor | 6e4a3f5 | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 6391 | void ASTReader::ReadPendingInstantiations( |
| 6392 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 6393 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 6394 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 6395 | SourceLocation Loc |
| 6396 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 6397 | |
Douglas Gregor | e5fa3c2 | 2012-10-03 18:34:48 +0000 | [diff] [blame] | 6398 | Pending.push_back(std::make_pair(D, Loc)); |
Douglas Gregor | 6e4a3f5 | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 6399 | } |
| 6400 | PendingInstantiations.clear(); |
| 6401 | } |
| 6402 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6403 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 6404 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 6405 | ReadMethodPool(Sel); |
| 6406 | } |
| 6407 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6408 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6409 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 6410 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 6411 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 6412 | if (DeserializationListener) |
| 6413 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6414 | } |
| 6415 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6416 | /// \brief Set the globally-visible declarations associated with the given |
| 6417 | /// identifier. |
| 6418 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 6419 | /// If the AST reader is currently in a state where the given declaration IDs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6420 | /// cannot safely be resolved, they are queued until it is safe to resolve |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6421 | /// them. |
| 6422 | /// |
| 6423 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 6424 | /// declarations. |
| 6425 | /// |
| 6426 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 6427 | /// visible at global scope. |
| 6428 | /// |
| 6429 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 6430 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 6431 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6432 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6433 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6434 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6435 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 6436 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6437 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 6438 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 6439 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 6440 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6441 | return; |
| 6442 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6443 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6444 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 6445 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 6446 | if (SemaObj) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 6447 | // Introduce this declaration into the translation-unit scope |
| 6448 | // and add it to the declaration chain for this identifier, so |
| 6449 | // that (unqualified) name lookup will find it. |
| 6450 | SemaObj->pushExternalDeclIntoScope(D, II); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6451 | } else { |
| 6452 | // Queue this declaration so that it will be added to the |
| 6453 | // translation unit scope and identifier's declaration chain |
| 6454 | // once a Sema object is known. |
| 6455 | PreloadedDecls.push_back(D); |
| 6456 | } |
| 6457 | } |
| 6458 | } |
| 6459 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6460 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 6461 | if (ID == 0) |
| 6462 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6463 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 6464 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 6465 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 6466 | return 0; |
| 6467 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6468 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 6469 | ID -= 1; |
| 6470 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 6471 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 6472 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6473 | ModuleFile *M = I->second; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 6474 | unsigned Index = ID - M->BaseIdentifierID; |
| 6475 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 6476 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 6477 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 6478 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 6479 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 6480 | // unsigned integers. This is important to avoid integer overflow when |
| 6481 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 6482 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 6483 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 6484 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 6485 | IdentifiersLoaded[ID] |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 6486 | = &PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 6487 | if (DeserializationListener) |
| 6488 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 6489 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6490 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 6491 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6492 | } |
| 6493 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6494 | IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6495 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 6496 | } |
| 6497 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6498 | IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 6499 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 6500 | return LocalID; |
| 6501 | |
| 6502 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6503 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 6504 | assert(I != M.IdentifierRemap.end() |
| 6505 | && "Invalid index into identifier index remap"); |
| 6506 | |
| 6507 | return LocalID + I->second; |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6508 | } |
| 6509 | |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 6510 | MacroInfo *ASTReader::getMacro(MacroID ID, MacroInfo *Hint) { |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6511 | if (ID == 0) |
| 6512 | return 0; |
| 6513 | |
| 6514 | if (MacrosLoaded.empty()) { |
| 6515 | Error("no macro table in AST file"); |
| 6516 | return 0; |
| 6517 | } |
| 6518 | |
| 6519 | ID -= NUM_PREDEF_MACRO_IDS; |
| 6520 | if (!MacrosLoaded[ID]) { |
| 6521 | GlobalMacroMapType::iterator I |
| 6522 | = GlobalMacroMap.find(ID + NUM_PREDEF_MACRO_IDS); |
| 6523 | assert(I != GlobalMacroMap.end() && "Corrupted global macro map"); |
| 6524 | ModuleFile *M = I->second; |
| 6525 | unsigned Index = ID - M->BaseMacroID; |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 6526 | ReadMacroRecord(*M, M->MacroOffsets[Index], Hint); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6527 | } |
| 6528 | |
| 6529 | return MacrosLoaded[ID]; |
| 6530 | } |
| 6531 | |
| 6532 | MacroID ASTReader::getGlobalMacroID(ModuleFile &M, unsigned LocalID) { |
| 6533 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 6534 | return LocalID; |
| 6535 | |
| 6536 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6537 | = M.MacroRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 6538 | assert(I != M.MacroRemap.end() && "Invalid index into macro index remap"); |
| 6539 | |
| 6540 | return LocalID + I->second; |
| 6541 | } |
| 6542 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 6543 | serialization::SubmoduleID |
| 6544 | ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) { |
| 6545 | if (LocalID < NUM_PREDEF_SUBMODULE_IDS) |
| 6546 | return LocalID; |
| 6547 | |
| 6548 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6549 | = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS); |
| 6550 | assert(I != M.SubmoduleRemap.end() |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6551 | && "Invalid index into submodule index remap"); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 6552 | |
| 6553 | return LocalID + I->second; |
| 6554 | } |
| 6555 | |
| 6556 | Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { |
| 6557 | if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) { |
| 6558 | assert(GlobalID == 0 && "Unhandled global submodule ID"); |
| 6559 | return 0; |
| 6560 | } |
| 6561 | |
| 6562 | if (GlobalID > SubmodulesLoaded.size()) { |
| 6563 | Error("submodule ID out of range in AST file"); |
| 6564 | return 0; |
| 6565 | } |
| 6566 | |
| 6567 | return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; |
| 6568 | } |
| 6569 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6570 | Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 6571 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 6572 | } |
| 6573 | |
| 6574 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 6575 | if (ID == 0) |
| 6576 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6577 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 6578 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 6579 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 6580 | return Selector(); |
| 6581 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 6582 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 6583 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 6584 | // Load this selector from the selector table. |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 6585 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 6586 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6587 | ModuleFile &M = *I->second; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 6588 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 6589 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 6590 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 6591 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 6592 | if (DeserializationListener) |
| 6593 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 6594 | } |
| 6595 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 6596 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 6597 | } |
| 6598 | |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 6599 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 6600 | return DecodeSelector(ID); |
| 6601 | } |
| 6602 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6603 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 6604 | // ID 0 (the null selector) is considered an external selector. |
| 6605 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 6606 | } |
| 6607 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 6608 | serialization::SelectorID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6609 | ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 6610 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 6611 | return LocalID; |
| 6612 | |
| 6613 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6614 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 6615 | assert(I != M.SelectorRemap.end() |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6616 | && "Invalid index into selector index remap"); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 6617 | |
| 6618 | return LocalID + I->second; |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 6619 | } |
| 6620 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6621 | DeclarationName |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6622 | ASTReader::ReadDeclarationName(ModuleFile &F, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6623 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6624 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 6625 | switch (Kind) { |
| 6626 | case DeclarationName::Identifier: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6627 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6628 | |
| 6629 | case DeclarationName::ObjCZeroArgSelector: |
| 6630 | case DeclarationName::ObjCOneArgSelector: |
| 6631 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 6632 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6633 | |
| 6634 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6635 | return Context.DeclarationNames.getCXXConstructorName( |
| 6636 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6637 | |
| 6638 | case DeclarationName::CXXDestructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6639 | return Context.DeclarationNames.getCXXDestructorName( |
| 6640 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6641 | |
| 6642 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6643 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 6644 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6645 | |
| 6646 | case DeclarationName::CXXOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6647 | return Context.DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6648 | (OverloadedOperatorKind)Record[Idx++]); |
| 6649 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 6650 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6651 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6652 | GetIdentifierInfo(F, Record, Idx)); |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 6653 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6654 | case DeclarationName::CXXUsingDirective: |
| 6655 | return DeclarationName::getUsingDirectiveName(); |
| 6656 | } |
| 6657 | |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 6658 | llvm_unreachable("Invalid NameKind!"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6659 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 6660 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6661 | void ASTReader::ReadDeclarationNameLoc(ModuleFile &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6662 | DeclarationNameLoc &DNLoc, |
| 6663 | DeclarationName Name, |
| 6664 | const RecordData &Record, unsigned &Idx) { |
| 6665 | switch (Name.getNameKind()) { |
| 6666 | case DeclarationName::CXXConstructorName: |
| 6667 | case DeclarationName::CXXDestructorName: |
| 6668 | case DeclarationName::CXXConversionFunctionName: |
| 6669 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 6670 | break; |
| 6671 | |
| 6672 | case DeclarationName::CXXOperatorName: |
| 6673 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 6674 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 6675 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 6676 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 6677 | break; |
| 6678 | |
| 6679 | case DeclarationName::CXXLiteralOperatorName: |
| 6680 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 6681 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 6682 | break; |
| 6683 | |
| 6684 | case DeclarationName::Identifier: |
| 6685 | case DeclarationName::ObjCZeroArgSelector: |
| 6686 | case DeclarationName::ObjCOneArgSelector: |
| 6687 | case DeclarationName::ObjCMultiArgSelector: |
| 6688 | case DeclarationName::CXXUsingDirective: |
| 6689 | break; |
| 6690 | } |
| 6691 | } |
| 6692 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6693 | void ASTReader::ReadDeclarationNameInfo(ModuleFile &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6694 | DeclarationNameInfo &NameInfo, |
| 6695 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6696 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6697 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 6698 | DeclarationNameLoc DNLoc; |
| 6699 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 6700 | NameInfo.setInfo(DNLoc); |
| 6701 | } |
| 6702 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6703 | void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6704 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 6705 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6706 | unsigned NumTPLists = Record[Idx++]; |
| 6707 | Info.NumTemplParamLists = NumTPLists; |
| 6708 | if (NumTPLists) { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6709 | Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6710 | for (unsigned i=0; i != NumTPLists; ++i) |
| 6711 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 6712 | } |
| 6713 | } |
| 6714 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6715 | TemplateName |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6716 | ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6717 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6718 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6719 | switch (Kind) { |
| 6720 | case TemplateName::Template: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6721 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6722 | |
| 6723 | case TemplateName::OverloadedTemplate: { |
| 6724 | unsigned size = Record[Idx++]; |
| 6725 | UnresolvedSet<8> Decls; |
| 6726 | while (size--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6727 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6728 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6729 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6730 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6731 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6732 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6733 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6734 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6735 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6736 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6737 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6738 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6739 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6740 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6741 | if (Record[Idx++]) // isIdentifier |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6742 | return Context.getDependentTemplateName(NNS, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6743 | GetIdentifierInfo(F, Record, |
| 6744 | Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6745 | return Context.getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 6746 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6747 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6748 | |
| 6749 | case TemplateName::SubstTemplateTemplateParm: { |
| 6750 | TemplateTemplateParmDecl *param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6751 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6752 | if (!param) return TemplateName(); |
| 6753 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6754 | return Context.getSubstTemplateTemplateParm(param, replacement); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6755 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6756 | |
| 6757 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 6758 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6759 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6760 | if (!Param) |
| 6761 | return TemplateName(); |
| 6762 | |
| 6763 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 6764 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 6765 | return TemplateName(); |
| 6766 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6767 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6768 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6769 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6770 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 6771 | llvm_unreachable("Unhandled template name kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6772 | } |
| 6773 | |
| 6774 | TemplateArgument |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6775 | ASTReader::ReadTemplateArgument(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 6776 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 6777 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 6778 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6779 | case TemplateArgument::Null: |
| 6780 | return TemplateArgument(); |
| 6781 | case TemplateArgument::Type: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6782 | return TemplateArgument(readType(F, Record, Idx)); |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 6783 | case TemplateArgument::Declaration: { |
| 6784 | ValueDecl *D = ReadDeclAs<ValueDecl>(F, Record, Idx); |
| 6785 | bool ForReferenceParam = Record[Idx++]; |
| 6786 | return TemplateArgument(D, ForReferenceParam); |
| 6787 | } |
| 6788 | case TemplateArgument::NullPtr: |
| 6789 | return TemplateArgument(readType(F, Record, Idx), /*isNullPtr*/true); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 6790 | case TemplateArgument::Integral: { |
| 6791 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6792 | QualType T = readType(F, Record, Idx); |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 6793 | return TemplateArgument(Context, Value, T); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 6794 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 6795 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6796 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 6797 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6798 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 6799 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 6800 | if (unsigned NumExpansions = Record[Idx++]) |
| 6801 | NumTemplateExpansions = NumExpansions - 1; |
| 6802 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 6803 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6804 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6805 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6806 | case TemplateArgument::Pack: { |
| 6807 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6808 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 6809 | for (unsigned I = 0; I != NumArgs; ++I) |
| 6810 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 6811 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6812 | } |
| 6813 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6814 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 6815 | llvm_unreachable("Unhandled template argument kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6816 | } |
| 6817 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6818 | TemplateParameterList * |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6819 | ASTReader::ReadTemplateParameterList(ModuleFile &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6820 | const RecordData &Record, unsigned &Idx) { |
| 6821 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 6822 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 6823 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6824 | |
| 6825 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6826 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6827 | Params.reserve(NumParams); |
| 6828 | while (NumParams--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6829 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6830 | |
| 6831 | TemplateParameterList* TemplateParams = |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6832 | TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6833 | Params.data(), Params.size(), RAngleLoc); |
| 6834 | return TemplateParams; |
| 6835 | } |
| 6836 | |
| 6837 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6838 | ASTReader:: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6839 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6840 | ModuleFile &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6841 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6842 | unsigned NumTemplateArgs = Record[Idx++]; |
| 6843 | TemplArgs.reserve(NumTemplateArgs); |
| 6844 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6845 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6846 | } |
| 6847 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6848 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6849 | void ASTReader::ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6850 | const RecordData &Record, unsigned &Idx) { |
| 6851 | unsigned NumDecls = Record[Idx++]; |
| 6852 | while (NumDecls--) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6853 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6854 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 6855 | Set.addDecl(D, AS); |
| 6856 | } |
| 6857 | } |
| 6858 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6859 | CXXBaseSpecifier |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6860 | ASTReader::ReadCXXBaseSpecifier(ModuleFile &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 6861 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6862 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 6863 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 6864 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6865 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6866 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 6867 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 6868 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6869 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 6870 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6871 | Result.setInheritConstructors(inheritConstructors); |
| 6872 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6873 | } |
| 6874 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6875 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6876 | ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6877 | unsigned &Idx) { |
| 6878 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6879 | unsigned NumInitializers = Record[Idx++]; |
| 6880 | if (NumInitializers) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6881 | CtorInitializers |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6882 | = new (Context) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6883 | for (unsigned i=0; i != NumInitializers; ++i) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6884 | TypeSourceInfo *TInfo = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6885 | bool IsBaseVirtual = false; |
| 6886 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6887 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6888 | |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6889 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 6890 | switch (Type) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6891 | case CTOR_INITIALIZER_BASE: |
| 6892 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6893 | IsBaseVirtual = Record[Idx++]; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6894 | break; |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6895 | |
| 6896 | case CTOR_INITIALIZER_DELEGATING: |
| 6897 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6898 | break; |
| 6899 | |
| 6900 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6901 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6902 | break; |
| 6903 | |
| 6904 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6905 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6906 | break; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6907 | } |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6908 | |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 6909 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6910 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6911 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 6912 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6913 | bool IsWritten = Record[Idx++]; |
| 6914 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6915 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6916 | if (IsWritten) { |
| 6917 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 6918 | } else { |
| 6919 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 6920 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 6921 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6922 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6923 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6924 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6925 | CXXCtorInitializer *BOMInit; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6926 | if (Type == CTOR_INITIALIZER_BASE) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6927 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, IsBaseVirtual, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6928 | LParenLoc, Init, RParenLoc, |
| 6929 | MemberOrEllipsisLoc); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6930 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6931 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, LParenLoc, |
| 6932 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6933 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6934 | if (Member) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6935 | BOMInit = new (Context) CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6936 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6937 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6938 | BOMInit = new (Context) CXXCtorInitializer(Context, IndirectMember, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6939 | MemberOrEllipsisLoc, LParenLoc, |
| 6940 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6941 | } else { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6942 | BOMInit = CXXCtorInitializer::Create(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6943 | LParenLoc, Init, RParenLoc, |
| 6944 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6945 | } |
| 6946 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 6947 | if (IsWritten) |
| 6948 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6949 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6950 | } |
| 6951 | } |
| 6952 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6953 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6954 | } |
| 6955 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6956 | NestedNameSpecifier * |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6957 | ASTReader::ReadNestedNameSpecifier(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6958 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6959 | unsigned N = Record[Idx++]; |
| 6960 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 6961 | for (unsigned I = 0; I != N; ++I) { |
| 6962 | NestedNameSpecifier::SpecifierKind Kind |
| 6963 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 6964 | switch (Kind) { |
| 6965 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6966 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6967 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6968 | break; |
| 6969 | } |
| 6970 | |
| 6971 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6972 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6973 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6974 | break; |
| 6975 | } |
| 6976 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 6977 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6978 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6979 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 6980 | break; |
| 6981 | } |
| 6982 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6983 | case NestedNameSpecifier::TypeSpec: |
| 6984 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6985 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 6986 | if (!T) |
| 6987 | return 0; |
| 6988 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6989 | bool Template = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6990 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6991 | break; |
| 6992 | } |
| 6993 | |
| 6994 | case NestedNameSpecifier::Global: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6995 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6996 | // No associated value, and there can't be a prefix. |
| 6997 | break; |
| 6998 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6999 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 7000 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 7001 | } |
| 7002 | return NNS; |
| 7003 | } |
| 7004 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7005 | NestedNameSpecifierLoc |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 7006 | ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7007 | unsigned &Idx) { |
| 7008 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 7009 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7010 | for (unsigned I = 0; I != N; ++I) { |
| 7011 | NestedNameSpecifier::SpecifierKind Kind |
| 7012 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 7013 | switch (Kind) { |
| 7014 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 7015 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7016 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 7017 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7018 | break; |
| 7019 | } |
| 7020 | |
| 7021 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 7022 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7023 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 7024 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7025 | break; |
| 7026 | } |
| 7027 | |
| 7028 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 7029 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7030 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 7031 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7032 | break; |
| 7033 | } |
| 7034 | |
| 7035 | case NestedNameSpecifier::TypeSpec: |
| 7036 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7037 | bool Template = Record[Idx++]; |
| 7038 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 7039 | if (!T) |
| 7040 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7041 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 7042 | |
| 7043 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 7044 | Builder.Extend(Context, |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 7045 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 7046 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7047 | break; |
| 7048 | } |
| 7049 | |
| 7050 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7051 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 7052 | Builder.MakeGlobal(Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7053 | break; |
| 7054 | } |
| 7055 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7056 | } |
| 7057 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 7058 | return Builder.getWithLocInContext(Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 7059 | } |
| 7060 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 7061 | SourceRange |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 7062 | ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 7063 | unsigned &Idx) { |
| 7064 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 7065 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 7066 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 7067 | } |
| 7068 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 7069 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 7070 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 7071 | unsigned BitWidth = Record[Idx++]; |
| 7072 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 7073 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 7074 | Idx += NumWords; |
| 7075 | return Result; |
| 7076 | } |
| 7077 | |
| 7078 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 7079 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 7080 | bool isUnsigned = Record[Idx++]; |
| 7081 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 7082 | } |
| 7083 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 7084 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 7085 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 7086 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 7087 | } |
| 7088 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 7089 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 7090 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 7091 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 7092 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 7093 | Idx += Len; |
| 7094 | return Result; |
| 7095 | } |
| 7096 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 7097 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 7098 | unsigned &Idx) { |
| 7099 | unsigned Major = Record[Idx++]; |
| 7100 | unsigned Minor = Record[Idx++]; |
| 7101 | unsigned Subminor = Record[Idx++]; |
| 7102 | if (Minor == 0) |
| 7103 | return VersionTuple(Major); |
| 7104 | if (Subminor == 0) |
| 7105 | return VersionTuple(Major, Minor - 1); |
| 7106 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 7107 | } |
| 7108 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 7109 | CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 7110 | const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 7111 | unsigned &Idx) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 7112 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 7113 | return CXXTemporary::Create(Context, Decl); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 7114 | } |
| 7115 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 7116 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 7117 | return Diag(SourceLocation(), DiagID); |
| 7118 | } |
| 7119 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 7120 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7121 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 7122 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 7123 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 7124 | /// \brief Retrieve the identifier table associated with the |
| 7125 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 7126 | IdentifierTable &ASTReader::getIdentifierTable() { |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 7127 | return PP.getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 7128 | } |
| 7129 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 7130 | /// \brief Record that the given ID maps to the given switch-case |
| 7131 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 7132 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 7133 | assert((*CurrSwitchCaseStmts)[ID] == 0 && |
| 7134 | "Already have a SwitchCase with this ID"); |
| 7135 | (*CurrSwitchCaseStmts)[ID] = SC; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 7136 | } |
| 7137 | |
| 7138 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 7139 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 7140 | assert((*CurrSwitchCaseStmts)[ID] != 0 && "No SwitchCase with this ID"); |
| 7141 | return (*CurrSwitchCaseStmts)[ID]; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 7142 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 7143 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 7144 | void ASTReader::ClearSwitchCaseIDs() { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 7145 | CurrSwitchCaseStmts->clear(); |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 7146 | } |
| 7147 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 7148 | void ASTReader::ReadComments() { |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 7149 | std::vector<RawComment *> Comments; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 7150 | for (SmallVectorImpl<std::pair<llvm::BitstreamCursor, |
| 7151 | serialization::ModuleFile *> >::iterator |
| 7152 | I = CommentsCursors.begin(), |
| 7153 | E = CommentsCursors.end(); |
| 7154 | I != E; ++I) { |
| 7155 | llvm::BitstreamCursor &Cursor = I->first; |
| 7156 | serialization::ModuleFile &F = *I->second; |
| 7157 | SavedStreamPosition SavedPosition(Cursor); |
| 7158 | |
| 7159 | RecordData Record; |
| 7160 | while (true) { |
| 7161 | unsigned Code = Cursor.ReadCode(); |
| 7162 | if (Code == llvm::bitc::END_BLOCK) |
| 7163 | break; |
| 7164 | |
| 7165 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 7166 | // No known subblocks, always skip them. |
| 7167 | Cursor.ReadSubBlockID(); |
| 7168 | if (Cursor.SkipBlock()) { |
| 7169 | Error("malformed block record in AST file"); |
| 7170 | return; |
| 7171 | } |
| 7172 | continue; |
| 7173 | } |
| 7174 | |
| 7175 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 7176 | Cursor.ReadAbbrevRecord(); |
| 7177 | continue; |
| 7178 | } |
| 7179 | |
| 7180 | // Read a record. |
| 7181 | Record.clear(); |
| 7182 | switch ((CommentRecordTypes) Cursor.ReadRecord(Code, Record)) { |
Chandler Carruth | 13691bb | 2012-06-20 06:47:54 +0000 | [diff] [blame] | 7183 | case COMMENTS_RAW_COMMENT: { |
| 7184 | unsigned Idx = 0; |
| 7185 | SourceRange SR = ReadSourceRange(F, Record, Idx); |
| 7186 | RawComment::CommentKind Kind = |
| 7187 | (RawComment::CommentKind) Record[Idx++]; |
| 7188 | bool IsTrailingComment = Record[Idx++]; |
| 7189 | bool IsAlmostTrailingComment = Record[Idx++]; |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 7190 | Comments.push_back(new (Context) RawComment(SR, Kind, |
| 7191 | IsTrailingComment, |
| 7192 | IsAlmostTrailingComment)); |
Chandler Carruth | 13691bb | 2012-06-20 06:47:54 +0000 | [diff] [blame] | 7193 | break; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 7194 | } |
| 7195 | } |
| 7196 | } |
| 7197 | } |
| 7198 | Context.Comments.addCommentsToFront(Comments); |
| 7199 | } |
| 7200 | |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 7201 | void ASTReader::finishPendingActions() { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 7202 | while (!PendingIdentifierInfos.empty() || !PendingDeclChains.empty() || |
| 7203 | !PendingMacroIDs.empty()) { |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 7204 | // If any identifiers with corresponding top-level declarations have |
| 7205 | // been loaded, load those declarations now. |
| 7206 | while (!PendingIdentifierInfos.empty()) { |
| 7207 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 7208 | PendingIdentifierInfos.front().DeclIDs, true); |
| 7209 | PendingIdentifierInfos.pop_front(); |
| 7210 | } |
| 7211 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 7212 | // Load pending declaration chains. |
| 7213 | for (unsigned I = 0; I != PendingDeclChains.size(); ++I) { |
| 7214 | loadPendingDeclChain(PendingDeclChains[I]); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 7215 | PendingDeclChainsKnown.erase(PendingDeclChains[I]); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 7216 | } |
| 7217 | PendingDeclChains.clear(); |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 7218 | |
| 7219 | // Load any pending macro definitions. |
Douglas Gregor | e9652bf | 2012-10-11 17:31:34 +0000 | [diff] [blame] | 7220 | for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) { |
| 7221 | // FIXME: std::move here |
| 7222 | SmallVector<MacroID, 2> GlobalIDs = PendingMacroIDs.begin()[I].second; |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 7223 | MacroInfo *Hint = 0; |
Douglas Gregor | e9652bf | 2012-10-11 17:31:34 +0000 | [diff] [blame] | 7224 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
| 7225 | ++IDIdx) { |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 7226 | Hint = getMacro(GlobalIDs[IDIdx], Hint); |
Douglas Gregor | e9652bf | 2012-10-11 17:31:34 +0000 | [diff] [blame] | 7227 | } |
| 7228 | } |
| 7229 | PendingMacroIDs.clear(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 7230 | } |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 7231 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 7232 | // If we deserialized any C++ or Objective-C class definitions, any |
| 7233 | // Objective-C protocol definitions, or any redeclarable templates, make sure |
| 7234 | // that all redeclarations point to the definitions. Note that this can only |
| 7235 | // happen now, after the redeclaration chains have been fully wired. |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 7236 | for (llvm::SmallPtrSet<Decl *, 4>::iterator D = PendingDefinitions.begin(), |
| 7237 | DEnd = PendingDefinitions.end(); |
| 7238 | D != DEnd; ++D) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 7239 | if (TagDecl *TD = dyn_cast<TagDecl>(*D)) { |
| 7240 | if (const TagType *TagT = dyn_cast<TagType>(TD->TypeForDecl)) { |
| 7241 | // Make sure that the TagType points at the definition. |
| 7242 | const_cast<TagType*>(TagT)->decl = TD; |
| 7243 | } |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 7244 | |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 7245 | if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(*D)) { |
| 7246 | for (CXXRecordDecl::redecl_iterator R = RD->redecls_begin(), |
| 7247 | REnd = RD->redecls_end(); |
| 7248 | R != REnd; ++R) |
| 7249 | cast<CXXRecordDecl>(*R)->DefinitionData = RD->DefinitionData; |
| 7250 | |
| 7251 | } |
| 7252 | |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 7253 | continue; |
| 7254 | } |
| 7255 | |
Douglas Gregor | 1d784b2 | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 7256 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(*D)) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 7257 | // Make sure that the ObjCInterfaceType points at the definition. |
| 7258 | const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl)) |
| 7259 | ->Decl = ID; |
| 7260 | |
Douglas Gregor | 1d784b2 | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 7261 | for (ObjCInterfaceDecl::redecl_iterator R = ID->redecls_begin(), |
| 7262 | REnd = ID->redecls_end(); |
| 7263 | R != REnd; ++R) |
| 7264 | R->Data = ID->Data; |
| 7265 | |
| 7266 | continue; |
| 7267 | } |
| 7268 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 7269 | if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(*D)) { |
| 7270 | for (ObjCProtocolDecl::redecl_iterator R = PD->redecls_begin(), |
| 7271 | REnd = PD->redecls_end(); |
| 7272 | R != REnd; ++R) |
| 7273 | R->Data = PD->Data; |
| 7274 | |
| 7275 | continue; |
| 7276 | } |
| 7277 | |
| 7278 | RedeclarableTemplateDecl *RTD |
| 7279 | = cast<RedeclarableTemplateDecl>(*D)->getCanonicalDecl(); |
| 7280 | for (RedeclarableTemplateDecl::redecl_iterator R = RTD->redecls_begin(), |
| 7281 | REnd = RTD->redecls_end(); |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 7282 | R != REnd; ++R) |
Douglas Gregor | 5456b0fe | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 7283 | R->Common = RTD->Common; |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 7284 | } |
| 7285 | PendingDefinitions.clear(); |
Douglas Gregor | 5456b0fe | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 7286 | |
| 7287 | // Load the bodies of any functions or methods we've encountered. We do |
| 7288 | // this now (delayed) so that we can be sure that the declaration chains |
| 7289 | // have been fully wired up. |
Douglas Gregor | ce12d2f | 2012-10-09 17:50:23 +0000 | [diff] [blame] | 7290 | for (PendingBodiesMap::iterator PB = PendingBodies.begin(), |
| 7291 | PBEnd = PendingBodies.end(); |
Douglas Gregor | 5456b0fe | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 7292 | PB != PBEnd; ++PB) { |
| 7293 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) { |
| 7294 | // FIXME: Check for =delete/=default? |
| 7295 | // FIXME: Complain about ODR violations here? |
| 7296 | if (!getContext().getLangOpts().Modules || !FD->hasBody()) |
| 7297 | FD->setLazyBody(PB->second); |
| 7298 | continue; |
| 7299 | } |
| 7300 | |
| 7301 | ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first); |
| 7302 | if (!getContext().getLangOpts().Modules || !MD->hasBody()) |
| 7303 | MD->setLazyBody(PB->second); |
| 7304 | } |
| 7305 | PendingBodies.clear(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 7306 | } |
| 7307 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 7308 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 7309 | assert(NumCurrentElementsDeserializing && |
| 7310 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 7311 | if (NumCurrentElementsDeserializing == 1) { |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 7312 | // We decrease NumCurrentElementsDeserializing only after pending actions |
| 7313 | // are finished, to avoid recursively re-calling finishPendingActions(). |
| 7314 | finishPendingActions(); |
| 7315 | } |
| 7316 | --NumCurrentElementsDeserializing; |
Argyrios Kyrtzidis | 7116833 | 2011-12-17 04:13:28 +0000 | [diff] [blame] | 7317 | |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 7318 | if (NumCurrentElementsDeserializing == 0 && |
| 7319 | Consumer && !PassingDeclsToConsumer) { |
| 7320 | // Guard variable to avoid recursively redoing the process of passing |
| 7321 | // decls to consumer. |
| 7322 | SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer, |
| 7323 | true); |
Argyrios Kyrtzidis | 7116833 | 2011-12-17 04:13:28 +0000 | [diff] [blame] | 7324 | |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 7325 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 7326 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 7327 | // decls to the consumer. |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 7328 | Decl *D = InterestingDecls.front(); |
| 7329 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 7330 | PassInterestingDeclToConsumer(D); |
| 7331 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 7332 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 7333 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 7334 | |
Douglas Gregor | f8a1e51 | 2011-09-02 00:26:20 +0000 | [diff] [blame] | 7335 | ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 7336 | StringRef isysroot, bool DisableValidation, |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 7337 | bool DisableStatCache, bool AllowASTWithCompilerErrors) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 7338 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 7339 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 7340 | Diags(PP.getDiagnostics()), SemaObj(0), PP(PP), Context(Context), |
Argyrios Kyrtzidis | d64c26f | 2012-10-03 01:58:42 +0000 | [diff] [blame] | 7341 | Consumer(0), ModuleMgr(PP.getFileManager()), |
Douglas Gregor | caed060 | 2012-10-18 21:31:35 +0000 | [diff] [blame] | 7342 | isysroot(isysroot), DisableValidation(DisableValidation), |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 7343 | DisableStatCache(DisableStatCache), |
| 7344 | AllowASTWithCompilerErrors(AllowASTWithCompilerErrors), |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 7345 | CurrentGeneration(0), CurrSwitchCaseStmts(&SwitchCaseStmts), |
| 7346 | NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 7347 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 7348 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 7349 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 7350 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 7351 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 7352 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 7353 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 7354 | PassingDeclsToConsumer(false), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 7355 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 7356 | { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 7357 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 7358 | } |
| 7359 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 7360 | ASTReader::~ASTReader() { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 7361 | for (DeclContextVisibleUpdatesPending::iterator |
| 7362 | I = PendingVisibleUpdates.begin(), |
| 7363 | E = PendingVisibleUpdates.end(); |
| 7364 | I != E; ++I) { |
| 7365 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 7366 | F = I->second.end(); |
| 7367 | J != F; ++J) |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 7368 | delete J->first; |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 7369 | } |
| 7370 | } |