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(); |
Douglas Gregor | a9b8da4 | 2012-10-25 00:25:27 +0000 | [diff] [blame] | 280 | SuggestedPredefines += ' '; |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 281 | SuggestedPredefines += Existing.first.str(); |
| 282 | SuggestedPredefines += '\n'; |
| 283 | } |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 284 | continue; |
| 285 | } |
| 286 | |
| 287 | // If the macro was defined in one but undef'd in the other, we have a |
| 288 | // conflict. |
| 289 | if (Existing.second != Known->second.second) { |
| 290 | if (Diags) { |
| 291 | Diags->Report(diag::err_pch_macro_def_undef) |
| 292 | << MacroName << Known->second.second; |
| 293 | } |
| 294 | return true; |
| 295 | } |
| 296 | |
| 297 | // If the macro was #undef'd in both, or if the macro bodies are identical, |
| 298 | // it's fine. |
| 299 | if (Existing.second || Existing.first == Known->second.first) |
| 300 | continue; |
| 301 | |
| 302 | // The macro bodies differ; complain. |
| 303 | if (Diags) { |
| 304 | Diags->Report(diag::err_pch_macro_def_conflict) |
| 305 | << MacroName << Known->second.first << Existing.first; |
| 306 | } |
| 307 | return true; |
| 308 | } |
| 309 | |
| 310 | // Check whether we're using predefines. |
| 311 | if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines) { |
| 312 | if (Diags) { |
| 313 | Diags->Report(diag::err_pch_undef) << ExistingPPOpts.UsePredefines; |
| 314 | } |
| 315 | return true; |
| 316 | } |
| 317 | |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 318 | // Compute the #include and #include_macros lines we need. |
| 319 | for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) { |
| 320 | StringRef File = ExistingPPOpts.Includes[I]; |
| 321 | if (File == ExistingPPOpts.ImplicitPCHInclude) |
| 322 | continue; |
| 323 | |
| 324 | if (std::find(PPOpts.Includes.begin(), PPOpts.Includes.end(), File) |
| 325 | != PPOpts.Includes.end()) |
| 326 | continue; |
| 327 | |
| 328 | SuggestedPredefines += "#include \""; |
| 329 | SuggestedPredefines += |
| 330 | HeaderSearch::NormalizeDashIncludePath(File, FileMgr); |
| 331 | SuggestedPredefines += "\"\n"; |
| 332 | } |
| 333 | |
| 334 | for (unsigned I = 0, N = ExistingPPOpts.MacroIncludes.size(); I != N; ++I) { |
| 335 | StringRef File = ExistingPPOpts.MacroIncludes[I]; |
| 336 | if (std::find(PPOpts.MacroIncludes.begin(), PPOpts.MacroIncludes.end(), |
| 337 | File) |
| 338 | != PPOpts.MacroIncludes.end()) |
| 339 | continue; |
| 340 | |
| 341 | SuggestedPredefines += "#__include_macros \""; |
| 342 | SuggestedPredefines += |
| 343 | HeaderSearch::NormalizeDashIncludePath(File, FileMgr); |
| 344 | SuggestedPredefines += "\"\n##\n"; |
| 345 | } |
| 346 | |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 347 | return false; |
| 348 | } |
| 349 | |
| 350 | bool PCHValidator::ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 351 | bool Complain, |
| 352 | std::string &SuggestedPredefines) { |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 353 | const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts(); |
| 354 | |
| 355 | return checkPreprocessorOptions(PPOpts, ExistingPPOpts, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 356 | Complain? &Reader.Diags : 0, |
| 357 | PP.getFileManager(), |
| 358 | SuggestedPredefines); |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 361 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 362 | unsigned ID) { |
| 363 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 364 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Argyrios Kyrtzidis | 62288ed | 2012-10-10 02:12:47 +0000 | [diff] [blame] | 367 | void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 368 | PP.setCounterValue(Value); |
| 369 | } |
| 370 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 371 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 372 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 373 | //===----------------------------------------------------------------------===// |
| 374 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 375 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 376 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 377 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 378 | } |
| 379 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 380 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 381 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 382 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 383 | return serialization::ComputeHash(Sel); |
| 384 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 385 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 386 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 387 | std::pair<unsigned, unsigned> |
| 388 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 389 | using namespace clang::io; |
| 390 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 391 | unsigned DataLen = ReadUnalignedLE16(d); |
| 392 | return std::make_pair(KeyLen, DataLen); |
| 393 | } |
| 394 | |
| 395 | ASTSelectorLookupTrait::internal_key_type |
| 396 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 397 | using namespace clang::io; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 398 | SelectorTable &SelTable = Reader.getContext().Selectors; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 399 | unsigned N = ReadUnalignedLE16(d); |
| 400 | IdentifierInfo *FirstII |
| 401 | = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 402 | if (N == 0) |
| 403 | return SelTable.getNullarySelector(FirstII); |
| 404 | else if (N == 1) |
| 405 | return SelTable.getUnarySelector(FirstII); |
| 406 | |
| 407 | SmallVector<IdentifierInfo *, 16> Args; |
| 408 | Args.push_back(FirstII); |
| 409 | for (unsigned I = 1; I != N; ++I) |
| 410 | Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d))); |
| 411 | |
| 412 | return SelTable.getSelector(N, Args.data()); |
| 413 | } |
| 414 | |
| 415 | ASTSelectorLookupTrait::data_type |
| 416 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
| 417 | unsigned DataLen) { |
| 418 | using namespace clang::io; |
| 419 | |
| 420 | data_type Result; |
| 421 | |
| 422 | Result.ID = Reader.getGlobalSelectorID(F, ReadUnalignedLE32(d)); |
| 423 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 424 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 425 | |
| 426 | // Load instance methods |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 427 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
| 428 | if (ObjCMethodDecl *Method |
| 429 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 430 | Result.Instance.push_back(Method); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 431 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 433 | // Load factory methods |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 434 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
| 435 | if (ObjCMethodDecl *Method |
| 436 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 437 | Result.Factory.push_back(Method); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 438 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 439 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 440 | return Result; |
| 441 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 442 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 443 | unsigned ASTIdentifierLookupTrait::ComputeHash(const internal_key_type& a) { |
| 444 | return llvm::HashString(StringRef(a.first, a.second)); |
| 445 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 447 | std::pair<unsigned, unsigned> |
| 448 | ASTIdentifierLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 449 | using namespace clang::io; |
| 450 | unsigned DataLen = ReadUnalignedLE16(d); |
| 451 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 452 | return std::make_pair(KeyLen, DataLen); |
| 453 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 454 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 455 | std::pair<const char*, unsigned> |
| 456 | ASTIdentifierLookupTrait::ReadKey(const unsigned char* d, unsigned n) { |
| 457 | assert(n >= 2 && d[n-1] == '\0'); |
| 458 | return std::make_pair((const char*) d, n-1); |
| 459 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 460 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 461 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 462 | const unsigned char* d, |
| 463 | unsigned DataLen) { |
| 464 | using namespace clang::io; |
| 465 | unsigned RawID = ReadUnalignedLE32(d); |
| 466 | bool IsInteresting = RawID & 0x01; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 467 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 468 | // Wipe out the "is interesting" bit. |
| 469 | RawID = RawID >> 1; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 470 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 471 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 472 | if (!IsInteresting) { |
| 473 | // For uninteresting identifiers, just build the IdentifierInfo |
| 474 | // and associate it with the persistent ID. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 475 | IdentifierInfo *II = KnownII; |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 476 | if (!II) { |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 477 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 478 | KnownII = II; |
| 479 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 480 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 481 | II->setIsFromAST(); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 482 | Reader.markIdentifierUpToDate(II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 483 | return II; |
| 484 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 485 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 486 | unsigned ObjCOrBuiltinID = ReadUnalignedLE16(d); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 487 | unsigned Bits = ReadUnalignedLE16(d); |
| 488 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 489 | Bits >>= 1; |
| 490 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 491 | Bits >>= 1; |
| 492 | bool Poisoned = Bits & 0x01; |
| 493 | Bits >>= 1; |
| 494 | bool ExtensionToken = Bits & 0x01; |
| 495 | Bits >>= 1; |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 496 | bool hadMacroDefinition = Bits & 0x01; |
| 497 | Bits >>= 1; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 498 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 499 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 500 | DataLen -= 8; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 501 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 502 | // Build the IdentifierInfo itself and link the identifier ID with |
| 503 | // the new IdentifierInfo. |
| 504 | IdentifierInfo *II = KnownII; |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 505 | if (!II) { |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 506 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 507 | KnownII = II; |
| 508 | } |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 509 | Reader.markIdentifierUpToDate(II); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 510 | II->setIsFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 511 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 512 | // Set or check the various bits in the IdentifierInfo structure. |
| 513 | // Token IDs are read-only. |
| 514 | if (HasRevertedTokenIDToIdentifier) |
| 515 | II->RevertTokenIDToIdentifier(); |
| 516 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 517 | assert(II->isExtensionToken() == ExtensionToken && |
| 518 | "Incorrect extension token flag"); |
| 519 | (void)ExtensionToken; |
| 520 | if (Poisoned) |
| 521 | II->setIsPoisoned(true); |
| 522 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 523 | "Incorrect C++ operator keyword flag"); |
| 524 | (void)CPlusPlusOperatorKeyword; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 525 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 526 | // If this identifier is a macro, deserialize the macro |
| 527 | // definition. |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 528 | if (hadMacroDefinition) { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 529 | SmallVector<MacroID, 4> MacroIDs; |
| 530 | while (uint32_t LocalID = ReadUnalignedLE32(d)) { |
| 531 | MacroIDs.push_back(Reader.getGlobalMacroID(F, LocalID)); |
| 532 | DataLen -= 4; |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 533 | } |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 534 | DataLen -= 4; |
| 535 | Reader.setIdentifierIsMacro(II, MacroIDs); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 538 | Reader.SetIdentifierInfo(ID, II); |
| 539 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 540 | // Read all of the declarations visible at global scope with this |
| 541 | // name. |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 542 | if (DataLen > 0) { |
| 543 | SmallVector<uint32_t, 4> DeclIDs; |
| 544 | for (; DataLen > 0; DataLen -= 4) |
| 545 | DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); |
| 546 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 549 | return II; |
| 550 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 551 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 552 | unsigned |
| 553 | ASTDeclContextNameLookupTrait::ComputeHash(const DeclNameKey &Key) const { |
| 554 | llvm::FoldingSetNodeID ID; |
| 555 | ID.AddInteger(Key.Kind); |
| 556 | |
| 557 | switch (Key.Kind) { |
| 558 | case DeclarationName::Identifier: |
| 559 | case DeclarationName::CXXLiteralOperatorName: |
| 560 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 561 | break; |
| 562 | case DeclarationName::ObjCZeroArgSelector: |
| 563 | case DeclarationName::ObjCOneArgSelector: |
| 564 | case DeclarationName::ObjCMultiArgSelector: |
| 565 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 566 | break; |
| 567 | case DeclarationName::CXXOperatorName: |
| 568 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 569 | break; |
| 570 | case DeclarationName::CXXConstructorName: |
| 571 | case DeclarationName::CXXDestructorName: |
| 572 | case DeclarationName::CXXConversionFunctionName: |
| 573 | case DeclarationName::CXXUsingDirective: |
| 574 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 577 | return ID.ComputeHash(); |
| 578 | } |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 579 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 580 | ASTDeclContextNameLookupTrait::internal_key_type |
| 581 | ASTDeclContextNameLookupTrait::GetInternalKey( |
| 582 | const external_key_type& Name) const { |
| 583 | DeclNameKey Key; |
| 584 | Key.Kind = Name.getNameKind(); |
| 585 | switch (Name.getNameKind()) { |
| 586 | case DeclarationName::Identifier: |
| 587 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 588 | break; |
| 589 | case DeclarationName::ObjCZeroArgSelector: |
| 590 | case DeclarationName::ObjCOneArgSelector: |
| 591 | case DeclarationName::ObjCMultiArgSelector: |
| 592 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 593 | break; |
| 594 | case DeclarationName::CXXOperatorName: |
| 595 | Key.Data = Name.getCXXOverloadedOperator(); |
| 596 | break; |
| 597 | case DeclarationName::CXXLiteralOperatorName: |
| 598 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 599 | break; |
| 600 | case DeclarationName::CXXConstructorName: |
| 601 | case DeclarationName::CXXDestructorName: |
| 602 | case DeclarationName::CXXConversionFunctionName: |
| 603 | case DeclarationName::CXXUsingDirective: |
| 604 | Key.Data = 0; |
| 605 | break; |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 608 | return Key; |
| 609 | } |
| 610 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 611 | std::pair<unsigned, unsigned> |
| 612 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 613 | using namespace clang::io; |
| 614 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 615 | unsigned DataLen = ReadUnalignedLE16(d); |
| 616 | return std::make_pair(KeyLen, DataLen); |
| 617 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 618 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 619 | ASTDeclContextNameLookupTrait::internal_key_type |
| 620 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 621 | using namespace clang::io; |
| 622 | |
| 623 | DeclNameKey Key; |
| 624 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 625 | switch (Key.Kind) { |
| 626 | case DeclarationName::Identifier: |
| 627 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 628 | break; |
| 629 | case DeclarationName::ObjCZeroArgSelector: |
| 630 | case DeclarationName::ObjCOneArgSelector: |
| 631 | case DeclarationName::ObjCMultiArgSelector: |
| 632 | Key.Data = |
| 633 | (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d)) |
| 634 | .getAsOpaquePtr(); |
| 635 | break; |
| 636 | case DeclarationName::CXXOperatorName: |
| 637 | Key.Data = *d++; // OverloadedOperatorKind |
| 638 | break; |
| 639 | case DeclarationName::CXXLiteralOperatorName: |
| 640 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 641 | break; |
| 642 | case DeclarationName::CXXConstructorName: |
| 643 | case DeclarationName::CXXDestructorName: |
| 644 | case DeclarationName::CXXConversionFunctionName: |
| 645 | case DeclarationName::CXXUsingDirective: |
| 646 | Key.Data = 0; |
| 647 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 648 | } |
| 649 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 650 | return Key; |
| 651 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 652 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 653 | ASTDeclContextNameLookupTrait::data_type |
| 654 | ASTDeclContextNameLookupTrait::ReadData(internal_key_type, |
| 655 | const unsigned char* d, |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 656 | unsigned DataLen) { |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 657 | using namespace clang::io; |
| 658 | unsigned NumDecls = ReadUnalignedLE16(d); |
Douglas Gregor | 9b8b20f | 2012-01-06 16:09:53 +0000 | [diff] [blame] | 659 | LE32DeclID *Start = (LE32DeclID *)d; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 660 | return std::make_pair(Start, Start + NumDecls); |
| 661 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 662 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 663 | bool ASTReader::ReadDeclContextStorage(ModuleFile &M, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 664 | llvm::BitstreamCursor &Cursor, |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 665 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 666 | DeclContextInfo &Info) { |
| 667 | SavedStreamPosition SavedPosition(Cursor); |
| 668 | // First the lexical decls. |
| 669 | if (Offsets.first != 0) { |
| 670 | Cursor.JumpToBit(Offsets.first); |
| 671 | |
| 672 | RecordData Record; |
| 673 | const char *Blob; |
| 674 | unsigned BlobLen; |
| 675 | unsigned Code = Cursor.ReadCode(); |
| 676 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 677 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 678 | Error("Expected lexical block"); |
| 679 | return true; |
| 680 | } |
| 681 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 682 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 683 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | // Now the lookup table. |
| 687 | if (Offsets.second != 0) { |
| 688 | Cursor.JumpToBit(Offsets.second); |
| 689 | |
| 690 | RecordData Record; |
| 691 | const char *Blob; |
| 692 | unsigned BlobLen; |
| 693 | unsigned Code = Cursor.ReadCode(); |
| 694 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 695 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 696 | Error("Expected visible lookup table block"); |
| 697 | return true; |
| 698 | } |
| 699 | Info.NameLookupTableData |
| 700 | = ASTDeclContextNameLookupTable::Create( |
| 701 | (const unsigned char *)Blob + Record[0], |
| 702 | (const unsigned char *)Blob, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 703 | ASTDeclContextNameLookupTrait(*this, M)); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | return false; |
| 707 | } |
| 708 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 709 | void ASTReader::Error(StringRef Msg) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 710 | Error(diag::err_fe_pch_malformed, Msg); |
| 711 | } |
| 712 | |
| 713 | void ASTReader::Error(unsigned DiagID, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 714 | StringRef Arg1, StringRef Arg2) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 715 | if (Diags.isDiagnosticInFlight()) |
| 716 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 717 | else |
| 718 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 719 | } |
| 720 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 721 | //===----------------------------------------------------------------------===// |
| 722 | // Source Manager Deserialization |
| 723 | //===----------------------------------------------------------------------===// |
| 724 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 725 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 726 | /// \returns true if there was an error. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 727 | bool ASTReader::ParseLineTable(ModuleFile &F, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 728 | SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 729 | unsigned Idx = 0; |
| 730 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 731 | |
| 732 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 733 | std::map<int, int> FileIDs; |
| 734 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 735 | // Extract the file name |
| 736 | unsigned FilenameLen = Record[Idx++]; |
| 737 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 738 | Idx += FilenameLen; |
Douglas Gregor | caed060 | 2012-10-18 21:31:35 +0000 | [diff] [blame] | 739 | MaybeAddSystemRootToFilename(F, Filename); |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 740 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | // Parse the line entries |
| 744 | std::vector<LineEntry> Entries; |
| 745 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 746 | int FID = Record[Idx++]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 747 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 748 | // Remap FileID from 1-based old view. |
| 749 | FID += F.SLocEntryBaseID - 1; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 750 | |
| 751 | // Extract the line entries |
| 752 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 753 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 754 | Entries.clear(); |
| 755 | Entries.reserve(NumEntries); |
| 756 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 757 | unsigned FileOffset = Record[Idx++]; |
| 758 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 759 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 760 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 761 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 762 | unsigned IncludeOffset = Record[Idx++]; |
| 763 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 764 | FileKind, IncludeOffset)); |
| 765 | } |
Douglas Gregor | 47d9de6 | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 766 | LineTable.AddEntry(FileID::get(FID), Entries); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | return false; |
| 770 | } |
| 771 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 772 | namespace { |
| 773 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 774 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 775 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 776 | const ino_t ino; |
| 777 | const dev_t dev; |
| 778 | const mode_t mode; |
| 779 | const time_t mtime; |
| 780 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 781 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 782 | 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] | 783 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 784 | }; |
| 785 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 786 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 787 | public: |
| 788 | typedef const char *external_key_type; |
| 789 | typedef const char *internal_key_type; |
| 790 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 791 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 792 | |
| 793 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 794 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 798 | |
| 799 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 800 | return strcmp(a, b) == 0; |
| 801 | } |
| 802 | |
| 803 | static std::pair<unsigned, unsigned> |
| 804 | ReadKeyDataLength(const unsigned char*& d) { |
| 805 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 806 | unsigned DataLen = (unsigned) *d++; |
| 807 | return std::make_pair(KeyLen + 1, DataLen); |
| 808 | } |
| 809 | |
| 810 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 811 | return (const char *)d; |
| 812 | } |
| 813 | |
| 814 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 815 | unsigned /*DataLen*/) { |
| 816 | using namespace clang::io; |
| 817 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 818 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 819 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 820 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 821 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 822 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 823 | return data_type(ino, dev, mode, mtime, size); |
| 824 | } |
| 825 | }; |
| 826 | |
| 827 | /// \brief stat() cache for precompiled headers. |
| 828 | /// |
| 829 | /// This cache is very similar to the stat cache used by pretokenized |
| 830 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 831 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 832 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 833 | CacheTy *Cache; |
| 834 | |
| 835 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 836 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 837 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 838 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 839 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 840 | Cache = CacheTy::Create(Buckets, Base); |
| 841 | } |
| 842 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 843 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 844 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 845 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 846 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 847 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 848 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 849 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 850 | // 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] | 851 | if (I == Cache->end()) { |
| 852 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 853 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 854 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 855 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 856 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 857 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 858 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 859 | StatBuf.st_ino = Data.ino; |
| 860 | StatBuf.st_dev = Data.dev; |
| 861 | StatBuf.st_mtime = Data.mtime; |
| 862 | StatBuf.st_mode = Data.mode; |
| 863 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 864 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 865 | } |
| 866 | }; |
| 867 | } // end anonymous namespace |
| 868 | |
| 869 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 870 | /// \brief Read a source manager block |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 871 | bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 872 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 873 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 874 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 875 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 876 | // Set the source-location entry cursor to the current position in |
| 877 | // the stream. This cursor will be used to read the contents of the |
| 878 | // source manager block initially, and then lazily read |
| 879 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 880 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 881 | |
| 882 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 883 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 884 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 885 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 889 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 890 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 891 | return true; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 892 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 893 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 894 | RecordData Record; |
| 895 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 896 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 897 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 898 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 899 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 900 | return true; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 901 | } |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 902 | return false; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 903 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 904 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 905 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 906 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 907 | SLocEntryCursor.ReadSubBlockID(); |
| 908 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 909 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 910 | return true; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 911 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 912 | continue; |
| 913 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 914 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 915 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 916 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 917 | continue; |
| 918 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 919 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 920 | // Read a record. |
| 921 | const char *BlobStart; |
| 922 | unsigned BlobLen; |
| 923 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 924 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 925 | default: // Default behavior: ignore. |
| 926 | break; |
| 927 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 928 | case SM_SLOC_FILE_ENTRY: |
| 929 | case SM_SLOC_BUFFER_ENTRY: |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 930 | case SM_SLOC_EXPANSION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 931 | // Once we hit one of the source location entries, we're done. |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 932 | return false; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | } |
| 936 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 937 | /// \brief If a header file is not found at the path that we expect it to be |
| 938 | /// and the PCH file was moved from its original location, try to resolve the |
| 939 | /// file by assuming that header+PCH were moved together and the header is in |
| 940 | /// the same place relative to the PCH. |
| 941 | static std::string |
| 942 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 943 | const std::string &OriginalDir, |
| 944 | const std::string &CurrDir) { |
| 945 | assert(OriginalDir != CurrDir && |
| 946 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 947 | using namespace llvm::sys; |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 948 | SmallString<128> filePath(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 949 | fs::make_absolute(filePath); |
| 950 | assert(path::is_absolute(OriginalDir)); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 951 | SmallString<128> currPCHPath(CurrDir); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 952 | |
| 953 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 954 | fileDirE = path::end(path::parent_path(filePath)); |
| 955 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 956 | origDirE = path::end(OriginalDir); |
| 957 | // Skip the common path components from filePath and OriginalDir. |
| 958 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 959 | *fileDirI == *origDirI) { |
| 960 | ++fileDirI; |
| 961 | ++origDirI; |
| 962 | } |
| 963 | for (; origDirI != origDirE; ++origDirI) |
| 964 | path::append(currPCHPath, ".."); |
| 965 | path::append(currPCHPath, fileDirI, fileDirE); |
| 966 | path::append(currPCHPath, path::filename(Filename)); |
| 967 | return currPCHPath.str(); |
| 968 | } |
| 969 | |
Douglas Gregor | 8b53d14 | 2012-10-22 22:53:10 +0000 | [diff] [blame] | 970 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 971 | if (ID == 0) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 972 | return false; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 973 | |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 974 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 975 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 976 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 977 | } |
| 978 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 979 | ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 980 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 981 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 982 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 983 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 984 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 985 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 986 | if (Code == llvm::bitc::END_BLOCK || |
| 987 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 988 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 989 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 990 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 991 | } |
| 992 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 993 | RecordData Record; |
| 994 | const char *BlobStart; |
| 995 | unsigned BlobLen; |
| 996 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 997 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 998 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 999 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1000 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1001 | case SM_SLOC_FILE_ENTRY: { |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 1002 | // We will detect whether a file changed and return 'Failure' for it, but |
| 1003 | // we will also try to fail gracefully by setting up the SLocEntry. |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1004 | unsigned InputID = Record[4]; |
| 1005 | InputFile IF = getInputFile(*F, InputID); |
| 1006 | const FileEntry *File = IF.getPointer(); |
| 1007 | bool OverriddenBuffer = IF.getInt(); |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 1008 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1009 | if (!IF.getPointer()) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1010 | return true; |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1011 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1012 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1013 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1014 | // This is the module's main file. |
| 1015 | IncludeLoc = getImportLocation(F); |
| 1016 | } |
Argyrios Kyrtzidis | ff39896 | 2012-07-11 20:59:04 +0000 | [diff] [blame] | 1017 | SrcMgr::CharacteristicKind |
| 1018 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1019 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter, |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1020 | ID, BaseOffset + Record[0]); |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1021 | SrcMgr::FileInfo &FileInfo = |
| 1022 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1023 | FileInfo.NumCreatedFIDs = Record[5]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1024 | if (Record[3]) |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1025 | FileInfo.setHasLineDirectives(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1026 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1027 | const DeclID *FirstDecl = F->FileSortedDecls + Record[6]; |
| 1028 | unsigned NumFileDecls = Record[7]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1029 | if (NumFileDecls) { |
| 1030 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
Argyrios Kyrtzidis | 9d128d0 | 2011-10-31 07:20:08 +0000 | [diff] [blame] | 1031 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 1032 | NumFileDecls)); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1033 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1034 | |
Douglas Gregor | 35f9ae6 | 2011-11-17 01:44:33 +0000 | [diff] [blame] | 1035 | const SrcMgr::ContentCache *ContentCache |
Argyrios Kyrtzidis | ff39896 | 2012-07-11 20:59:04 +0000 | [diff] [blame] | 1036 | = SourceMgr.getOrCreateContentCache(File, |
| 1037 | /*isSystemFile=*/FileCharacter != SrcMgr::C_User); |
Douglas Gregor | 35f9ae6 | 2011-11-17 01:44:33 +0000 | [diff] [blame] | 1038 | if (OverriddenBuffer && !ContentCache->BufferOverridden && |
| 1039 | ContentCache->ContentsEntry == ContentCache->OrigEntry) { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1040 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1041 | Record.clear(); |
| 1042 | unsigned RecCode |
| 1043 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
| 1044 | |
| 1045 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
| 1046 | Error("AST record has invalid code"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1047 | return true; |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | llvm::MemoryBuffer *Buffer |
| 1051 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1052 | File->getName()); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1053 | SourceMgr.overrideFileContents(File, Buffer); |
| 1054 | } |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 1055 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1056 | break; |
| 1057 | } |
| 1058 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1059 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1060 | const char *Name = BlobStart; |
| 1061 | unsigned Offset = Record[0]; |
| 1062 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1063 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1064 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1065 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1066 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1067 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1068 | Error("AST record has invalid code"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1069 | return true; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1072 | llvm::MemoryBuffer *Buffer |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1073 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
| 1074 | Name); |
Douglas Gregor | 0ca6e27 | 2012-10-25 00:30:23 +0000 | [diff] [blame^] | 1075 | SourceMgr.createFileIDForMemBuffer(Buffer, ID, BaseOffset + Offset); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1076 | break; |
| 1077 | } |
| 1078 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1079 | case SM_SLOC_EXPANSION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1080 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Chandler Carruth | bf340e4 | 2011-07-26 03:03:05 +0000 | [diff] [blame] | 1081 | SourceMgr.createExpansionLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1082 | ReadSourceLocation(*F, Record[2]), |
| 1083 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1084 | Record[4], |
| 1085 | ID, |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1086 | BaseOffset + Record[0]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1087 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1088 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1091 | return false; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1094 | /// \brief Find the location where the module F is imported. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1095 | SourceLocation ASTReader::getImportLocation(ModuleFile *F) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1096 | if (F->ImportLoc.isValid()) |
| 1097 | return F->ImportLoc; |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1098 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1099 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1100 | // location of its includer. |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1101 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1102 | // Main file is the importer. We assume that it is the first entry in the |
| 1103 | // entry table. We can't ask the manager, because at the time of PCH loading |
| 1104 | // the main file entry doesn't exist yet. |
| 1105 | // The very first entry is the invalid instantiation loc, which takes up |
| 1106 | // offsets 0 and 1. |
| 1107 | return SourceLocation::getFromRawEncoding(2U); |
| 1108 | } |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1109 | //return F->Loaders[0]->FirstLoc; |
| 1110 | return F->ImportedBy[0]->FirstLoc; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1113 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1114 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1115 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1116 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1117 | unsigned BlockID) { |
| 1118 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1119 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1120 | return Failure; |
| 1121 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1122 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1123 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1124 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1125 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1126 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1127 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1128 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1129 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1130 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1131 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1132 | Cursor.ReadAbbrevRecord(); |
| 1133 | } |
| 1134 | } |
| 1135 | |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 1136 | void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset, |
| 1137 | MacroInfo *Hint) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1138 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1139 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1140 | // Keep track of where we are in the stream, then jump back there |
| 1141 | // after reading this macro. |
| 1142 | SavedStreamPosition SavedPosition(Stream); |
| 1143 | |
| 1144 | Stream.JumpToBit(Offset); |
| 1145 | RecordData Record; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1146 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1147 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1148 | |
Douglas Gregor | e8219a6 | 2012-10-11 21:07:39 +0000 | [diff] [blame] | 1149 | // RAII object to add the loaded macro information once we're done |
| 1150 | // adding tokens. |
| 1151 | struct AddLoadedMacroInfoRAII { |
| 1152 | Preprocessor &PP; |
| 1153 | MacroInfo *Hint; |
| 1154 | MacroInfo *MI; |
| 1155 | IdentifierInfo *II; |
| 1156 | |
| 1157 | AddLoadedMacroInfoRAII(Preprocessor &PP, MacroInfo *Hint) |
| 1158 | : PP(PP), Hint(Hint), MI(), II() { } |
| 1159 | ~AddLoadedMacroInfoRAII( ) { |
| 1160 | if (MI) { |
| 1161 | // Finally, install the macro. |
| 1162 | PP.addLoadedMacroInfo(II, MI, Hint); |
| 1163 | } |
| 1164 | } |
| 1165 | } AddLoadedMacroInfo(PP, Hint); |
| 1166 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1167 | while (true) { |
| 1168 | unsigned Code = Stream.ReadCode(); |
| 1169 | switch (Code) { |
| 1170 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1171 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1172 | |
| 1173 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1174 | // No known subblocks, always skip them. |
| 1175 | Stream.ReadSubBlockID(); |
| 1176 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1177 | Error("malformed block record in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1178 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1179 | } |
| 1180 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1181 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1182 | case llvm::bitc::DEFINE_ABBREV: |
| 1183 | Stream.ReadAbbrevRecord(); |
| 1184 | continue; |
| 1185 | default: break; |
| 1186 | } |
| 1187 | |
| 1188 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1189 | const char *BlobStart = 0; |
| 1190 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1191 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1192 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1193 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1194 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1195 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1196 | case PP_MACRO_OBJECT_LIKE: |
| 1197 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1198 | // If we already have a macro, that means that we've hit the end |
| 1199 | // of the definition of the macro we were looking for. We're |
| 1200 | // done. |
| 1201 | if (Macro) |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1202 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1203 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1204 | IdentifierInfo *II = getLocalIdentifier(F, Record[0]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1205 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1206 | Error("macro must have a name in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1207 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1208 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1209 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1210 | unsigned GlobalID = getGlobalMacroID(F, Record[1]); |
| 1211 | |
| 1212 | // If this macro has already been loaded, don't do so again. |
| 1213 | if (MacrosLoaded[GlobalID - NUM_PREDEF_MACRO_IDS]) |
| 1214 | return; |
| 1215 | |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1216 | SubmoduleID GlobalSubmoduleID = getGlobalSubmoduleID(F, Record[2]); |
| 1217 | unsigned NextIndex = 3; |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1218 | SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1219 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1220 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1221 | // Record this macro. |
| 1222 | MacrosLoaded[GlobalID - NUM_PREDEF_MACRO_IDS] = MI; |
| 1223 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1224 | SourceLocation UndefLoc = ReadSourceLocation(F, Record, NextIndex); |
| 1225 | if (UndefLoc.isValid()) |
| 1226 | MI->setUndefLoc(UndefLoc); |
| 1227 | |
| 1228 | MI->setIsUsed(Record[NextIndex++]); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1229 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1230 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1231 | bool IsPublic = Record[NextIndex++]; |
Douglas Gregor | aa93a87 | 2011-10-17 15:32:29 +0000 | [diff] [blame] | 1232 | MI->setVisibility(IsPublic, ReadSourceLocation(F, Record, NextIndex)); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1233 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1234 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1235 | // Decode function-like macro info. |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1236 | bool isC99VarArgs = Record[NextIndex++]; |
| 1237 | bool isGNUVarArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1238 | MacroArgs.clear(); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1239 | unsigned NumArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1240 | for (unsigned i = 0; i != NumArgs; ++i) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1241 | MacroArgs.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1242 | |
| 1243 | // Install function-like macro info. |
| 1244 | MI->setIsFunctionLike(); |
| 1245 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1246 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1247 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1248 | PP.getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1251 | if (DeserializationListener) |
| 1252 | DeserializationListener->MacroRead(GlobalID, MI); |
| 1253 | |
| 1254 | // If an update record marked this as undefined, do so now. |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1255 | // FIXME: Only if the submodule this update came from is visible? |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1256 | MacroUpdatesMap::iterator Update = MacroUpdates.find(GlobalID); |
| 1257 | if (Update != MacroUpdates.end()) { |
| 1258 | if (MI->getUndefLoc().isInvalid()) { |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 1259 | for (unsigned I = 0, N = Update->second.size(); I != N; ++I) { |
| 1260 | bool Hidden = false; |
| 1261 | if (unsigned SubmoduleID = Update->second[I].first) { |
| 1262 | if (Module *Owner = getSubmodule(SubmoduleID)) { |
| 1263 | if (Owner->NameVisibility == Module::Hidden) { |
| 1264 | // Note that this #undef is hidden. |
| 1265 | Hidden = true; |
| 1266 | |
| 1267 | // Record this hiding for later. |
| 1268 | HiddenNamesMap[Owner].push_back( |
| 1269 | HiddenName(II, MI, Update->second[I].second.UndefLoc)); |
| 1270 | } |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | if (!Hidden) { |
| 1275 | MI->setUndefLoc(Update->second[I].second.UndefLoc); |
| 1276 | if (PPMutationListener *Listener = PP.getPPMutationListener()) |
| 1277 | Listener->UndefinedMacro(MI); |
| 1278 | break; |
| 1279 | } |
| 1280 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1281 | } |
| 1282 | MacroUpdates.erase(Update); |
| 1283 | } |
| 1284 | |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1285 | // Determine whether this macro definition is visible. |
| 1286 | bool Hidden = !MI->isPublic(); |
| 1287 | if (!Hidden && GlobalSubmoduleID) { |
| 1288 | if (Module *Owner = getSubmodule(GlobalSubmoduleID)) { |
| 1289 | if (Owner->NameVisibility == Module::Hidden) { |
| 1290 | // The owning module is not visible, and this macro definition |
| 1291 | // should not be, either. |
| 1292 | Hidden = true; |
| 1293 | |
| 1294 | // Note that this macro definition was hidden because its owning |
| 1295 | // module is not yet visible. |
| 1296 | HiddenNamesMap[Owner].push_back(HiddenName(II, MI)); |
| 1297 | } |
| 1298 | } |
| 1299 | } |
| 1300 | MI->setHidden(Hidden); |
| 1301 | |
Douglas Gregor | e8219a6 | 2012-10-11 21:07:39 +0000 | [diff] [blame] | 1302 | // Make sure we install the macro once we're done. |
| 1303 | AddLoadedMacroInfo.MI = MI; |
| 1304 | AddLoadedMacroInfo.II = II; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1305 | |
| 1306 | // Remember that we saw this macro last so that we add the tokens that |
| 1307 | // form its body to it. |
| 1308 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1309 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1310 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1311 | Record[NextIndex]) { |
| 1312 | // We have a macro definition. Register the association |
| 1313 | PreprocessedEntityID |
| 1314 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1315 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 1316 | PPRec.RegisterMacroDefinition(Macro, |
| 1317 | PPRec.getPPEntityID(GlobalID-1, /*isLoaded=*/true)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1318 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1319 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1320 | ++NumMacrosRead; |
| 1321 | break; |
| 1322 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1324 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1325 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1326 | // erroneous, just pretend we didn't see this. |
| 1327 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1328 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1329 | Token Tok; |
| 1330 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1331 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1332 | Tok.setLength(Record[1]); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1333 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[2])) |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1334 | Tok.setIdentifierInfo(II); |
| 1335 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1336 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1337 | Macro->AddTokenToBody(Tok); |
| 1338 | break; |
| 1339 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 1340 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1341 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1344 | PreprocessedEntityID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1345 | ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const { |
Argyrios Kyrtzidis | 1f6d225 | 2011-09-19 20:40:02 +0000 | [diff] [blame] | 1346 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1347 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1348 | assert(I != M.PreprocessedEntityRemap.end() |
| 1349 | && "Invalid index into preprocessed entity index remap"); |
| 1350 | |
| 1351 | return LocalID + I->second; |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1354 | unsigned HeaderFileInfoTrait::ComputeHash(const char *path) { |
| 1355 | return llvm::HashString(llvm::sys::path::filename(path)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1356 | } |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1357 | |
| 1358 | HeaderFileInfoTrait::internal_key_type |
| 1359 | HeaderFileInfoTrait::GetInternalKey(const char *path) { return path; } |
| 1360 | |
| 1361 | bool HeaderFileInfoTrait::EqualKey(internal_key_type a, internal_key_type b) { |
| 1362 | if (strcmp(a, b) == 0) |
| 1363 | return true; |
| 1364 | |
| 1365 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1366 | return false; |
Douglas Gregor | 99a922b | 2011-12-09 16:22:07 +0000 | [diff] [blame] | 1367 | |
| 1368 | // Determine whether the actual files are equivalent. |
| 1369 | bool Result = false; |
| 1370 | if (llvm::sys::fs::equivalent(a, b, Result)) |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1371 | return false; |
| 1372 | |
Douglas Gregor | 99a922b | 2011-12-09 16:22:07 +0000 | [diff] [blame] | 1373 | return Result; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | std::pair<unsigned, unsigned> |
| 1377 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 1378 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1379 | unsigned DataLen = (unsigned) *d++; |
| 1380 | return std::make_pair(KeyLen + 1, DataLen); |
| 1381 | } |
| 1382 | |
| 1383 | HeaderFileInfoTrait::data_type |
| 1384 | HeaderFileInfoTrait::ReadData(const internal_key_type, const unsigned char *d, |
| 1385 | unsigned DataLen) { |
| 1386 | const unsigned char *End = d + DataLen; |
| 1387 | using namespace clang::io; |
| 1388 | HeaderFileInfo HFI; |
| 1389 | unsigned Flags = *d++; |
| 1390 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1391 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1392 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1393 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1394 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
| 1395 | HFI.NumIncludes = ReadUnalignedLE16(d); |
Douglas Gregor | 541ba16 | 2011-10-17 18:53:12 +0000 | [diff] [blame] | 1396 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID(M, |
| 1397 | ReadUnalignedLE32(d)); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1398 | if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { |
| 1399 | // The framework offset is 1 greater than the actual offset, |
| 1400 | // since 0 is used as an indicator for "no framework name". |
| 1401 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1402 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1403 | } |
| 1404 | |
| 1405 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1406 | (void)End; |
| 1407 | |
| 1408 | // This HeaderFileInfo was externally loaded. |
| 1409 | HFI.External = true; |
| 1410 | return HFI; |
| 1411 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1412 | |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1413 | void ASTReader::setIdentifierIsMacro(IdentifierInfo *II, ArrayRef<MacroID> IDs){ |
| 1414 | II->setHadMacroDefinition(true); |
| 1415 | assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard"); |
| 1416 | PendingMacroIDs[II].append(IDs.begin(), IDs.end()); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1419 | void ASTReader::ReadDefinedMacros() { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1420 | // Note that we are loading defined macros. |
| 1421 | Deserializing Macros(this); |
| 1422 | |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1423 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1424 | E = ModuleMgr.rend(); I != E; ++I) { |
| 1425 | llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1426 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1427 | // If there was no preprocessor block, skip this file. |
| 1428 | if (!MacroCursor.getBitStreamReader()) |
| 1429 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1430 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1431 | llvm::BitstreamCursor Cursor = MacroCursor; |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1432 | Cursor.JumpToBit((*I)->MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1433 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1434 | RecordData Record; |
| 1435 | while (true) { |
| 1436 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1437 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1438 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1439 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1440 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1441 | // No known subblocks, always skip them. |
| 1442 | Cursor.ReadSubBlockID(); |
| 1443 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1444 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1445 | return; |
| 1446 | } |
| 1447 | continue; |
| 1448 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1449 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1450 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1451 | Cursor.ReadAbbrevRecord(); |
| 1452 | continue; |
| 1453 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1454 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1455 | // Read a record. |
| 1456 | const char *BlobStart; |
| 1457 | unsigned BlobLen; |
| 1458 | Record.clear(); |
| 1459 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1460 | default: // Default behavior: ignore. |
| 1461 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1462 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1463 | case PP_MACRO_OBJECT_LIKE: |
| 1464 | case PP_MACRO_FUNCTION_LIKE: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1465 | getLocalIdentifier(**I, Record[0]); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1466 | break; |
| 1467 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1468 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1469 | // Ignore tokens. |
| 1470 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1471 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1472 | } |
| 1473 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1476 | namespace { |
| 1477 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 1478 | class IdentifierLookupVisitor { |
| 1479 | StringRef Name; |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1480 | unsigned PriorGeneration; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1481 | IdentifierInfo *Found; |
| 1482 | public: |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1483 | IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration) |
| 1484 | : Name(Name), PriorGeneration(PriorGeneration), Found() { } |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1485 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1486 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1487 | IdentifierLookupVisitor *This |
| 1488 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 1489 | |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1490 | // If we've already searched this module file, skip it now. |
| 1491 | if (M.Generation <= This->PriorGeneration) |
| 1492 | return true; |
| 1493 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1494 | ASTIdentifierLookupTable *IdTable |
| 1495 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 1496 | if (!IdTable) |
| 1497 | return false; |
| 1498 | |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1499 | ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), |
| 1500 | M, This->Found); |
| 1501 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1502 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 1503 | This->Name.size()); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1504 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Trait); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1505 | if (Pos == IdTable->end()) |
| 1506 | return false; |
| 1507 | |
| 1508 | // Dereferencing the iterator has the effect of building the |
| 1509 | // IdentifierInfo node and populating it with the various |
| 1510 | // declarations it needs. |
| 1511 | This->Found = *Pos; |
| 1512 | return true; |
| 1513 | } |
| 1514 | |
| 1515 | // \brief Retrieve the identifier info found within the module |
| 1516 | // files. |
| 1517 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 1518 | }; |
| 1519 | } |
| 1520 | |
| 1521 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1522 | // Note that we are loading an identifier. |
| 1523 | Deserializing AnIdentifier(this); |
| 1524 | |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1525 | unsigned PriorGeneration = 0; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1526 | if (getContext().getLangOpts().Modules) |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1527 | PriorGeneration = IdentifierGeneration[&II]; |
| 1528 | |
| 1529 | IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration); |
| 1530 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
| 1531 | markIdentifierUpToDate(&II); |
| 1532 | } |
| 1533 | |
| 1534 | void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { |
| 1535 | if (!II) |
| 1536 | return; |
| 1537 | |
| 1538 | II->setOutOfDate(false); |
| 1539 | |
| 1540 | // Update the generation for this identifier. |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1541 | if (getContext().getLangOpts().Modules) |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1542 | IdentifierGeneration[II] = CurrentGeneration; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1545 | llvm::PointerIntPair<const FileEntry *, 1, bool> |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1546 | ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1547 | // If this ID is bogus, just return an empty input file. |
| 1548 | if (ID == 0 || ID > F.InputFilesLoaded.size()) |
| 1549 | return InputFile(); |
| 1550 | |
| 1551 | // If we've already loaded this input file, return it. |
| 1552 | if (F.InputFilesLoaded[ID-1].getPointer()) |
| 1553 | return F.InputFilesLoaded[ID-1]; |
| 1554 | |
| 1555 | // Go find this input file. |
| 1556 | llvm::BitstreamCursor &Cursor = F.InputFilesCursor; |
| 1557 | SavedStreamPosition SavedPosition(Cursor); |
| 1558 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
| 1559 | |
| 1560 | unsigned Code = Cursor.ReadCode(); |
| 1561 | RecordData Record; |
| 1562 | const char *BlobStart = 0; |
| 1563 | unsigned BlobLen = 0; |
| 1564 | switch ((InputFileRecordTypes)Cursor.ReadRecord(Code, Record, |
| 1565 | &BlobStart, &BlobLen)) { |
| 1566 | case INPUT_FILE: { |
| 1567 | unsigned StoredID = Record[0]; |
| 1568 | assert(ID == StoredID && "Bogus stored ID or offset"); |
NAKAMURA Takumi | 6b8194e | 2012-10-22 21:50:39 +0000 | [diff] [blame] | 1569 | (void)StoredID; |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1570 | off_t StoredSize = (off_t)Record[1]; |
| 1571 | time_t StoredTime = (time_t)Record[2]; |
| 1572 | bool Overridden = (bool)Record[3]; |
| 1573 | |
| 1574 | // Get the file entry for this input file. |
| 1575 | StringRef OrigFilename(BlobStart, BlobLen); |
| 1576 | std::string Filename = OrigFilename; |
| 1577 | MaybeAddSystemRootToFilename(F, Filename); |
| 1578 | const FileEntry *File |
| 1579 | = Overridden? FileMgr.getVirtualFile(Filename, StoredSize, StoredTime) |
| 1580 | : FileMgr.getFile(Filename, /*OpenFile=*/false); |
| 1581 | |
| 1582 | // If we didn't find the file, resolve it relative to the |
| 1583 | // original directory from which this AST file was created. |
| 1584 | if (File == 0 && !F.OriginalDir.empty() && !CurrentDir.empty() && |
| 1585 | F.OriginalDir != CurrentDir) { |
| 1586 | std::string Resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1587 | F.OriginalDir, |
| 1588 | CurrentDir); |
| 1589 | if (!Resolved.empty()) |
| 1590 | File = FileMgr.getFile(Resolved); |
| 1591 | } |
| 1592 | |
| 1593 | // For an overridden file, create a virtual file with the stored |
| 1594 | // size/timestamp. |
| 1595 | if (Overridden && File == 0) { |
| 1596 | File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime); |
| 1597 | } |
| 1598 | |
| 1599 | if (File == 0) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1600 | if (Complain) { |
| 1601 | std::string ErrorStr = "could not find file '"; |
| 1602 | ErrorStr += Filename; |
| 1603 | ErrorStr += "' referenced by AST file"; |
| 1604 | Error(ErrorStr.c_str()); |
| 1605 | } |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1606 | return InputFile(); |
| 1607 | } |
| 1608 | |
| 1609 | // Note that we've loaded this input file. |
| 1610 | F.InputFilesLoaded[ID-1] = InputFile(File, Overridden); |
| 1611 | |
| 1612 | // Check if there was a request to override the contents of the file |
| 1613 | // that was part of the precompiled header. Overridding such a file |
| 1614 | // can lead to problems when lexing using the source locations from the |
| 1615 | // PCH. |
| 1616 | SourceManager &SM = getSourceManager(); |
| 1617 | if (!Overridden && SM.isFileOverridden(File)) { |
| 1618 | Error(diag::err_fe_pch_file_overridden, Filename); |
| 1619 | // After emitting the diagnostic, recover by disabling the override so |
| 1620 | // that the original file will be used. |
| 1621 | SM.disableFileContentsOverride(File); |
| 1622 | // The FileEntry is a virtual file entry with the size of the contents |
| 1623 | // that would override the original contents. Set it to the original's |
| 1624 | // size/time. |
| 1625 | FileMgr.modifyFileEntry(const_cast<FileEntry*>(File), |
| 1626 | StoredSize, StoredTime); |
| 1627 | } |
| 1628 | |
| 1629 | // For an overridden file, there is nothing to validate. |
| 1630 | if (Overridden) |
| 1631 | return InputFile(File, Overridden); |
| 1632 | |
| 1633 | // The stat info from the FileEntry came from the cached stat |
| 1634 | // info of the PCH, so we cannot trust it. |
| 1635 | struct stat StatBuf; |
| 1636 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 1637 | StatBuf.st_size = File->getSize(); |
| 1638 | StatBuf.st_mtime = File->getModificationTime(); |
| 1639 | } |
| 1640 | |
| 1641 | if ((StoredSize != StatBuf.st_size |
| 1642 | #if !defined(LLVM_ON_WIN32) |
| 1643 | // In our regression testing, the Windows file system seems to |
| 1644 | // have inconsistent modification times that sometimes |
| 1645 | // erroneously trigger this error-handling path. |
| 1646 | || StoredTime != StatBuf.st_mtime |
| 1647 | #endif |
| 1648 | )) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1649 | if (Complain) |
| 1650 | Error(diag::err_fe_pch_file_modified, Filename); |
| 1651 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1652 | return InputFile(); |
| 1653 | } |
| 1654 | |
| 1655 | return InputFile(File, Overridden); |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | return InputFile(); |
| 1660 | } |
| 1661 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1662 | const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1663 | ModuleFile &M = ModuleMgr.getPrimaryModule(); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1664 | std::string Filename = filenameStrRef; |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1665 | MaybeAddSystemRootToFilename(M, Filename); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1666 | const FileEntry *File = FileMgr.getFile(Filename); |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1667 | if (File == 0 && !M.OriginalDir.empty() && !CurrentDir.empty() && |
| 1668 | M.OriginalDir != CurrentDir) { |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1669 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1670 | M.OriginalDir, |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1671 | CurrentDir); |
| 1672 | if (!resolved.empty()) |
| 1673 | File = FileMgr.getFile(resolved); |
| 1674 | } |
| 1675 | |
| 1676 | return File; |
| 1677 | } |
| 1678 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1679 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1680 | /// not an absolute path, add the system root to the beginning of the file |
| 1681 | /// name. |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1682 | StringRef ASTReader::MaybeAddSystemRootToFilename(ModuleFile &M, |
| 1683 | std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1684 | // 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] | 1685 | if (!M.RelocatablePCH) |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1686 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1687 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1688 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1689 | return Filename; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1690 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1691 | if (isysroot.empty()) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1692 | // If no system root was given, default to '/' |
| 1693 | Filename.insert(Filename.begin(), '/'); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1694 | return Filename; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1695 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1696 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1697 | unsigned Length = isysroot.size(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1698 | if (isysroot[Length - 1] != '/') |
| 1699 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1700 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1701 | Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end()); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1702 | return Filename; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1705 | ASTReader::ASTReadResult |
| 1706 | ASTReader::ReadControlBlock(ModuleFile &F, |
| 1707 | llvm::SmallVectorImpl<ModuleFile *> &Loaded, |
| 1708 | unsigned ClientLoadCapabilities) { |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1709 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1710 | |
| 1711 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
| 1712 | Error("malformed block record in AST file"); |
| 1713 | return Failure; |
| 1714 | } |
| 1715 | |
| 1716 | // Read all of the records and blocks in the control block. |
| 1717 | RecordData Record; |
| 1718 | while (!Stream.AtEndOfStream()) { |
| 1719 | unsigned Code = Stream.ReadCode(); |
| 1720 | if (Code == llvm::bitc::END_BLOCK) { |
| 1721 | if (Stream.ReadBlockEnd()) { |
| 1722 | Error("error at end of control block in AST file"); |
| 1723 | return Failure; |
| 1724 | } |
| 1725 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1726 | // Validate all of the input files. |
| 1727 | if (!DisableValidation) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1728 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1729 | for (unsigned I = 0, N = Record[0]; I < N; ++I) |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1730 | if (!getInputFile(F, I+1, Complain).getPointer()) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1731 | return OutOfDate; |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1732 | } |
| 1733 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1734 | return Success; |
| 1735 | } |
| 1736 | |
| 1737 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1738 | switch (Stream.ReadSubBlockID()) { |
| 1739 | case INPUT_FILES_BLOCK_ID: |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1740 | F.InputFilesCursor = Stream; |
| 1741 | if (Stream.SkipBlock() || // Skip with the main cursor |
| 1742 | // Read the abbreviations |
| 1743 | ReadBlockAbbrevs(F.InputFilesCursor, INPUT_FILES_BLOCK_ID)) { |
| 1744 | Error("malformed block record in AST file"); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1745 | return Failure; |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1746 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1747 | continue; |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1748 | |
| 1749 | default: |
| 1750 | if (!Stream.SkipBlock()) |
| 1751 | continue; |
| 1752 | break; |
| 1753 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1754 | |
| 1755 | Error("malformed block record in AST file"); |
| 1756 | return Failure; |
| 1757 | } |
| 1758 | |
| 1759 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1760 | Stream.ReadAbbrevRecord(); |
| 1761 | continue; |
| 1762 | } |
| 1763 | |
| 1764 | // Read and process a record. |
| 1765 | Record.clear(); |
| 1766 | const char *BlobStart = 0; |
| 1767 | unsigned BlobLen = 0; |
| 1768 | switch ((ControlRecordTypes)Stream.ReadRecord(Code, Record, |
| 1769 | &BlobStart, &BlobLen)) { |
| 1770 | case METADATA: { |
| 1771 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1772 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
| 1773 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
| 1774 | : diag::warn_pch_version_too_new); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1775 | return VersionMismatch; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | bool hasErrors = Record[5]; |
| 1779 | if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) { |
| 1780 | Diag(diag::err_pch_with_compiler_errors); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1781 | return HadErrors; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1782 | } |
| 1783 | |
Douglas Gregor | caed060 | 2012-10-18 21:31:35 +0000 | [diff] [blame] | 1784 | F.RelocatablePCH = Record[4]; |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1785 | |
| 1786 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
| 1787 | StringRef ASTBranch(BlobStart, BlobLen); |
| 1788 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1789 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
| 1790 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1791 | return VersionMismatch; |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1792 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1793 | break; |
| 1794 | } |
| 1795 | |
| 1796 | case IMPORTS: { |
| 1797 | // Load each of the imported PCH files. |
| 1798 | unsigned Idx = 0, N = Record.size(); |
| 1799 | while (Idx < N) { |
| 1800 | // Read information about the AST file. |
| 1801 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 1802 | unsigned Length = Record[Idx++]; |
| 1803 | SmallString<128> ImportedFile(Record.begin() + Idx, |
| 1804 | Record.begin() + Idx + Length); |
| 1805 | Idx += Length; |
| 1806 | |
| 1807 | // Load the AST file. |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1808 | switch(ReadASTCore(ImportedFile, ImportedKind, &F, Loaded, |
| 1809 | ClientLoadCapabilities)) { |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1810 | case Failure: return Failure; |
| 1811 | // 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] | 1812 | case OutOfDate: return OutOfDate; |
| 1813 | case VersionMismatch: return VersionMismatch; |
| 1814 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 1815 | case HadErrors: return HadErrors; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1816 | case Success: break; |
| 1817 | } |
| 1818 | } |
| 1819 | break; |
| 1820 | } |
| 1821 | |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1822 | case LANGUAGE_OPTIONS: { |
| 1823 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 1824 | if (Listener && &F == *ModuleMgr.begin() && |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 1825 | ParseLanguageOptions(Record, Complain, *Listener) && |
| 1826 | !DisableValidation) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1827 | return ConfigurationMismatch; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1828 | break; |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1829 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1830 | |
Douglas Gregor | ee097c1 | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1831 | case TARGET_OPTIONS: { |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 1832 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 1833 | if (Listener && &F == *ModuleMgr.begin() && |
| 1834 | ParseTargetOptions(Record, Complain, *Listener) && |
| 1835 | !DisableValidation) |
| 1836 | return ConfigurationMismatch; |
Douglas Gregor | ee097c1 | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1837 | break; |
| 1838 | } |
| 1839 | |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1840 | case DIAGNOSTIC_OPTIONS: { |
| 1841 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 1842 | if (Listener && &F == *ModuleMgr.begin() && |
| 1843 | ParseDiagnosticOptions(Record, Complain, *Listener) && |
| 1844 | !DisableValidation) |
| 1845 | return ConfigurationMismatch; |
| 1846 | break; |
| 1847 | } |
Douglas Gregor | 1b2c3c0 | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1848 | |
| 1849 | case FILE_SYSTEM_OPTIONS: { |
| 1850 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 1851 | if (Listener && &F == *ModuleMgr.begin() && |
| 1852 | ParseFileSystemOptions(Record, Complain, *Listener) && |
| 1853 | !DisableValidation) |
| 1854 | return ConfigurationMismatch; |
| 1855 | break; |
| 1856 | } |
| 1857 | |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1858 | case HEADER_SEARCH_OPTIONS: { |
| 1859 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 1860 | if (Listener && &F == *ModuleMgr.begin() && |
| 1861 | ParseHeaderSearchOptions(Record, Complain, *Listener) && |
| 1862 | !DisableValidation) |
| 1863 | return ConfigurationMismatch; |
| 1864 | break; |
| 1865 | } |
| 1866 | |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1867 | case PREPROCESSOR_OPTIONS: { |
| 1868 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 1869 | if (Listener && &F == *ModuleMgr.begin() && |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 1870 | ParsePreprocessorOptions(Record, Complain, *Listener, |
| 1871 | SuggestedPredefines) && |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1872 | !DisableValidation) |
| 1873 | return ConfigurationMismatch; |
| 1874 | break; |
| 1875 | } |
| 1876 | |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1877 | case ORIGINAL_FILE: |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1878 | F.OriginalSourceFileID = FileID::get(Record[0]); |
| 1879 | F.ActualOriginalSourceFileName.assign(BlobStart, BlobLen); |
| 1880 | F.OriginalSourceFileName = F.ActualOriginalSourceFileName; |
| 1881 | MaybeAddSystemRootToFilename(F, F.OriginalSourceFileName); |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1882 | break; |
| 1883 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1884 | case ORIGINAL_PCH_DIR: |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1885 | F.OriginalDir.assign(BlobStart, BlobLen); |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1886 | break; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1887 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1888 | case INPUT_FILE_OFFSETS: |
| 1889 | F.InputFileOffsets = (const uint32_t *)BlobStart; |
| 1890 | F.InputFilesLoaded.resize(Record[0]); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1891 | break; |
| 1892 | } |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | Error("premature end of bitstream in AST file"); |
| 1896 | return Failure; |
| 1897 | } |
| 1898 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1899 | bool ASTReader::ReadASTBlock(ModuleFile &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1900 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1901 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1902 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1903 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1904 | return true; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1905 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1906 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1907 | // Read all of the records and blocks for the AST file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1908 | RecordData Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1909 | while (!Stream.AtEndOfStream()) { |
| 1910 | unsigned Code = Stream.ReadCode(); |
| 1911 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1912 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1913 | Error("error at end of module block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1914 | return true; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1915 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1916 | |
Argyrios Kyrtzidis | 1f94124 | 2012-09-21 01:30:00 +0000 | [diff] [blame] | 1917 | DeclContext *DC = Context.getTranslationUnitDecl(); |
| 1918 | if (!DC->hasExternalVisibleStorage() && DC->hasExternalLexicalStorage()) |
| 1919 | DC->setMustBuildLookupTable(); |
| 1920 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1921 | return false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1925 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1926 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1927 | // We lazily load the decls block, but we want to set up the |
| 1928 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1929 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1930 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1931 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1932 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1933 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1934 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1935 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1936 | return true; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1937 | } |
| 1938 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1939 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1940 | case DECL_UPDATES_BLOCK_ID: |
| 1941 | if (Stream.SkipBlock()) { |
| 1942 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1943 | return true; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1944 | } |
| 1945 | break; |
| 1946 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1947 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1948 | F.MacroCursor = Stream; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1949 | if (!PP.getExternalSource()) |
| 1950 | PP.setExternalSource(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1951 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1952 | if (Stream.SkipBlock() || |
| 1953 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1954 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1955 | return true; |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1956 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1957 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1958 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1959 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1960 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1961 | F.PreprocessorDetailCursor = Stream; |
| 1962 | if (Stream.SkipBlock() || |
| 1963 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1964 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1965 | Error("malformed preprocessor detail record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1966 | return true; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1967 | } |
| 1968 | F.PreprocessorDetailStartOffset |
| 1969 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1970 | |
| 1971 | if (!PP.getPreprocessingRecord()) |
Argyrios Kyrtzidis | c6c5452 | 2012-03-05 05:48:17 +0000 | [diff] [blame] | 1972 | PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1973 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 1974 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1975 | break; |
| 1976 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1977 | case SOURCE_MANAGER_BLOCK_ID: |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1978 | if (ReadSourceManagerBlock(F)) |
| 1979 | return true; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1980 | break; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1981 | |
| 1982 | case SUBMODULE_BLOCK_ID: |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1983 | if (ReadSubmoduleBlock(F)) |
| 1984 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1985 | break; |
| 1986 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 1987 | case COMMENTS_BLOCK_ID: { |
| 1988 | llvm::BitstreamCursor C = Stream; |
| 1989 | if (Stream.SkipBlock() || |
| 1990 | ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) { |
| 1991 | Error("malformed comments block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1992 | return true; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 1993 | } |
| 1994 | CommentsCursors.push_back(std::make_pair(C, &F)); |
| 1995 | break; |
| 1996 | } |
| 1997 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1998 | default: |
| 1999 | if (!Stream.SkipBlock()) |
| 2000 | break; |
| 2001 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2002 | return true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2003 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2004 | continue; |
| 2005 | } |
| 2006 | |
| 2007 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2008 | Stream.ReadAbbrevRecord(); |
| 2009 | continue; |
| 2010 | } |
| 2011 | |
| 2012 | // Read and process a record. |
| 2013 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2014 | const char *BlobStart = 0; |
| 2015 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2016 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2017 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2018 | default: // Default behavior: ignore. |
| 2019 | break; |
| 2020 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2021 | case TYPE_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2022 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2023 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2024 | return true; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2025 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2026 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 2027 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2028 | unsigned LocalBaseTypeIndex = Record[1]; |
| 2029 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 2030 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2031 | if (F.LocalNumTypes > 0) { |
| 2032 | // Introduce the global -> local mapping for types within this module. |
| 2033 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 2034 | |
| 2035 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2036 | F.TypeRemap.insertOrReplace( |
| 2037 | std::make_pair(LocalBaseTypeIndex, |
| 2038 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2039 | |
| 2040 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 2041 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2042 | break; |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2045 | case DECL_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2046 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2047 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2048 | return true; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2049 | } |
Argyrios Kyrtzidis | 9d31fa7 | 2011-10-27 18:47:35 +0000 | [diff] [blame] | 2050 | F.DeclOffsets = (const DeclOffset *)BlobStart; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2051 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2052 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2053 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 96e973f | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 2054 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2055 | if (F.LocalNumDecls > 0) { |
| 2056 | // Introduce the global -> local mapping for declarations within this |
| 2057 | // module. |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2058 | GlobalDeclMap.insert( |
| 2059 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2060 | |
| 2061 | // Introduce the local -> global mapping for declarations within this |
| 2062 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2063 | F.DeclRemap.insertOrReplace( |
| 2064 | std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2065 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2066 | // Introduce the global -> local mapping for declarations within this |
| 2067 | // module. |
| 2068 | F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID; |
| 2069 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2070 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 2071 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2072 | break; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2073 | } |
| 2074 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2075 | case TU_UPDATE_LEXICAL: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2076 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 2077 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
| 2078 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); |
| 2079 | Info.NumLexicalDecls |
| 2080 | = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2081 | TU->setHasExternalLexicalStorage(true); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2082 | break; |
| 2083 | } |
| 2084 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2085 | case UPDATE_VISIBLE: { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2086 | unsigned Idx = 0; |
| 2087 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 2088 | ASTDeclContextNameLookupTable *Table = |
| 2089 | ASTDeclContextNameLookupTable::Create( |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2090 | (const unsigned char *)BlobStart + Record[Idx++], |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2091 | (const unsigned char *)BlobStart, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 2092 | ASTDeclContextNameLookupTrait(*this, F)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2093 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID) { // Is it the TU? |
| 2094 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 2095 | F.DeclContextInfos[TU].NameLookupTableData = Table; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2096 | TU->setHasExternalVisibleStorage(true); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2097 | } else |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2098 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2099 | break; |
| 2100 | } |
| 2101 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2102 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2103 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2104 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2105 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2106 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2107 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2108 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2109 | ASTIdentifierLookupTrait(*this, F)); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2110 | |
| 2111 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2112 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2113 | break; |
| 2114 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2115 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2116 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2117 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2118 | return true; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2119 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2120 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2121 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2122 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2123 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 2124 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2125 | if (F.LocalNumIdentifiers > 0) { |
| 2126 | // Introduce the global -> local mapping for identifiers within this |
| 2127 | // module. |
| 2128 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 2129 | &F)); |
| 2130 | |
| 2131 | // Introduce the local -> global mapping for identifiers within this |
| 2132 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2133 | F.IdentifierRemap.insertOrReplace( |
| 2134 | std::make_pair(LocalBaseIdentifierID, |
| 2135 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2136 | |
| 2137 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2138 | + F.LocalNumIdentifiers); |
| 2139 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2140 | break; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2141 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2142 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2143 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2144 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2145 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2146 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2147 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2148 | case SPECIAL_TYPES: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 2149 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2150 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2151 | break; |
| 2152 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2153 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2154 | TotalNumStatements += Record[0]; |
| 2155 | TotalNumMacros += Record[1]; |
| 2156 | TotalLexicalDeclContexts += Record[2]; |
| 2157 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2158 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2159 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2160 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2161 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2162 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2163 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2164 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2165 | case DELEGATING_CTORS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2166 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2167 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2168 | break; |
| 2169 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2170 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 2171 | if (Record.size() % 4 != 0) { |
| 2172 | Error("invalid weak identifiers record"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2173 | return true; |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 2177 | // files. This isn't the way to do it :) |
| 2178 | WeakUndeclaredIdentifiers.clear(); |
| 2179 | |
| 2180 | // Translate the weak, undeclared identifiers into global IDs. |
| 2181 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2182 | WeakUndeclaredIdentifiers.push_back( |
| 2183 | getGlobalIdentifierID(F, Record[I++])); |
| 2184 | WeakUndeclaredIdentifiers.push_back( |
| 2185 | getGlobalIdentifierID(F, Record[I++])); |
| 2186 | WeakUndeclaredIdentifiers.push_back( |
| 2187 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2188 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2189 | } |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2190 | break; |
| 2191 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2192 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2193 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2194 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2195 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2196 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2197 | case SELECTOR_OFFSETS: { |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2198 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2199 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2200 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2201 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 2202 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2203 | if (F.LocalNumSelectors > 0) { |
| 2204 | // Introduce the global -> local mapping for selectors within this |
| 2205 | // module. |
| 2206 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 2207 | |
| 2208 | // Introduce the local -> global mapping for selectors within this |
| 2209 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2210 | F.SelectorRemap.insertOrReplace( |
| 2211 | std::make_pair(LocalBaseSelectorID, |
| 2212 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2213 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2214 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 2215 | } |
| 2216 | break; |
| 2217 | } |
| 2218 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2219 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2220 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2221 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2222 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2223 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2224 | F.SelectorLookupTableData + Record[0], |
| 2225 | F.SelectorLookupTableData, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2226 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2227 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2228 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2229 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2230 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 2231 | if (!Record.empty()) { |
| 2232 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2233 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 2234 | Record[Idx++])); |
| 2235 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2236 | getRawEncoding()); |
| 2237 | } |
| 2238 | } |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2239 | break; |
| 2240 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2241 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2242 | if (!Record.empty() && Listener) |
Argyrios Kyrtzidis | 62288ed | 2012-10-10 02:12:47 +0000 | [diff] [blame] | 2243 | Listener->ReadCounter(F, Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2244 | break; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2245 | |
| 2246 | case FILE_SORTED_DECLS: |
| 2247 | F.FileSortedDecls = (const DeclID *)BlobStart; |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2248 | F.NumFileSortedDecls = Record[0]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2249 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2250 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2251 | case SOURCE_LOCATION_OFFSETS: { |
| 2252 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2253 | F.LocalNumSLocEntries = Record[0]; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2254 | unsigned SLocSpaceSize = Record[1]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2255 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2256 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
| 2257 | SLocSpaceSize); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2258 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2259 | // we invert it. Because we invert it, though, we need the other end of |
| 2260 | // the range. |
| 2261 | unsigned RangeStart = |
| 2262 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2263 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2264 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2265 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2266 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 2267 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 2268 | GlobalSLocOffsetMap.insert( |
| 2269 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 2270 | - SLocSpaceSize,&F)); |
| 2271 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2272 | // Initialize the remapping table. |
| 2273 | // Invalid stays invalid. |
| 2274 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2275 | // This module. Base was 2 when being compiled. |
| 2276 | F.SLocRemap.insert(std::make_pair(2U, |
| 2277 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2278 | |
| 2279 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2280 | break; |
| 2281 | } |
| 2282 | |
Douglas Gregor | 5d51a1d | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 2283 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2284 | // Additional remapping information. |
| 2285 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2286 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2287 | |
| 2288 | // Continuous range maps we may be updating in our module. |
| 2289 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2290 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2291 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2292 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2293 | MacroRemap(F.MacroRemap); |
| 2294 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2295 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2296 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2297 | SubmoduleRemap(F.SubmoduleRemap); |
| 2298 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2299 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2300 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2301 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 2302 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2303 | while(Data < DataEnd) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2304 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2305 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2306 | Data += Len; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2307 | ModuleFile *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2308 | if (!OM) { |
| 2309 | Error("SourceLocation remap refers to unknown module"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2310 | return true; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2311 | } |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2312 | |
| 2313 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 2314 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2315 | uint32_t MacroIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2316 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2317 | uint32_t SubmoduleIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2318 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 2319 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2320 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2321 | |
| 2322 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 2323 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 2324 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2325 | IdentifierRemap.insert( |
| 2326 | std::make_pair(IdentifierIDOffset, |
| 2327 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2328 | MacroRemap.insert(std::make_pair(MacroIDOffset, |
| 2329 | OM->BaseMacroID - MacroIDOffset)); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2330 | PreprocessedEntityRemap.insert( |
| 2331 | std::make_pair(PreprocessedEntityIDOffset, |
| 2332 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2333 | SubmoduleRemap.insert(std::make_pair(SubmoduleIDOffset, |
| 2334 | OM->BaseSubmoduleID - SubmoduleIDOffset)); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2335 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 2336 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2337 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 2338 | OM->BaseDeclID - DeclIDOffset)); |
| 2339 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2340 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2341 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2342 | |
| 2343 | // Global -> local mappings. |
| 2344 | F.GlobalToLocalDeclIDs[OM] = DeclIDOffset; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2345 | } |
| 2346 | break; |
| 2347 | } |
| 2348 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2349 | case SOURCE_MANAGER_LINE_TABLE: |
| 2350 | if (ParseLineTable(F, Record)) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2351 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2352 | break; |
| 2353 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2354 | case SOURCE_LOCATION_PRELOADS: { |
| 2355 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2356 | // which is based off F.SLocEntryBaseID. |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2357 | if (!F.PreloadSLocEntries.empty()) { |
| 2358 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2359 | return true; |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | F.PreloadSLocEntries.swap(Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2363 | break; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2364 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2365 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2366 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2367 | if (!DisableStatCache) { |
| 2368 | ASTStatCache *MyStatCache = |
| 2369 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2370 | (const unsigned char *)BlobStart, |
| 2371 | NumStatHits, NumStatMisses); |
| 2372 | FileMgr.addStatCache(MyStatCache); |
| 2373 | F.StatCache = MyStatCache; |
| 2374 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2375 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2376 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2377 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2378 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2379 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2380 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2381 | break; |
| 2382 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2383 | case VTABLE_USES: |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2384 | if (Record.size() % 3 != 0) { |
| 2385 | Error("Invalid VTABLE_USES record"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2386 | return true; |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2389 | // Later tables overwrite earlier ones. |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2390 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2391 | // the right way to do this. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2392 | VTableUses.clear(); |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2393 | |
| 2394 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2395 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2396 | VTableUses.push_back( |
| 2397 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2398 | VTableUses.push_back(Record[Idx++]); |
| 2399 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2400 | break; |
| 2401 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2402 | case DYNAMIC_CLASSES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2403 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2404 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2405 | break; |
| 2406 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2407 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2408 | if (PendingInstantiations.size() % 2 != 0) { |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 2409 | Error("Invalid existing PendingInstantiations"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2410 | return true; |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | if (Record.size() % 2 != 0) { |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2414 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2415 | return true; |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2416 | } |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 2417 | |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2418 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2419 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2420 | PendingInstantiations.push_back( |
| 2421 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2422 | } |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2423 | break; |
| 2424 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2425 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2426 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2427 | // FIXME: Modules will have some trouble with this. |
| 2428 | SemaDeclRefs.clear(); |
| 2429 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2430 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2431 | break; |
| 2432 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2433 | case PPD_ENTITIES_OFFSETS: { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2434 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)BlobStart; |
| 2435 | assert(BlobLen % sizeof(PPEntityOffset) == 0); |
| 2436 | F.NumPreprocessedEntities = BlobLen / sizeof(PPEntityOffset); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2437 | |
| 2438 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2439 | |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2440 | unsigned StartingID; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2441 | if (!PP.getPreprocessingRecord()) |
Argyrios Kyrtzidis | c6c5452 | 2012-03-05 05:48:17 +0000 | [diff] [blame] | 2442 | PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2443 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2444 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2445 | StartingID |
| 2446 | = PP.getPreprocessingRecord() |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2447 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2448 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2449 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2450 | if (F.NumPreprocessedEntities > 0) { |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2451 | // Introduce the global -> local mapping for preprocessed entities in |
| 2452 | // this module. |
| 2453 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2454 | |
| 2455 | // Introduce the local -> global mapping for preprocessed entities in |
| 2456 | // this module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2457 | F.PreprocessedEntityRemap.insertOrReplace( |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2458 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2459 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2460 | } |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2461 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2462 | break; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2463 | } |
| 2464 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2465 | case DECL_UPDATE_OFFSETS: { |
| 2466 | if (Record.size() % 2 != 0) { |
| 2467 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2468 | return true; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2469 | } |
| 2470 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2471 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2472 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2473 | break; |
| 2474 | } |
| 2475 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2476 | case DECL_REPLACEMENTS: { |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2477 | if (Record.size() % 3 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2478 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2479 | return true; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2480 | } |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2481 | for (unsigned I = 0, N = Record.size(); I != N; I += 3) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2482 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2483 | = ReplacedDeclInfo(&F, Record[I+1], Record[I+2]); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2484 | break; |
| 2485 | } |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2486 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2487 | case OBJC_CATEGORIES_MAP: { |
| 2488 | if (F.LocalNumObjCCategoriesInMap != 0) { |
| 2489 | Error("duplicate OBJC_CATEGORIES_MAP record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2490 | return true; |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2491 | } |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2492 | |
| 2493 | F.LocalNumObjCCategoriesInMap = Record[0]; |
| 2494 | F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)BlobStart; |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2495 | break; |
| 2496 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2497 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2498 | case OBJC_CATEGORIES: |
| 2499 | F.ObjCCategories.swap(Record); |
| 2500 | break; |
| 2501 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2502 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2503 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2504 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2505 | return true; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2509 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2510 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2511 | break; |
| 2512 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2513 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2514 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2515 | if (Record.size() % 2 != 0) { |
| 2516 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2517 | return true; |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2518 | } |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2519 | |
| 2520 | if (F.PragmaDiagMappings.empty()) |
| 2521 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2522 | else |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2523 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2524 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2525 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2526 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2527 | case CUDA_SPECIAL_DECL_REFS: |
| 2528 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2529 | // FIXME: Modules will have trouble with this. |
| 2530 | CUDASpecialDeclRefs.clear(); |
| 2531 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2532 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2533 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2534 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2535 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2536 | F.HeaderFileInfoTableData = BlobStart; |
| 2537 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2538 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2539 | if (Record[0]) { |
| 2540 | F.HeaderFileInfoTable |
| 2541 | = HeaderFileInfoLookupTable::Create( |
| 2542 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2543 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2544 | HeaderFileInfoTrait(*this, F, |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2545 | &PP.getHeaderSearchInfo(), |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2546 | BlobStart + Record[2])); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2547 | |
| 2548 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 2549 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 2550 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2551 | } |
| 2552 | break; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2553 | } |
| 2554 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2555 | case FP_PRAGMA_OPTIONS: |
| 2556 | // Later tables overwrite earlier ones. |
| 2557 | FPPragmaOptions.swap(Record); |
| 2558 | break; |
| 2559 | |
| 2560 | case OPENCL_EXTENSIONS: |
| 2561 | // Later tables overwrite earlier ones. |
| 2562 | OpenCLExtensions.swap(Record); |
| 2563 | break; |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2564 | |
| 2565 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2566 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2567 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2568 | break; |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2569 | |
| 2570 | case KNOWN_NAMESPACES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2571 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2572 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2573 | break; |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2574 | |
| 2575 | case IMPORTED_MODULES: { |
| 2576 | if (F.Kind != MK_Module) { |
| 2577 | // If we aren't loading a module (which has its own exports), make |
| 2578 | // all of the imported modules visible. |
| 2579 | // FIXME: Deal with macros-only imports. |
| 2580 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 2581 | if (unsigned GlobalID = getGlobalSubmoduleID(F, Record[I])) |
| 2582 | ImportedModules.push_back(GlobalID); |
| 2583 | } |
| 2584 | } |
| 2585 | break; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2586 | } |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2587 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2588 | case LOCAL_REDECLARATIONS: { |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2589 | F.RedeclarationChains.swap(Record); |
| 2590 | break; |
| 2591 | } |
| 2592 | |
| 2593 | case LOCAL_REDECLARATIONS_MAP: { |
| 2594 | if (F.LocalNumRedeclarationsInMap != 0) { |
| 2595 | Error("duplicate LOCAL_REDECLARATIONS_MAP record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2596 | return true; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2597 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2598 | |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2599 | F.LocalNumRedeclarationsInMap = Record[0]; |
| 2600 | F.RedeclarationsMap = (const LocalRedeclarationsInfo *)BlobStart; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2601 | break; |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2602 | } |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 2603 | |
| 2604 | case MERGED_DECLARATIONS: { |
| 2605 | for (unsigned Idx = 0; Idx < Record.size(); /* increment in loop */) { |
| 2606 | GlobalDeclID CanonID = getGlobalDeclID(F, Record[Idx++]); |
| 2607 | SmallVectorImpl<GlobalDeclID> &Decls = StoredMergedDecls[CanonID]; |
| 2608 | for (unsigned N = Record[Idx++]; N > 0; --N) |
| 2609 | Decls.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2610 | } |
| 2611 | break; |
| 2612 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2613 | |
| 2614 | case MACRO_OFFSET: { |
| 2615 | if (F.LocalNumMacros != 0) { |
| 2616 | Error("duplicate MACRO_OFFSET record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2617 | return true; |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2618 | } |
| 2619 | F.MacroOffsets = (const uint32_t *)BlobStart; |
| 2620 | F.LocalNumMacros = Record[0]; |
| 2621 | unsigned LocalBaseMacroID = Record[1]; |
| 2622 | F.BaseMacroID = getTotalNumMacros(); |
| 2623 | |
| 2624 | if (F.LocalNumMacros > 0) { |
| 2625 | // Introduce the global -> local mapping for macros within this module. |
| 2626 | GlobalMacroMap.insert(std::make_pair(getTotalNumMacros() + 1, &F)); |
| 2627 | |
| 2628 | // Introduce the local -> global mapping for macros within this module. |
| 2629 | F.MacroRemap.insertOrReplace( |
| 2630 | std::make_pair(LocalBaseMacroID, |
| 2631 | F.BaseMacroID - LocalBaseMacroID)); |
| 2632 | |
| 2633 | MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros); |
| 2634 | } |
| 2635 | break; |
| 2636 | } |
| 2637 | |
| 2638 | case MACRO_UPDATES: { |
| 2639 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2640 | MacroID ID = getGlobalMacroID(F, Record[I++]); |
| 2641 | if (I == N) |
| 2642 | break; |
| 2643 | |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 2644 | SourceLocation UndefLoc = ReadSourceLocation(F, Record, I); |
| 2645 | SubmoduleID SubmoduleID = getGlobalSubmoduleID(F, Record[I++]);; |
| 2646 | MacroUpdate Update; |
| 2647 | Update.UndefLoc = UndefLoc; |
| 2648 | MacroUpdates[ID].push_back(std::make_pair(SubmoduleID, Update)); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2649 | } |
| 2650 | break; |
| 2651 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2652 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2653 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2654 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2655 | return true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2656 | } |
| 2657 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2658 | void ASTReader::makeNamesVisible(const HiddenNames &Names) { |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2659 | for (unsigned I = 0, N = Names.size(); I != N; ++I) { |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 2660 | switch (Names[I].getKind()) { |
| 2661 | case HiddenName::Declaration: |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 2662 | Names[I].getDecl()->Hidden = false; |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 2663 | break; |
| 2664 | |
| 2665 | case HiddenName::MacroVisibility: { |
| 2666 | std::pair<IdentifierInfo *, MacroInfo *> Macro = Names[I].getMacro(); |
| 2667 | Macro.second->setHidden(!Macro.second->isPublic()); |
| 2668 | if (Macro.second->isDefined()) { |
| 2669 | PP.makeLoadedMacroInfoVisible(Macro.first, Macro.second); |
| 2670 | } |
| 2671 | break; |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 2672 | } |
| 2673 | |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 2674 | case HiddenName::MacroUndef: { |
| 2675 | std::pair<IdentifierInfo *, MacroInfo *> Macro = Names[I].getMacro(); |
| 2676 | if (Macro.second->isDefined()) { |
| 2677 | Macro.second->setUndefLoc(Names[I].getMacroUndefLoc()); |
| 2678 | if (PPMutationListener *Listener = PP.getPPMutationListener()) |
| 2679 | Listener->UndefinedMacro(Macro.second); |
| 2680 | PP.makeLoadedMacroInfoVisible(Macro.first, Macro.second); |
| 2681 | } |
| 2682 | break; |
| 2683 | } |
Douglas Gregor | 1d4c113 | 2011-12-20 22:06:13 +0000 | [diff] [blame] | 2684 | } |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2685 | } |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2686 | } |
| 2687 | |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2688 | void ASTReader::makeModuleVisible(Module *Mod, |
| 2689 | Module::NameVisibilityKind NameVisibility) { |
| 2690 | llvm::SmallPtrSet<Module *, 4> Visited; |
| 2691 | llvm::SmallVector<Module *, 4> Stack; |
| 2692 | Stack.push_back(Mod); |
| 2693 | while (!Stack.empty()) { |
| 2694 | Mod = Stack.back(); |
| 2695 | Stack.pop_back(); |
| 2696 | |
| 2697 | if (NameVisibility <= Mod->NameVisibility) { |
| 2698 | // This module already has this level of visibility (or greater), so |
| 2699 | // there is nothing more to do. |
| 2700 | continue; |
| 2701 | } |
| 2702 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2703 | if (!Mod->isAvailable()) { |
| 2704 | // Modules that aren't available cannot be made visible. |
| 2705 | continue; |
| 2706 | } |
| 2707 | |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2708 | // Update the module's name visibility. |
| 2709 | Mod->NameVisibility = NameVisibility; |
| 2710 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2711 | // If we've already deserialized any names from this module, |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2712 | // mark them as visible. |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2713 | HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod); |
| 2714 | if (Hidden != HiddenNamesMap.end()) { |
| 2715 | makeNamesVisible(Hidden->second); |
| 2716 | HiddenNamesMap.erase(Hidden); |
| 2717 | } |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2718 | |
| 2719 | // Push any non-explicit submodules onto the stack to be marked as |
| 2720 | // visible. |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2721 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2722 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2723 | Sub != SubEnd; ++Sub) { |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2724 | if (!(*Sub)->IsExplicit && Visited.insert(*Sub)) |
| 2725 | Stack.push_back(*Sub); |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2726 | } |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2727 | |
| 2728 | // Push any exported modules onto the stack to be marked as visible. |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2729 | bool AnyWildcard = false; |
| 2730 | bool UnrestrictedWildcard = false; |
| 2731 | llvm::SmallVector<Module *, 4> WildcardRestrictions; |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2732 | for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { |
| 2733 | Module *Exported = Mod->Exports[I].getPointer(); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2734 | if (!Mod->Exports[I].getInt()) { |
| 2735 | // Export a named module directly; no wildcards involved. |
| 2736 | if (Visited.insert(Exported)) |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2737 | Stack.push_back(Exported); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2738 | |
| 2739 | continue; |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2740 | } |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2741 | |
| 2742 | // Wildcard export: export all of the imported modules that match |
| 2743 | // the given pattern. |
| 2744 | AnyWildcard = true; |
| 2745 | if (UnrestrictedWildcard) |
| 2746 | continue; |
| 2747 | |
| 2748 | if (Module *Restriction = Mod->Exports[I].getPointer()) |
| 2749 | WildcardRestrictions.push_back(Restriction); |
| 2750 | else { |
| 2751 | WildcardRestrictions.clear(); |
| 2752 | UnrestrictedWildcard = true; |
| 2753 | } |
| 2754 | } |
| 2755 | |
| 2756 | // If there were any wildcards, push any imported modules that were |
| 2757 | // re-exported by the wildcard restriction. |
| 2758 | if (!AnyWildcard) |
| 2759 | continue; |
| 2760 | |
| 2761 | for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { |
| 2762 | Module *Imported = Mod->Imports[I]; |
Benjamin Kramer | d48bcb2 | 2012-08-22 15:37:55 +0000 | [diff] [blame] | 2763 | if (!Visited.insert(Imported)) |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2764 | continue; |
| 2765 | |
| 2766 | bool Acceptable = UnrestrictedWildcard; |
| 2767 | if (!Acceptable) { |
| 2768 | // Check whether this module meets one of the restrictions. |
| 2769 | for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) { |
| 2770 | Module *Restriction = WildcardRestrictions[R]; |
| 2771 | if (Imported == Restriction || Imported->isSubModuleOf(Restriction)) { |
| 2772 | Acceptable = true; |
| 2773 | break; |
| 2774 | } |
| 2775 | } |
| 2776 | } |
| 2777 | |
| 2778 | if (!Acceptable) |
| 2779 | continue; |
| 2780 | |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2781 | Stack.push_back(Imported); |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2782 | } |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2783 | } |
| 2784 | } |
| 2785 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2786 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2787 | ModuleKind Type, |
| 2788 | unsigned ClientLoadCapabilities) { |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2789 | // Bump the generation number. |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2790 | unsigned PreviousGeneration = CurrentGeneration++; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2791 | |
| 2792 | // Load the core of the AST files. |
| 2793 | llvm::SmallVector<ModuleFile *, 4> Loaded; |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2794 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0, Loaded, |
| 2795 | ClientLoadCapabilities)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2796 | case Failure: return Failure; |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2797 | case OutOfDate: return OutOfDate; |
| 2798 | case VersionMismatch: return VersionMismatch; |
| 2799 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 2800 | case HadErrors: return HadErrors; |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2801 | case Success: break; |
| 2802 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2803 | |
| 2804 | // 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] | 2805 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2806 | // Load the AST blocks of all of the modules that we loaded. |
| 2807 | for (llvm::SmallVectorImpl<ModuleFile *>::iterator M = Loaded.begin(), |
| 2808 | MEnd = Loaded.end(); |
| 2809 | M != MEnd; ++M) { |
| 2810 | ModuleFile &F = **M; |
| 2811 | |
| 2812 | // Read the AST block. |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2813 | if (ReadASTBlock(F)) |
| 2814 | return Failure; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2815 | |
| 2816 | // Once read, set the ModuleFile bit base offset and update the size in |
| 2817 | // bits of all files we've seen. |
| 2818 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 2819 | TotalModulesSizeInBits += F.SizeInBits; |
| 2820 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
| 2821 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2822 | // Preload SLocEntries. |
| 2823 | for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) { |
| 2824 | int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
Douglas Gregor | 8b53d14 | 2012-10-22 22:53:10 +0000 | [diff] [blame] | 2825 | // Load it through the SourceManager and don't call ReadSLocEntry() |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2826 | // directly because the entry may have already been loaded in which case |
Douglas Gregor | 8b53d14 | 2012-10-22 22:53:10 +0000 | [diff] [blame] | 2827 | // calling ReadSLocEntry() directly would trigger an assertion in |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2828 | // SourceManager. |
| 2829 | SourceMgr.getLoadedSLocEntryByID(Index); |
| 2830 | } |
| 2831 | } |
| 2832 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2833 | // Mark all of the identifiers in the identifier table as being out of date, |
| 2834 | // so that various accessors know to check the loaded modules when the |
| 2835 | // identifier is used. |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2836 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 2837 | IdEnd = PP.getIdentifierTable().end(); |
| 2838 | Id != IdEnd; ++Id) |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2839 | Id->second->setOutOfDate(true); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2840 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2841 | // Resolve any unresolved module exports. |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2842 | for (unsigned I = 0, N = UnresolvedModuleImportExports.size(); I != N; ++I) { |
| 2843 | UnresolvedModuleImportExport &Unresolved = UnresolvedModuleImportExports[I]; |
| 2844 | SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2845 | Module *ResolvedMod = getSubmodule(GlobalID); |
| 2846 | |
| 2847 | if (Unresolved.IsImport) { |
| 2848 | if (ResolvedMod) |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2849 | Unresolved.Mod->Imports.push_back(ResolvedMod); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2850 | continue; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2851 | } |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2852 | |
| 2853 | if (ResolvedMod || Unresolved.IsWildcard) |
| 2854 | Unresolved.Mod->Exports.push_back( |
| 2855 | Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard)); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2856 | } |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2857 | UnresolvedModuleImportExports.clear(); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2858 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2859 | InitializeContext(); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2860 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2861 | if (DeserializationListener) |
| 2862 | DeserializationListener->ReaderInitialized(this); |
| 2863 | |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 2864 | ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule(); |
| 2865 | if (!PrimaryModule.OriginalSourceFileID.isInvalid()) { |
| 2866 | PrimaryModule.OriginalSourceFileID |
| 2867 | = FileID::get(PrimaryModule.SLocEntryBaseID |
| 2868 | + PrimaryModule.OriginalSourceFileID.getOpaqueValue() - 1); |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 2869 | |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 2870 | // If this AST file is a precompiled preamble, then set the |
| 2871 | // preamble file ID of the source manager to the file source file |
| 2872 | // from which the preamble was built. |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 2873 | if (Type == MK_Preamble) { |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 2874 | SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID); |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 2875 | } else if (Type == MK_MainFile) { |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 2876 | SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2877 | } |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2878 | } |
| 2879 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2880 | // For any Objective-C class definitions we have already loaded, make sure |
| 2881 | // that we load any additional categories. |
| 2882 | for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { |
| 2883 | loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), |
| 2884 | ObjCClassesLoaded[I], |
| 2885 | PreviousGeneration); |
| 2886 | } |
| 2887 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2888 | return Success; |
| 2889 | } |
| 2890 | |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2891 | ASTReader::ASTReadResult |
| 2892 | ASTReader::ReadASTCore(StringRef FileName, |
| 2893 | ModuleKind Type, |
| 2894 | ModuleFile *ImportedBy, |
| 2895 | llvm::SmallVectorImpl<ModuleFile *> &Loaded, |
| 2896 | unsigned ClientLoadCapabilities) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2897 | ModuleFile *M; |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2898 | bool NewModule; |
| 2899 | std::string ErrorStr; |
| 2900 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2901 | CurrentGeneration, ErrorStr); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2902 | |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2903 | if (!M) { |
| 2904 | // We couldn't load the module. |
| 2905 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 2906 | + ErrorStr; |
| 2907 | Error(Msg); |
| 2908 | return Failure; |
| 2909 | } |
| 2910 | |
| 2911 | if (!NewModule) { |
| 2912 | // We've already loaded this module. |
| 2913 | return Success; |
| 2914 | } |
| 2915 | |
| 2916 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 2917 | // module? |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2918 | if (FileName != "-") { |
| 2919 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2920 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2921 | } |
| 2922 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2923 | ModuleFile &F = *M; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2924 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2925 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2926 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2927 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2928 | // Sniff for the signature. |
| 2929 | if (Stream.Read(8) != 'C' || |
| 2930 | Stream.Read(8) != 'P' || |
| 2931 | Stream.Read(8) != 'C' || |
| 2932 | Stream.Read(8) != 'H') { |
| 2933 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2934 | return Failure; |
| 2935 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2936 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2937 | while (!Stream.AtEndOfStream()) { |
| 2938 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2939 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2940 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2941 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2942 | return Failure; |
| 2943 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2944 | |
| 2945 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2946 | |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 2947 | // We only know the control subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2948 | switch (BlockID) { |
| 2949 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2950 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2951 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2952 | return Failure; |
| 2953 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2954 | break; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2955 | case CONTROL_BLOCK_ID: |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2956 | switch (ReadControlBlock(F, Loaded, ClientLoadCapabilities)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2957 | case Success: |
| 2958 | break; |
| 2959 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2960 | case Failure: return Failure; |
| 2961 | case OutOfDate: return OutOfDate; |
| 2962 | case VersionMismatch: return VersionMismatch; |
| 2963 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 2964 | case HadErrors: return HadErrors; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2965 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2966 | break; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2967 | case AST_BLOCK_ID: |
| 2968 | // Record that we've loaded this module. |
| 2969 | Loaded.push_back(M); |
| 2970 | return Success; |
| 2971 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2972 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2973 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2974 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2975 | return Failure; |
| 2976 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2977 | break; |
| 2978 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2979 | } |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2980 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2981 | return Success; |
| 2982 | } |
| 2983 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2984 | void ASTReader::InitializeContext() { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2985 | // If there's a listener, notify them that we "read" the translation unit. |
| 2986 | if (DeserializationListener) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2987 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2988 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2989 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2990 | // Make sure we load the declaration update records for the translation unit, |
| 2991 | // if there are any. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2992 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2993 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2994 | |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2995 | // FIXME: Find a better way to deal with collisions between these |
| 2996 | // built-in types. Right now, we just ignore the problem. |
| 2997 | |
| 2998 | // Load the special types. |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 2999 | if (SpecialTypes.size() >= NumSpecialTypeIDs) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 3000 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 3001 | if (!Context.CFConstantStringTypeDecl) |
| 3002 | Context.setCFConstantStringType(GetType(String)); |
| 3003 | } |
| 3004 | |
| 3005 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 3006 | QualType FileType = GetType(File); |
| 3007 | if (FileType.isNull()) { |
| 3008 | Error("FILE type is NULL"); |
| 3009 | return; |
| 3010 | } |
| 3011 | |
| 3012 | if (!Context.FILEDecl) { |
| 3013 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 3014 | Context.setFILEDecl(Typedef->getDecl()); |
| 3015 | else { |
| 3016 | const TagType *Tag = FileType->getAs<TagType>(); |
| 3017 | if (!Tag) { |
| 3018 | Error("Invalid FILE type in AST file"); |
| 3019 | return; |
| 3020 | } |
| 3021 | Context.setFILEDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3022 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3023 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 3024 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 3025 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 3026 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 3027 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 3028 | if (Jmp_bufType.isNull()) { |
| 3029 | Error("jmp_buf type is NULL"); |
| 3030 | return; |
| 3031 | } |
| 3032 | |
| 3033 | if (!Context.jmp_bufDecl) { |
| 3034 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 3035 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 3036 | else { |
| 3037 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 3038 | if (!Tag) { |
| 3039 | Error("Invalid jmp_buf type in AST file"); |
| 3040 | return; |
| 3041 | } |
| 3042 | Context.setjmp_bufDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3043 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3044 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 3045 | } |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 3046 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 3047 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 3048 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 3049 | if (Sigjmp_bufType.isNull()) { |
| 3050 | Error("sigjmp_buf type is NULL"); |
| 3051 | return; |
| 3052 | } |
| 3053 | |
| 3054 | if (!Context.sigjmp_bufDecl) { |
| 3055 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 3056 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 3057 | else { |
| 3058 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 3059 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 3060 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 3061 | } |
| 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | if (unsigned ObjCIdRedef |
| 3066 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 3067 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 3068 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 3069 | } |
| 3070 | |
| 3071 | if (unsigned ObjCClassRedef |
| 3072 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 3073 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 3074 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 3075 | } |
| 3076 | |
| 3077 | if (unsigned ObjCSelRedef |
| 3078 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 3079 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 3080 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 3081 | } |
Rafael Espindola | e2d4f4e | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 3082 | |
| 3083 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 3084 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 3085 | if (Ucontext_tType.isNull()) { |
| 3086 | Error("ucontext_t type is NULL"); |
| 3087 | return; |
| 3088 | } |
| 3089 | |
| 3090 | if (!Context.ucontext_tDecl) { |
| 3091 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| 3092 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 3093 | else { |
| 3094 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| 3095 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 3096 | Context.setucontext_tDecl(Tag->getDecl()); |
| 3097 | } |
| 3098 | } |
| 3099 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 3100 | } |
| 3101 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3102 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3103 | |
| 3104 | // If there were any CUDA special declarations, deserialize them. |
| 3105 | if (!CUDASpecialDeclRefs.empty()) { |
| 3106 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3107 | Context.setcudaConfigureCallDecl( |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3108 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 3109 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 3110 | |
| 3111 | // Re-export any modules that were imported by a non-module AST file. |
| 3112 | for (unsigned I = 0, N = ImportedModules.size(); I != N; ++I) { |
| 3113 | if (Module *Imported = getSubmodule(ImportedModules[I])) |
| 3114 | makeModuleVisible(Imported, Module::AllVisible); |
| 3115 | } |
| 3116 | ImportedModules.clear(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3117 | } |
| 3118 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 3119 | void ASTReader::finalizeForWriting() { |
| 3120 | for (HiddenNamesMapType::iterator Hidden = HiddenNamesMap.begin(), |
| 3121 | HiddenEnd = HiddenNamesMap.end(); |
| 3122 | Hidden != HiddenEnd; ++Hidden) { |
| 3123 | makeNamesVisible(Hidden->second); |
| 3124 | } |
| 3125 | HiddenNamesMap.clear(); |
| 3126 | } |
| 3127 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3128 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3129 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3130 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3131 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 3132 | FileManager &FileMgr, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 3133 | DiagnosticsEngine &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3134 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3135 | std::string ErrStr; |
Dylan Noblesmith | 6f42b62 | 2012-02-05 02:12:40 +0000 | [diff] [blame] | 3136 | OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 3137 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3138 | if (!Buffer) { |
Kaelyn Uhrain | da01f62 | 2012-06-20 00:36:03 +0000 | [diff] [blame] | 3139 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ASTFileName << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3140 | return std::string(); |
| 3141 | } |
| 3142 | |
| 3143 | // Initialize the stream |
| 3144 | llvm::BitstreamReader StreamFile; |
| 3145 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3146 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3147 | (const unsigned char *)Buffer->getBufferEnd()); |
| 3148 | Stream.init(StreamFile); |
| 3149 | |
| 3150 | // Sniff for the signature. |
| 3151 | if (Stream.Read(8) != 'C' || |
| 3152 | Stream.Read(8) != 'P' || |
| 3153 | Stream.Read(8) != 'C' || |
| 3154 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3155 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3156 | return std::string(); |
| 3157 | } |
| 3158 | |
| 3159 | RecordData Record; |
| 3160 | while (!Stream.AtEndOfStream()) { |
| 3161 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3162 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3163 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3164 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3165 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3166 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3167 | switch (BlockID) { |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3168 | case CONTROL_BLOCK_ID: |
| 3169 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3170 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3171 | return std::string(); |
| 3172 | } |
| 3173 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3174 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3175 | default: |
| 3176 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3177 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3178 | return std::string(); |
| 3179 | } |
| 3180 | break; |
| 3181 | } |
| 3182 | continue; |
| 3183 | } |
| 3184 | |
| 3185 | if (Code == llvm::bitc::END_BLOCK) { |
| 3186 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3187 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3188 | return std::string(); |
| 3189 | } |
| 3190 | continue; |
| 3191 | } |
| 3192 | |
| 3193 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3194 | Stream.ReadAbbrevRecord(); |
| 3195 | continue; |
| 3196 | } |
| 3197 | |
| 3198 | Record.clear(); |
| 3199 | const char *BlobStart = 0; |
| 3200 | unsigned BlobLen = 0; |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 3201 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) == ORIGINAL_FILE) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3202 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3203 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3204 | |
| 3205 | return std::string(); |
| 3206 | } |
| 3207 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3208 | namespace { |
| 3209 | class SimplePCHValidator : public ASTReaderListener { |
| 3210 | const LangOptions &ExistingLangOpts; |
| 3211 | const TargetOptions &ExistingTargetOpts; |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3212 | const PreprocessorOptions &ExistingPPOpts; |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3213 | FileManager &FileMgr; |
| 3214 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3215 | public: |
| 3216 | SimplePCHValidator(const LangOptions &ExistingLangOpts, |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3217 | const TargetOptions &ExistingTargetOpts, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3218 | const PreprocessorOptions &ExistingPPOpts, |
| 3219 | FileManager &FileMgr) |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3220 | : ExistingLangOpts(ExistingLangOpts), |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3221 | ExistingTargetOpts(ExistingTargetOpts), |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3222 | ExistingPPOpts(ExistingPPOpts), |
| 3223 | FileMgr(FileMgr) |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3224 | { |
| 3225 | } |
| 3226 | |
| 3227 | virtual bool ReadLanguageOptions(const LangOptions &LangOpts, |
| 3228 | bool Complain) { |
| 3229 | return checkLanguageOptions(ExistingLangOpts, LangOpts, 0); |
| 3230 | } |
| 3231 | virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, |
| 3232 | bool Complain) { |
| 3233 | return checkTargetOptions(ExistingTargetOpts, TargetOpts, 0); |
| 3234 | } |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3235 | virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3236 | bool Complain, |
| 3237 | std::string &SuggestedPredefines) { |
| 3238 | return checkPreprocessorOptions(ExistingPPOpts, PPOpts, 0, FileMgr, |
| 3239 | SuggestedPredefines); |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3240 | } |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3241 | }; |
| 3242 | } |
| 3243 | |
| 3244 | bool ASTReader::isAcceptableASTFile(StringRef Filename, |
| 3245 | FileManager &FileMgr, |
| 3246 | const LangOptions &LangOpts, |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3247 | const TargetOptions &TargetOpts, |
| 3248 | const PreprocessorOptions &PPOpts) { |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3249 | // Open the AST file. |
| 3250 | std::string ErrStr; |
| 3251 | OwningPtr<llvm::MemoryBuffer> Buffer; |
| 3252 | Buffer.reset(FileMgr.getBufferForFile(Filename, &ErrStr)); |
| 3253 | if (!Buffer) { |
| 3254 | return false; |
| 3255 | } |
| 3256 | |
| 3257 | // Initialize the stream |
| 3258 | llvm::BitstreamReader StreamFile; |
| 3259 | llvm::BitstreamCursor Stream; |
| 3260 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
| 3261 | (const unsigned char *)Buffer->getBufferEnd()); |
| 3262 | Stream.init(StreamFile); |
| 3263 | |
| 3264 | // Sniff for the signature. |
| 3265 | if (Stream.Read(8) != 'C' || |
| 3266 | Stream.Read(8) != 'P' || |
| 3267 | Stream.Read(8) != 'C' || |
| 3268 | Stream.Read(8) != 'H') { |
| 3269 | return false; |
| 3270 | } |
| 3271 | |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3272 | SimplePCHValidator Validator(LangOpts, TargetOpts, PPOpts, FileMgr); |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3273 | RecordData Record; |
| 3274 | bool InControlBlock = false; |
| 3275 | while (!Stream.AtEndOfStream()) { |
| 3276 | unsigned Code = Stream.ReadCode(); |
| 3277 | |
| 3278 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3279 | unsigned BlockID = Stream.ReadSubBlockID(); |
| 3280 | |
| 3281 | // We only know the control subblock ID. |
| 3282 | switch (BlockID) { |
| 3283 | case CONTROL_BLOCK_ID: |
| 3284 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
| 3285 | return false; |
| 3286 | } else { |
| 3287 | InControlBlock = true; |
| 3288 | } |
| 3289 | break; |
| 3290 | |
| 3291 | default: |
| 3292 | if (Stream.SkipBlock()) |
| 3293 | return false; |
| 3294 | break; |
| 3295 | } |
| 3296 | continue; |
| 3297 | } |
| 3298 | |
| 3299 | if (Code == llvm::bitc::END_BLOCK) { |
| 3300 | if (Stream.ReadBlockEnd()) { |
| 3301 | return false; |
| 3302 | } |
| 3303 | InControlBlock = false; |
| 3304 | continue; |
| 3305 | } |
| 3306 | |
| 3307 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3308 | Stream.ReadAbbrevRecord(); |
| 3309 | continue; |
| 3310 | } |
| 3311 | |
| 3312 | Record.clear(); |
| 3313 | const char *BlobStart = 0; |
| 3314 | unsigned BlobLen = 0; |
| 3315 | unsigned RecCode = Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
| 3316 | if (InControlBlock) { |
| 3317 | switch ((ControlRecordTypes)RecCode) { |
| 3318 | case METADATA: { |
| 3319 | if (Record[0] != VERSION_MAJOR) { |
| 3320 | return false; |
| 3321 | } |
| 3322 | |
| 3323 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
| 3324 | StringRef ASTBranch(BlobStart, BlobLen); |
| 3325 | if (StringRef(CurBranch) != ASTBranch) |
| 3326 | return false; |
| 3327 | |
| 3328 | break; |
| 3329 | } |
| 3330 | case LANGUAGE_OPTIONS: |
| 3331 | if (ParseLanguageOptions(Record, false, Validator)) |
| 3332 | return false; |
| 3333 | break; |
| 3334 | |
| 3335 | case TARGET_OPTIONS: |
| 3336 | if (ParseTargetOptions(Record, false, Validator)) |
| 3337 | return false; |
| 3338 | break; |
| 3339 | |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 3340 | case DIAGNOSTIC_OPTIONS: |
| 3341 | if (ParseDiagnosticOptions(Record, false, Validator)) |
| 3342 | return false; |
| 3343 | break; |
| 3344 | |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 3345 | case FILE_SYSTEM_OPTIONS: |
| 3346 | if (ParseFileSystemOptions(Record, false, Validator)) |
| 3347 | return false; |
| 3348 | break; |
| 3349 | |
| 3350 | case HEADER_SEARCH_OPTIONS: |
| 3351 | if (ParseHeaderSearchOptions(Record, false, Validator)) |
| 3352 | return false; |
| 3353 | break; |
| 3354 | |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3355 | case PREPROCESSOR_OPTIONS: { |
| 3356 | std::string IgnoredSuggestedPredefines; |
| 3357 | if (ParsePreprocessorOptions(Record, false, Validator, |
| 3358 | IgnoredSuggestedPredefines)) |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3359 | return false; |
| 3360 | break; |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3361 | } |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3362 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3363 | default: |
| 3364 | // No other validation to perform. |
| 3365 | break; |
| 3366 | } |
| 3367 | } |
| 3368 | } |
| 3369 | |
| 3370 | return true; |
| 3371 | } |
| 3372 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3373 | bool ASTReader::ReadSubmoduleBlock(ModuleFile &F) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3374 | // Enter the submodule block. |
| 3375 | if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) { |
| 3376 | Error("malformed submodule block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3377 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3381 | bool First = true; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3382 | Module *CurrentModule = 0; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3383 | RecordData Record; |
| 3384 | while (true) { |
| 3385 | unsigned Code = F.Stream.ReadCode(); |
| 3386 | if (Code == llvm::bitc::END_BLOCK) { |
| 3387 | if (F.Stream.ReadBlockEnd()) { |
| 3388 | Error("error at end of submodule block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3389 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3390 | } |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3391 | return false; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3395 | // No known subblocks, always skip them. |
| 3396 | F.Stream.ReadSubBlockID(); |
| 3397 | if (F.Stream.SkipBlock()) { |
| 3398 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3399 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3400 | } |
| 3401 | continue; |
| 3402 | } |
| 3403 | |
| 3404 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3405 | F.Stream.ReadAbbrevRecord(); |
| 3406 | continue; |
| 3407 | } |
| 3408 | |
| 3409 | // Read a record. |
| 3410 | const char *BlobStart; |
| 3411 | unsigned BlobLen; |
| 3412 | Record.clear(); |
| 3413 | switch (F.Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 3414 | default: // Default behavior: ignore. |
| 3415 | break; |
| 3416 | |
| 3417 | case SUBMODULE_DEFINITION: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3418 | if (First) { |
| 3419 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3420 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3421 | } |
| 3422 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3423 | if (Record.size() < 7) { |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3424 | Error("malformed module definition"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3425 | return true; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3426 | } |
| 3427 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3428 | StringRef Name(BlobStart, BlobLen); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3429 | SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[0]); |
| 3430 | SubmoduleID Parent = getGlobalSubmoduleID(F, Record[1]); |
| 3431 | bool IsFramework = Record[2]; |
| 3432 | bool IsExplicit = Record[3]; |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 3433 | bool IsSystem = Record[4]; |
| 3434 | bool InferSubmodules = Record[5]; |
| 3435 | bool InferExplicitSubmodules = Record[6]; |
| 3436 | bool InferExportWildcard = Record[7]; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3437 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3438 | Module *ParentModule = 0; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3439 | if (Parent) |
| 3440 | ParentModule = getSubmodule(Parent); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3441 | |
| 3442 | // Retrieve this (sub)module from the module map, creating it if |
| 3443 | // necessary. |
| 3444 | CurrentModule = ModMap.findOrCreateModule(Name, ParentModule, |
| 3445 | IsFramework, |
| 3446 | IsExplicit).first; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3447 | SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS; |
| 3448 | if (GlobalIndex >= SubmodulesLoaded.size() || |
| 3449 | SubmodulesLoaded[GlobalIndex]) { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3450 | Error("too many submodules"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3451 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3452 | } |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3453 | |
Argyrios Kyrtzidis | d64c26f | 2012-10-03 01:58:42 +0000 | [diff] [blame] | 3454 | CurrentModule->setASTFile(F.File); |
Douglas Gregor | 305dc3e | 2011-12-20 00:28:52 +0000 | [diff] [blame] | 3455 | CurrentModule->IsFromModuleFile = true; |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 3456 | CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3457 | CurrentModule->InferSubmodules = InferSubmodules; |
| 3458 | CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; |
| 3459 | CurrentModule->InferExportWildcard = InferExportWildcard; |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3460 | if (DeserializationListener) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3461 | DeserializationListener->ModuleRead(GlobalID, CurrentModule); |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3462 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3463 | SubmodulesLoaded[GlobalIndex] = CurrentModule; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3464 | break; |
| 3465 | } |
| 3466 | |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3467 | case SUBMODULE_UMBRELLA_HEADER: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3468 | if (First) { |
| 3469 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3470 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3471 | } |
| 3472 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3473 | if (!CurrentModule) |
| 3474 | break; |
| 3475 | |
| 3476 | StringRef FileName(BlobStart, BlobLen); |
| 3477 | if (const FileEntry *Umbrella = PP.getFileManager().getFile(FileName)) { |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 3478 | if (!CurrentModule->getUmbrellaHeader()) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3479 | ModMap.setUmbrellaHeader(CurrentModule, Umbrella); |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 3480 | else if (CurrentModule->getUmbrellaHeader() != Umbrella) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3481 | Error("mismatched umbrella headers in submodule"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3482 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3483 | } |
| 3484 | } |
| 3485 | break; |
| 3486 | } |
| 3487 | |
| 3488 | case SUBMODULE_HEADER: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3489 | if (First) { |
| 3490 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3491 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3492 | } |
| 3493 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3494 | if (!CurrentModule) |
| 3495 | break; |
| 3496 | |
| 3497 | // FIXME: Be more lazy about this! |
| 3498 | StringRef FileName(BlobStart, BlobLen); |
| 3499 | if (const FileEntry *File = PP.getFileManager().getFile(FileName)) { |
| 3500 | if (std::find(CurrentModule->Headers.begin(), |
| 3501 | CurrentModule->Headers.end(), |
| 3502 | File) == CurrentModule->Headers.end()) |
Douglas Gregor | 2b49d1f | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 3503 | ModMap.addHeader(CurrentModule, File, false); |
| 3504 | } |
| 3505 | break; |
| 3506 | } |
| 3507 | |
| 3508 | case SUBMODULE_EXCLUDED_HEADER: { |
| 3509 | if (First) { |
| 3510 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3511 | return true; |
Douglas Gregor | 2b49d1f | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | if (!CurrentModule) |
| 3515 | break; |
| 3516 | |
| 3517 | // FIXME: Be more lazy about this! |
| 3518 | StringRef FileName(BlobStart, BlobLen); |
| 3519 | if (const FileEntry *File = PP.getFileManager().getFile(FileName)) { |
| 3520 | if (std::find(CurrentModule->Headers.begin(), |
| 3521 | CurrentModule->Headers.end(), |
| 3522 | File) == CurrentModule->Headers.end()) |
| 3523 | ModMap.addHeader(CurrentModule, File, true); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3524 | } |
| 3525 | break; |
| 3526 | } |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 3527 | |
| 3528 | case SUBMODULE_TOPHEADER: { |
| 3529 | if (First) { |
| 3530 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3531 | return true; |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 3532 | } |
| 3533 | |
| 3534 | if (!CurrentModule) |
| 3535 | break; |
| 3536 | |
| 3537 | // FIXME: Be more lazy about this! |
| 3538 | StringRef FileName(BlobStart, BlobLen); |
| 3539 | if (const FileEntry *File = PP.getFileManager().getFile(FileName)) |
| 3540 | CurrentModule->TopHeaders.insert(File); |
| 3541 | break; |
| 3542 | } |
| 3543 | |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3544 | case SUBMODULE_UMBRELLA_DIR: { |
| 3545 | if (First) { |
| 3546 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3547 | return true; |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3548 | } |
| 3549 | |
| 3550 | if (!CurrentModule) |
| 3551 | break; |
| 3552 | |
| 3553 | StringRef DirName(BlobStart, BlobLen); |
| 3554 | if (const DirectoryEntry *Umbrella |
| 3555 | = PP.getFileManager().getDirectory(DirName)) { |
| 3556 | if (!CurrentModule->getUmbrellaDir()) |
| 3557 | ModMap.setUmbrellaDir(CurrentModule, Umbrella); |
| 3558 | else if (CurrentModule->getUmbrellaDir() != Umbrella) { |
| 3559 | Error("mismatched umbrella directories in submodule"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3560 | return true; |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3561 | } |
| 3562 | } |
| 3563 | break; |
| 3564 | } |
| 3565 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3566 | case SUBMODULE_METADATA: { |
| 3567 | if (!First) { |
| 3568 | Error("submodule metadata record not at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3569 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3570 | } |
| 3571 | First = false; |
| 3572 | |
| 3573 | F.BaseSubmoduleID = getTotalNumSubmodules(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3574 | F.LocalNumSubmodules = Record[0]; |
| 3575 | unsigned LocalBaseSubmoduleID = Record[1]; |
| 3576 | if (F.LocalNumSubmodules > 0) { |
| 3577 | // Introduce the global -> local mapping for submodules within this |
| 3578 | // module. |
| 3579 | GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F)); |
| 3580 | |
| 3581 | // Introduce the local -> global mapping for submodules within this |
| 3582 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 3583 | F.SubmoduleRemap.insertOrReplace( |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3584 | std::make_pair(LocalBaseSubmoduleID, |
| 3585 | F.BaseSubmoduleID - LocalBaseSubmoduleID)); |
| 3586 | |
| 3587 | SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules); |
| 3588 | } |
| 3589 | break; |
| 3590 | } |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3591 | |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3592 | case SUBMODULE_IMPORTS: { |
| 3593 | if (First) { |
| 3594 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3595 | return true; |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3596 | } |
| 3597 | |
| 3598 | if (!CurrentModule) |
| 3599 | break; |
| 3600 | |
| 3601 | for (unsigned Idx = 0; Idx != Record.size(); ++Idx) { |
| 3602 | UnresolvedModuleImportExport Unresolved; |
| 3603 | Unresolved.File = &F; |
| 3604 | Unresolved.Mod = CurrentModule; |
| 3605 | Unresolved.ID = Record[Idx]; |
| 3606 | Unresolved.IsImport = true; |
| 3607 | Unresolved.IsWildcard = false; |
| 3608 | UnresolvedModuleImportExports.push_back(Unresolved); |
| 3609 | } |
| 3610 | break; |
| 3611 | } |
| 3612 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3613 | case SUBMODULE_EXPORTS: { |
| 3614 | if (First) { |
| 3615 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3616 | return true; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3617 | } |
| 3618 | |
| 3619 | if (!CurrentModule) |
| 3620 | break; |
| 3621 | |
| 3622 | for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3623 | UnresolvedModuleImportExport Unresolved; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3624 | Unresolved.File = &F; |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3625 | Unresolved.Mod = CurrentModule; |
| 3626 | Unresolved.ID = Record[Idx]; |
| 3627 | Unresolved.IsImport = false; |
| 3628 | Unresolved.IsWildcard = Record[Idx + 1]; |
| 3629 | UnresolvedModuleImportExports.push_back(Unresolved); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3630 | } |
| 3631 | |
| 3632 | // Once we've loaded the set of exports, there's no reason to keep |
| 3633 | // the parsed, unresolved exports around. |
| 3634 | CurrentModule->UnresolvedExports.clear(); |
| 3635 | break; |
| 3636 | } |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3637 | case SUBMODULE_REQUIRES: { |
| 3638 | if (First) { |
| 3639 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3640 | return true; |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | if (!CurrentModule) |
| 3644 | break; |
| 3645 | |
| 3646 | CurrentModule->addRequirement(StringRef(BlobStart, BlobLen), |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3647 | Context.getLangOpts(), |
Douglas Gregor | dc58aa7 | 2012-01-30 06:01:29 +0000 | [diff] [blame] | 3648 | Context.getTargetInfo()); |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3649 | break; |
| 3650 | } |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3651 | } |
| 3652 | } |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3653 | } |
| 3654 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3655 | /// \brief Parse the record that corresponds to a LangOptions data |
| 3656 | /// structure. |
| 3657 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3658 | /// This routine parses the language options from the AST file and then gives |
| 3659 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3660 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3661 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3662 | bool ASTReader::ParseLanguageOptions(const RecordData &Record, |
| 3663 | bool Complain, |
| 3664 | ASTReaderListener &Listener) { |
| 3665 | LangOptions LangOpts; |
| 3666 | unsigned Idx = 0; |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 3667 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 3668 | LangOpts.Name = Record[Idx++]; |
| 3669 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 3670 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 3671 | #include "clang/Basic/LangOptions.def" |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3672 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3673 | ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++]; |
| 3674 | VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx); |
| 3675 | LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion); |
| 3676 | |
| 3677 | unsigned Length = Record[Idx++]; |
| 3678 | LangOpts.CurrentModule.assign(Record.begin() + Idx, |
| 3679 | Record.begin() + Idx + Length); |
| 3680 | return Listener.ReadLanguageOptions(LangOpts, Complain); |
| 3681 | } |
| 3682 | |
| 3683 | bool ASTReader::ParseTargetOptions(const RecordData &Record, |
| 3684 | bool Complain, |
| 3685 | ASTReaderListener &Listener) { |
| 3686 | unsigned Idx = 0; |
| 3687 | TargetOptions TargetOpts; |
| 3688 | TargetOpts.Triple = ReadString(Record, Idx); |
| 3689 | TargetOpts.CPU = ReadString(Record, Idx); |
| 3690 | TargetOpts.ABI = ReadString(Record, Idx); |
| 3691 | TargetOpts.CXXABI = ReadString(Record, Idx); |
| 3692 | TargetOpts.LinkerVersion = ReadString(Record, Idx); |
| 3693 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3694 | TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx)); |
| 3695 | } |
| 3696 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3697 | TargetOpts.Features.push_back(ReadString(Record, Idx)); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3698 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3699 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3700 | return Listener.ReadTargetOptions(TargetOpts, Complain); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3701 | } |
| 3702 | |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 3703 | bool ASTReader::ParseDiagnosticOptions(const RecordData &Record, bool Complain, |
| 3704 | ASTReaderListener &Listener) { |
| 3705 | DiagnosticOptions DiagOpts; |
| 3706 | unsigned Idx = 0; |
| 3707 | #define DIAGOPT(Name, Bits, Default) DiagOpts.Name = Record[Idx++]; |
| 3708 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 3709 | DiagOpts.set##Name(static_cast<Type>(Record[Idx++])); |
| 3710 | #include "clang/Basic/DiagnosticOptions.def" |
| 3711 | |
| 3712 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3713 | DiagOpts.Warnings.push_back(ReadString(Record, Idx)); |
| 3714 | } |
| 3715 | |
| 3716 | return Listener.ReadDiagnosticOptions(DiagOpts, Complain); |
| 3717 | } |
| 3718 | |
Douglas Gregor | 1b2c3c0 | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 3719 | bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain, |
| 3720 | ASTReaderListener &Listener) { |
| 3721 | FileSystemOptions FSOpts; |
| 3722 | unsigned Idx = 0; |
| 3723 | FSOpts.WorkingDir = ReadString(Record, Idx); |
| 3724 | return Listener.ReadFileSystemOptions(FSOpts, Complain); |
| 3725 | } |
| 3726 | |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 3727 | bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record, |
| 3728 | bool Complain, |
| 3729 | ASTReaderListener &Listener) { |
| 3730 | HeaderSearchOptions HSOpts; |
| 3731 | unsigned Idx = 0; |
| 3732 | HSOpts.Sysroot = ReadString(Record, Idx); |
| 3733 | |
| 3734 | // Include entries. |
| 3735 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3736 | std::string Path = ReadString(Record, Idx); |
| 3737 | frontend::IncludeDirGroup Group |
| 3738 | = static_cast<frontend::IncludeDirGroup>(Record[Idx++]); |
| 3739 | bool IsUserSupplied = Record[Idx++]; |
| 3740 | bool IsFramework = Record[Idx++]; |
| 3741 | bool IgnoreSysRoot = Record[Idx++]; |
| 3742 | bool IsInternal = Record[Idx++]; |
| 3743 | bool ImplicitExternC = Record[Idx++]; |
| 3744 | HSOpts.UserEntries.push_back( |
| 3745 | HeaderSearchOptions::Entry(Path, Group, IsUserSupplied, IsFramework, |
| 3746 | IgnoreSysRoot, IsInternal, ImplicitExternC)); |
| 3747 | } |
| 3748 | |
| 3749 | // System header prefixes. |
| 3750 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3751 | std::string Prefix = ReadString(Record, Idx); |
| 3752 | bool IsSystemHeader = Record[Idx++]; |
| 3753 | HSOpts.SystemHeaderPrefixes.push_back( |
| 3754 | HeaderSearchOptions::SystemHeaderPrefix(Prefix, IsSystemHeader)); |
| 3755 | } |
| 3756 | |
| 3757 | HSOpts.ResourceDir = ReadString(Record, Idx); |
| 3758 | HSOpts.ModuleCachePath = ReadString(Record, Idx); |
| 3759 | HSOpts.DisableModuleHash = Record[Idx++]; |
| 3760 | HSOpts.UseBuiltinIncludes = Record[Idx++]; |
| 3761 | HSOpts.UseStandardSystemIncludes = Record[Idx++]; |
| 3762 | HSOpts.UseStandardCXXIncludes = Record[Idx++]; |
| 3763 | HSOpts.UseLibcxx = Record[Idx++]; |
| 3764 | |
| 3765 | return Listener.ReadHeaderSearchOptions(HSOpts, Complain); |
| 3766 | } |
| 3767 | |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3768 | bool ASTReader::ParsePreprocessorOptions(const RecordData &Record, |
| 3769 | bool Complain, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3770 | ASTReaderListener &Listener, |
| 3771 | std::string &SuggestedPredefines) { |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3772 | PreprocessorOptions PPOpts; |
| 3773 | unsigned Idx = 0; |
| 3774 | |
| 3775 | // Macro definitions/undefs |
| 3776 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3777 | std::string Macro = ReadString(Record, Idx); |
| 3778 | bool IsUndef = Record[Idx++]; |
| 3779 | PPOpts.Macros.push_back(std::make_pair(Macro, IsUndef)); |
| 3780 | } |
| 3781 | |
| 3782 | // Includes |
| 3783 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3784 | PPOpts.Includes.push_back(ReadString(Record, Idx)); |
| 3785 | } |
| 3786 | |
| 3787 | // Macro Includes |
| 3788 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3789 | PPOpts.MacroIncludes.push_back(ReadString(Record, Idx)); |
| 3790 | } |
| 3791 | |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3792 | PPOpts.UsePredefines = Record[Idx++]; |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3793 | PPOpts.ImplicitPCHInclude = ReadString(Record, Idx); |
| 3794 | PPOpts.ImplicitPTHInclude = ReadString(Record, Idx); |
| 3795 | PPOpts.ObjCXXARCStandardLibrary = |
| 3796 | static_cast<ObjCXXARCStandardLibraryKind>(Record[Idx++]); |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3797 | SuggestedPredefines.clear(); |
| 3798 | return Listener.ReadPreprocessorOptions(PPOpts, Complain, |
| 3799 | SuggestedPredefines); |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3800 | } |
| 3801 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3802 | std::pair<ModuleFile *, unsigned> |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3803 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3804 | GlobalPreprocessedEntityMapType::iterator |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3805 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3806 | assert(I != GlobalPreprocessedEntityMap.end() && |
| 3807 | "Corrupted global preprocessed entity map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3808 | ModuleFile *M = I->second; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3809 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 3810 | return std::make_pair(M, LocalIndex); |
| 3811 | } |
| 3812 | |
Argyrios Kyrtzidis | 632dcc9 | 2012-10-02 16:10:51 +0000 | [diff] [blame] | 3813 | std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator> |
| 3814 | ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const { |
| 3815 | if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord()) |
| 3816 | return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID, |
| 3817 | Mod.NumPreprocessedEntities); |
| 3818 | |
| 3819 | return std::make_pair(PreprocessingRecord::iterator(), |
| 3820 | PreprocessingRecord::iterator()); |
| 3821 | } |
| 3822 | |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 3823 | std::pair<ASTReader::ModuleDeclIterator, ASTReader::ModuleDeclIterator> |
| 3824 | ASTReader::getModuleFileLevelDecls(ModuleFile &Mod) { |
| 3825 | return std::make_pair(ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls), |
| 3826 | ModuleDeclIterator(this, &Mod, |
| 3827 | Mod.FileSortedDecls + Mod.NumFileSortedDecls)); |
| 3828 | } |
| 3829 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3830 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 3831 | PreprocessedEntityID PPID = Index+1; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3832 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 3833 | ModuleFile &M = *PPInfo.first; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3834 | unsigned LocalIndex = PPInfo.second; |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3835 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3836 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3837 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3838 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3839 | |
| 3840 | unsigned Code = M.PreprocessorDetailCursor.ReadCode(); |
| 3841 | switch (Code) { |
| 3842 | case llvm::bitc::END_BLOCK: |
| 3843 | return 0; |
| 3844 | |
| 3845 | case llvm::bitc::ENTER_SUBBLOCK: |
| 3846 | Error("unexpected subblock record in preprocessor detail block"); |
| 3847 | return 0; |
| 3848 | |
| 3849 | case llvm::bitc::DEFINE_ABBREV: |
| 3850 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 3851 | return 0; |
| 3852 | |
| 3853 | default: |
| 3854 | break; |
| 3855 | } |
| 3856 | |
| 3857 | if (!PP.getPreprocessingRecord()) { |
| 3858 | Error("no preprocessing record"); |
| 3859 | return 0; |
| 3860 | } |
| 3861 | |
| 3862 | // Read the record. |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3863 | SourceRange Range(ReadSourceLocation(M, PPOffs.Begin), |
| 3864 | ReadSourceLocation(M, PPOffs.End)); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3865 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 3866 | const char *BlobStart = 0; |
| 3867 | unsigned BlobLen = 0; |
| 3868 | RecordData Record; |
| 3869 | PreprocessorDetailRecordTypes RecType = |
| 3870 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.ReadRecord( |
| 3871 | Code, Record, BlobStart, BlobLen); |
| 3872 | switch (RecType) { |
| 3873 | case PPD_MACRO_EXPANSION: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3874 | bool isBuiltin = Record[0]; |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3875 | IdentifierInfo *Name = 0; |
| 3876 | MacroDefinition *Def = 0; |
| 3877 | if (isBuiltin) |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3878 | Name = getLocalIdentifier(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3879 | else { |
| 3880 | PreprocessedEntityID |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3881 | GlobalID = getGlobalPreprocessedEntityID(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3882 | Def =cast<MacroDefinition>(PPRec.getLoadedPreprocessedEntity(GlobalID-1)); |
| 3883 | } |
| 3884 | |
| 3885 | MacroExpansion *ME; |
| 3886 | if (isBuiltin) |
| 3887 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 3888 | else |
| 3889 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 3890 | |
| 3891 | return ME; |
| 3892 | } |
| 3893 | |
| 3894 | case PPD_MACRO_DEFINITION: { |
| 3895 | // Decode the identifier info and then check again; if the macro is |
| 3896 | // still defined and associated with the identifier, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3897 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3898 | MacroDefinition *MD |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3899 | = new (PPRec) MacroDefinition(II, Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3900 | |
| 3901 | if (DeserializationListener) |
| 3902 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 3903 | |
| 3904 | return MD; |
| 3905 | } |
| 3906 | |
| 3907 | case PPD_INCLUSION_DIRECTIVE: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3908 | const char *FullFileNameStart = BlobStart + Record[0]; |
Argyrios Kyrtzidis | 29f98b4 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 3909 | StringRef FullFileName(FullFileNameStart, BlobLen - Record[0]); |
| 3910 | const FileEntry *File = 0; |
| 3911 | if (!FullFileName.empty()) |
| 3912 | File = PP.getFileManager().getFile(FullFileName); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3913 | |
| 3914 | // FIXME: Stable encoding |
| 3915 | InclusionDirective::InclusionKind Kind |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3916 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3917 | InclusionDirective *ID |
| 3918 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3919 | StringRef(BlobStart, Record[0]), |
Argyrios Kyrtzidis | 8dd927c | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 3920 | Record[1], Record[3], |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3921 | File, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3922 | Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3923 | return ID; |
| 3924 | } |
| 3925 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 3926 | |
| 3927 | llvm_unreachable("Invalid PreprocessorDetailRecordTypes"); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3928 | } |
| 3929 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3930 | /// \brief \arg SLocMapI points at a chunk of a module that contains no |
| 3931 | /// preprocessed entities or the entities it contains are not the ones we are |
| 3932 | /// looking for. Find the next module that contains entities and return the ID |
| 3933 | /// of the first entry. |
| 3934 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 3935 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 3936 | ++SLocMapI; |
| 3937 | for (GlobalSLocOffsetMapType::const_iterator |
| 3938 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3939 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3940 | if (M.NumPreprocessedEntities) |
| 3941 | return getGlobalPreprocessedEntityID(M, M.BasePreprocessedEntityID); |
| 3942 | } |
| 3943 | |
| 3944 | return getTotalNumPreprocessedEntities(); |
| 3945 | } |
| 3946 | |
| 3947 | namespace { |
| 3948 | |
| 3949 | template <unsigned PPEntityOffset::*PPLoc> |
| 3950 | struct PPEntityComp { |
| 3951 | const ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3952 | ModuleFile &M; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3953 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3954 | PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) { } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3955 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 3956 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 3957 | SourceLocation LHS = getLoc(L); |
| 3958 | SourceLocation RHS = getLoc(R); |
| 3959 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3960 | } |
| 3961 | |
| 3962 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3963 | SourceLocation LHS = getLoc(L); |
| 3964 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3965 | } |
| 3966 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 3967 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3968 | SourceLocation RHS = getLoc(R); |
| 3969 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3970 | } |
| 3971 | |
| 3972 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
| 3973 | return Reader.ReadSourceLocation(M, PPE.*PPLoc); |
| 3974 | } |
| 3975 | }; |
| 3976 | |
| 3977 | } |
| 3978 | |
| 3979 | /// \brief Returns the first preprocessed entity ID that ends after \arg BLoc. |
| 3980 | PreprocessedEntityID |
| 3981 | ASTReader::findBeginPreprocessedEntity(SourceLocation BLoc) const { |
| 3982 | if (SourceMgr.isLocalSourceLocation(BLoc)) |
| 3983 | return getTotalNumPreprocessedEntities(); |
| 3984 | |
| 3985 | GlobalSLocOffsetMapType::const_iterator |
| 3986 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 3987 | BLoc.getOffset()); |
| 3988 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 3989 | "Corrupted global sloc offset map"); |
| 3990 | |
| 3991 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 3992 | return findNextPreprocessedEntity(SLocMapI); |
| 3993 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3994 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3995 | typedef const PPEntityOffset *pp_iterator; |
| 3996 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 3997 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
Argyrios Kyrtzidis | 4cd0634 | 2011-09-22 21:17:02 +0000 | [diff] [blame] | 3998 | |
| 3999 | size_t Count = M.NumPreprocessedEntities; |
| 4000 | size_t Half; |
| 4001 | pp_iterator First = pp_begin; |
| 4002 | pp_iterator PPI; |
| 4003 | |
| 4004 | // Do a binary search manually instead of using std::lower_bound because |
| 4005 | // The end locations of entities may be unordered (when a macro expansion |
| 4006 | // is inside another macro argument), but for this case it is not important |
| 4007 | // whether we get the first macro expansion or its containing macro. |
| 4008 | while (Count > 0) { |
| 4009 | Half = Count/2; |
| 4010 | PPI = First; |
| 4011 | std::advance(PPI, Half); |
| 4012 | if (SourceMgr.isBeforeInTranslationUnit(ReadSourceLocation(M, PPI->End), |
| 4013 | BLoc)){ |
| 4014 | First = PPI; |
| 4015 | ++First; |
| 4016 | Count = Count - Half - 1; |
| 4017 | } else |
| 4018 | Count = Half; |
| 4019 | } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 4020 | |
| 4021 | if (PPI == pp_end) |
| 4022 | return findNextPreprocessedEntity(SLocMapI); |
| 4023 | |
| 4024 | return getGlobalPreprocessedEntityID(M, |
| 4025 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 4026 | } |
| 4027 | |
| 4028 | /// \brief Returns the first preprocessed entity ID that begins after \arg ELoc. |
| 4029 | PreprocessedEntityID |
| 4030 | ASTReader::findEndPreprocessedEntity(SourceLocation ELoc) const { |
| 4031 | if (SourceMgr.isLocalSourceLocation(ELoc)) |
| 4032 | return getTotalNumPreprocessedEntities(); |
| 4033 | |
| 4034 | GlobalSLocOffsetMapType::const_iterator |
| 4035 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 4036 | ELoc.getOffset()); |
| 4037 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 4038 | "Corrupted global sloc offset map"); |
| 4039 | |
| 4040 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 4041 | return findNextPreprocessedEntity(SLocMapI); |
| 4042 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4043 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 4044 | typedef const PPEntityOffset *pp_iterator; |
| 4045 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 4046 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 4047 | pp_iterator PPI = |
| 4048 | std::upper_bound(pp_begin, pp_end, ELoc, |
| 4049 | PPEntityComp<&PPEntityOffset::Begin>(*this, M)); |
| 4050 | |
| 4051 | if (PPI == pp_end) |
| 4052 | return findNextPreprocessedEntity(SLocMapI); |
| 4053 | |
| 4054 | return getGlobalPreprocessedEntityID(M, |
| 4055 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 4056 | } |
| 4057 | |
| 4058 | /// \brief Returns a pair of [Begin, End) indices of preallocated |
| 4059 | /// preprocessed entities that \arg Range encompasses. |
| 4060 | std::pair<unsigned, unsigned> |
| 4061 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 4062 | if (Range.isInvalid()) |
| 4063 | return std::make_pair(0,0); |
| 4064 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 4065 | |
| 4066 | PreprocessedEntityID BeginID = findBeginPreprocessedEntity(Range.getBegin()); |
| 4067 | PreprocessedEntityID EndID = findEndPreprocessedEntity(Range.getEnd()); |
| 4068 | return std::make_pair(BeginID, EndID); |
| 4069 | } |
| 4070 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 4071 | /// \brief Optionally returns true or false if the preallocated preprocessed |
| 4072 | /// entity with index \arg Index came from file \arg FID. |
| 4073 | llvm::Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
| 4074 | FileID FID) { |
| 4075 | if (FID.isInvalid()) |
| 4076 | return false; |
| 4077 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4078 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 4079 | ModuleFile &M = *PPInfo.first; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 4080 | unsigned LocalIndex = PPInfo.second; |
| 4081 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 4082 | |
| 4083 | SourceLocation Loc = ReadSourceLocation(M, PPOffs.Begin); |
| 4084 | if (Loc.isInvalid()) |
| 4085 | return false; |
| 4086 | |
| 4087 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 4088 | return true; |
| 4089 | else |
| 4090 | return false; |
| 4091 | } |
| 4092 | |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 4093 | namespace { |
| 4094 | /// \brief Visitor used to search for information about a header file. |
| 4095 | class HeaderFileInfoVisitor { |
| 4096 | ASTReader &Reader; |
| 4097 | const FileEntry *FE; |
| 4098 | |
| 4099 | llvm::Optional<HeaderFileInfo> HFI; |
| 4100 | |
| 4101 | public: |
| 4102 | HeaderFileInfoVisitor(ASTReader &Reader, const FileEntry *FE) |
| 4103 | : Reader(Reader), FE(FE) { } |
| 4104 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4105 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 4106 | HeaderFileInfoVisitor *This |
| 4107 | = static_cast<HeaderFileInfoVisitor *>(UserData); |
| 4108 | |
| 4109 | HeaderFileInfoTrait Trait(This->Reader, M, |
| 4110 | &This->Reader.getPreprocessor().getHeaderSearchInfo(), |
| 4111 | M.HeaderFileFrameworkStrings, |
| 4112 | This->FE->getName()); |
| 4113 | |
| 4114 | HeaderFileInfoLookupTable *Table |
| 4115 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 4116 | if (!Table) |
| 4117 | return false; |
| 4118 | |
| 4119 | // Look in the on-disk hash table for an entry for this file name. |
| 4120 | HeaderFileInfoLookupTable::iterator Pos = Table->find(This->FE->getName(), |
| 4121 | &Trait); |
| 4122 | if (Pos == Table->end()) |
| 4123 | return false; |
| 4124 | |
| 4125 | This->HFI = *Pos; |
| 4126 | return true; |
| 4127 | } |
| 4128 | |
| 4129 | llvm::Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| 4130 | }; |
| 4131 | } |
| 4132 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4133 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 4134 | HeaderFileInfoVisitor Visitor(*this, FE); |
| 4135 | ModuleMgr.visit(&HeaderFileInfoVisitor::visit, &Visitor); |
| 4136 | if (llvm::Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4137 | if (Listener) |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 4138 | Listener->ReadHeaderFileInfo(*HFI, FE->getUID()); |
| 4139 | return *HFI; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | return HeaderFileInfo(); |
| 4143 | } |
| 4144 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 4145 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4146 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4147 | ModuleFile &F = *(*I); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4148 | unsigned Idx = 0; |
| 4149 | while (Idx < F.PragmaDiagMappings.size()) { |
| 4150 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 4151 | Diag.DiagStates.push_back(*Diag.GetCurDiagState()); |
| 4152 | Diag.DiagStatePoints.push_back( |
| 4153 | DiagnosticsEngine::DiagStatePoint(&Diag.DiagStates.back(), |
| 4154 | FullSourceLoc(Loc, SourceMgr))); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4155 | while (1) { |
| 4156 | assert(Idx < F.PragmaDiagMappings.size() && |
| 4157 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 4158 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 4159 | break; // Something is messed up but at least avoid infinite loop in |
| 4160 | // release build. |
| 4161 | } |
| 4162 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 4163 | if (DiagID == (unsigned)-1) { |
| 4164 | break; // no more diag/map pairs for this location. |
| 4165 | } |
| 4166 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 4167 | DiagnosticMappingInfo MappingInfo = Diag.makeMappingInfo(Map, Loc); |
| 4168 | Diag.GetCurDiagState()->setMappingInfo(DiagID, MappingInfo); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4169 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 4170 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 4171 | } |
| 4172 | } |
| 4173 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4174 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4175 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4176 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | e9b76c1 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 4177 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4178 | ModuleFile *M = I->second; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 4179 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4180 | } |
| 4181 | |
| 4182 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4183 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4184 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 4185 | /// routine actually reads the record corresponding to the type at the given |
| 4186 | /// location. It is a helper routine for GetType, which deals with reading type |
| 4187 | /// IDs. |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4188 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4189 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4190 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 4191 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 4192 | // Keep track of where we are in the stream, then jump back there |
| 4193 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4194 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 4195 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4196 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 4197 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4198 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4199 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4200 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4201 | unsigned Idx = 0; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4202 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4203 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4204 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4205 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 4206 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4207 | if (Record.size() != 2) { |
| 4208 | Error("Incorrect encoding of extended qualifier type"); |
| 4209 | return QualType(); |
| 4210 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4211 | QualType Base = readType(*Loc.F, Record, Idx); |
| 4212 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4213 | return Context.getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 4214 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4215 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4216 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4217 | if (Record.size() != 1) { |
| 4218 | Error("Incorrect encoding of complex type"); |
| 4219 | return QualType(); |
| 4220 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4221 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4222 | return Context.getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4225 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4226 | if (Record.size() != 1) { |
| 4227 | Error("Incorrect encoding of pointer type"); |
| 4228 | return QualType(); |
| 4229 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4230 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4231 | return Context.getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4232 | } |
| 4233 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4234 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4235 | if (Record.size() != 1) { |
| 4236 | Error("Incorrect encoding of block pointer type"); |
| 4237 | return QualType(); |
| 4238 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4239 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4240 | return Context.getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4241 | } |
| 4242 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4243 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 4244 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4245 | Error("Incorrect encoding of lvalue reference type"); |
| 4246 | return QualType(); |
| 4247 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4248 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4249 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4250 | } |
| 4251 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4252 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4253 | if (Record.size() != 1) { |
| 4254 | Error("Incorrect encoding of rvalue reference type"); |
| 4255 | return QualType(); |
| 4256 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4257 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4258 | return Context.getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4259 | } |
| 4260 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4261 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 4262 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4263 | Error("Incorrect encoding of member pointer type"); |
| 4264 | return QualType(); |
| 4265 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4266 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 4267 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 4268 | if (PointeeType.isNull() || ClassType.isNull()) |
| 4269 | return QualType(); |
| 4270 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4271 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4272 | } |
| 4273 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4274 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4275 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4276 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 4277 | unsigned IndexTypeQuals = Record[2]; |
| 4278 | unsigned Idx = 3; |
| 4279 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4280 | return Context.getConstantArrayType(ElementType, Size, |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 4281 | ASM, IndexTypeQuals); |
| 4282 | } |
| 4283 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4284 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4285 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4286 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 4287 | unsigned IndexTypeQuals = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4288 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4289 | } |
| 4290 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4291 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4292 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 4293 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 4294 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4295 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 4296 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4297 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 4298 | ASM, IndexTypeQuals, |
| 4299 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4300 | } |
| 4301 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4302 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 4303 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4304 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4305 | return QualType(); |
| 4306 | } |
| 4307 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4308 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4309 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4310 | unsigned VecKind = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4311 | return Context.getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4312 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4313 | } |
| 4314 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4315 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 4316 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4317 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4318 | return QualType(); |
| 4319 | } |
| 4320 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4321 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4322 | unsigned NumElements = Record[1]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4323 | return Context.getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4324 | } |
| 4325 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4326 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4327 | if (Record.size() != 6) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4328 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4329 | return QualType(); |
| 4330 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4331 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4332 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 4333 | (CallingConv)Record[4], Record[5]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4334 | return Context.getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4335 | } |
| 4336 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4337 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4338 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4339 | |
| 4340 | FunctionProtoType::ExtProtoInfo EPI; |
| 4341 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 4342 | /*hasregparm*/ Record[2], |
| 4343 | /*regparm*/ Record[3], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4344 | static_cast<CallingConv>(Record[4]), |
| 4345 | /*produces*/ Record[5]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4346 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4347 | unsigned Idx = 6; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4348 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4349 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4350 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4351 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4352 | |
| 4353 | EPI.Variadic = Record[Idx++]; |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 4354 | EPI.HasTrailingReturn = Record[Idx++]; |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4355 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 4356 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4357 | ExceptionSpecificationType EST = |
| 4358 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 4359 | EPI.ExceptionSpecType = EST; |
Douglas Gregor | b0d06e2 | 2012-04-04 00:34:49 +0000 | [diff] [blame] | 4360 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4361 | if (EST == EST_Dynamic) { |
| 4362 | EPI.NumExceptions = Record[Idx++]; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4363 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4364 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4365 | EPI.Exceptions = Exceptions.data(); |
| 4366 | } else if (EST == EST_ComputedNoexcept) { |
| 4367 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
Richard Smith | 7bb698a | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 4368 | } else if (EST == EST_Uninstantiated) { |
| 4369 | EPI.ExceptionSpecDecl = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
| 4370 | EPI.ExceptionSpecTemplate = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
Richard Smith | b9d0b76 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 4371 | } else if (EST == EST_Unevaluated) { |
| 4372 | EPI.ExceptionSpecDecl = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4373 | } |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4374 | return Context.getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4375 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4376 | } |
| 4377 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4378 | case TYPE_UNRESOLVED_USING: { |
| 4379 | unsigned Idx = 0; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4380 | return Context.getTypeDeclType( |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4381 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 4382 | } |
| 4383 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4384 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 4385 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4386 | Error("incorrect encoding of typedef type"); |
| 4387 | return QualType(); |
| 4388 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4389 | unsigned Idx = 0; |
| 4390 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4391 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 4392 | if (!Canonical.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4393 | Canonical = Context.getCanonicalType(Canonical); |
| 4394 | return Context.getTypedefType(Decl, Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 4395 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4396 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4397 | case TYPE_TYPEOF_EXPR: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4398 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4399 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4400 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4401 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4402 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4403 | return QualType(); |
| 4404 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4405 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4406 | return Context.getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4407 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4408 | |
Douglas Gregor | f8af982 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 4409 | case TYPE_DECLTYPE: { |
| 4410 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 4411 | return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType); |
| 4412 | } |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 4413 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4414 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4415 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 4416 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4417 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4418 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4419 | } |
| 4420 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4421 | case TYPE_AUTO: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4422 | return Context.getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4423 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4424 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4425 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4426 | Error("incorrect encoding of record type"); |
| 4427 | return QualType(); |
| 4428 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4429 | unsigned Idx = 0; |
| 4430 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 4431 | RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx); |
| 4432 | RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl()); |
| 4433 | QualType T = Context.getRecordType(RD); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4434 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4435 | return T; |
| 4436 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4437 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4438 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4439 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4440 | Error("incorrect encoding of enum type"); |
| 4441 | return QualType(); |
| 4442 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4443 | unsigned Idx = 0; |
| 4444 | bool IsDependent = Record[Idx++]; |
| 4445 | QualType T |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4446 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4447 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4448 | return T; |
| 4449 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4450 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4451 | case TYPE_ATTRIBUTED: { |
| 4452 | if (Record.size() != 3) { |
| 4453 | Error("incorrect encoding of attributed type"); |
| 4454 | return QualType(); |
| 4455 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4456 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 4457 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4458 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4459 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4460 | } |
| 4461 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4462 | case TYPE_PAREN: { |
| 4463 | if (Record.size() != 1) { |
| 4464 | Error("incorrect encoding of paren type"); |
| 4465 | return QualType(); |
| 4466 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4467 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4468 | return Context.getParenType(InnerType); |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4469 | } |
| 4470 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4471 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 4472 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4473 | Error("incorrect encoding of pack expansion type"); |
| 4474 | return QualType(); |
| 4475 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4476 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4477 | if (Pattern.isNull()) |
| 4478 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4479 | llvm::Optional<unsigned> NumExpansions; |
| 4480 | if (Record[1]) |
| 4481 | NumExpansions = Record[1] - 1; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4482 | return Context.getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4483 | } |
| 4484 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4485 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4486 | unsigned Idx = 0; |
| 4487 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4488 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4489 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4490 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4491 | } |
| 4492 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4493 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4494 | unsigned Idx = 0; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4495 | ObjCInterfaceDecl *ItfD |
| 4496 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 4497 | return Context.getObjCInterfaceType(ItfD->getCanonicalDecl()); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4498 | } |
| 4499 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4500 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4501 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4502 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4503 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4504 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4505 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4506 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4507 | return Context.getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4508 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4509 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4510 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 4511 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4512 | QualType Pointee = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4513 | return Context.getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 4514 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4515 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4516 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4517 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4518 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 4519 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4520 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4521 | Context.getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4522 | Replacement); |
| 4523 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4524 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4525 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 4526 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4527 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4528 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4529 | return Context.getSubstTemplateTypeParmPackType( |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4530 | cast<TemplateTypeParmType>(Parm), |
| 4531 | ArgPack); |
| 4532 | } |
| 4533 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4534 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4535 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4536 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 4537 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4538 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 4539 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4540 | QualType(new (Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4541 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4542 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4543 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4544 | unsigned Idx = 0; |
| 4545 | unsigned Depth = Record[Idx++]; |
| 4546 | unsigned Index = Record[Idx++]; |
| 4547 | bool Pack = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4548 | TemplateTypeParmDecl *D |
| 4549 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4550 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4551 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4552 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4553 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 4554 | unsigned Idx = 0; |
| 4555 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4556 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4557 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4558 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 4559 | if (!Canon.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4560 | Canon = Context.getCanonicalType(Canon); |
| 4561 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 4562 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4563 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4564 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4565 | unsigned Idx = 0; |
| 4566 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4567 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4568 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4569 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4570 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4571 | Args.reserve(NumArgs); |
| 4572 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4573 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4574 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4575 | Args.size(), Args.data()); |
| 4576 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4577 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4578 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4579 | unsigned Idx = 0; |
| 4580 | |
| 4581 | // ArrayType |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4582 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4583 | ArrayType::ArraySizeModifier ASM |
| 4584 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 4585 | unsigned IndexTypeQuals = Record[Idx++]; |
| 4586 | |
| 4587 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4588 | Expr *NumElts = ReadExpr(*Loc.F); |
| 4589 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4590 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4591 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4592 | IndexTypeQuals, Brackets); |
| 4593 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4594 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4595 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4596 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4597 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4598 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4599 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4600 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4601 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4602 | QualType T; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4603 | if (Underlying.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4604 | T = Context.getCanonicalTemplateSpecializationType(Name, Args.data(), |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4605 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 4606 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4607 | T = Context.getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4608 | Args.size(), Underlying); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4609 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4610 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4611 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4612 | |
| 4613 | case TYPE_ATOMIC: { |
| 4614 | if (Record.size() != 1) { |
| 4615 | Error("Incorrect encoding of atomic type"); |
| 4616 | return QualType(); |
| 4617 | } |
| 4618 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 4619 | return Context.getAtomicType(ValueType); |
| 4620 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4621 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 4622 | llvm_unreachable("Invalid TypeCode!"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4623 | } |
| 4624 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4625 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4626 | ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4627 | ModuleFile &F; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4628 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4629 | unsigned &Idx; |
| 4630 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4631 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 4632 | unsigned &I) { |
| 4633 | return Reader.ReadSourceLocation(F, R, I); |
| 4634 | } |
| 4635 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4636 | template<typename T> |
| 4637 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 4638 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 4639 | } |
| 4640 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4641 | public: |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4642 | TypeLocReader(ASTReader &Reader, ModuleFile &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4643 | const ASTReader::RecordData &Record, unsigned &Idx) |
Benjamin Kramer | facde17 | 2012-06-06 17:32:50 +0000 | [diff] [blame] | 4644 | : Reader(Reader), F(F), Record(Record), Idx(Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4645 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4646 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4647 | // We want compile-time assurance that we've enumerated all of |
| 4648 | // these, so unfortunately we have to declare them first, then |
| 4649 | // define them out-of-line. |
| 4650 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4651 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4652 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4653 | #include "clang/AST/TypeLocNodes.def" |
| 4654 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4655 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 4656 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4657 | }; |
| 4658 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4659 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4660 | // nothing to do |
| 4661 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4662 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4663 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 4664 | if (TL.needsExtraLocalData()) { |
| 4665 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 4666 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 4667 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 4668 | TL.setModeAttr(Record[Idx++]); |
| 4669 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4670 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4671 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4672 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4673 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4674 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4675 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4676 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4677 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4678 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4679 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4680 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4681 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4682 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4683 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4684 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4685 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4686 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4687 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4688 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4689 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4690 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4691 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 4692 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4693 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4694 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4695 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4696 | TL.setSizeExpr(0); |
| 4697 | } |
| 4698 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 4699 | VisitArrayTypeLoc(TL); |
| 4700 | } |
| 4701 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 4702 | VisitArrayTypeLoc(TL); |
| 4703 | } |
| 4704 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 4705 | VisitArrayTypeLoc(TL); |
| 4706 | } |
| 4707 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 4708 | DependentSizedArrayTypeLoc TL) { |
| 4709 | VisitArrayTypeLoc(TL); |
| 4710 | } |
| 4711 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 4712 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4713 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4714 | } |
| 4715 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4716 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4717 | } |
| 4718 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4719 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4720 | } |
| 4721 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4722 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4723 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4724 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4725 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4726 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4727 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4728 | } |
| 4729 | } |
| 4730 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 4731 | VisitFunctionTypeLoc(TL); |
| 4732 | } |
| 4733 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 4734 | VisitFunctionTypeLoc(TL); |
| 4735 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4736 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4737 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4738 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4739 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4740 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4741 | } |
| 4742 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4743 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 4744 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4745 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4746 | } |
| 4747 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4748 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 4749 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4750 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4751 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4752 | } |
| 4753 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4754 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4755 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4756 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 4757 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 4758 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4759 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4760 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 4761 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4762 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 4763 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 4764 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4765 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4766 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4767 | } |
| 4768 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4769 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4770 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4771 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 4772 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 4773 | if (TL.hasAttrOperand()) { |
| 4774 | SourceRange range; |
| 4775 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 4776 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 4777 | TL.setAttrOperandParensRange(range); |
| 4778 | } |
| 4779 | if (TL.hasAttrExprOperand()) { |
| 4780 | if (Record[Idx++]) |
| 4781 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 4782 | else |
| 4783 | TL.setAttrExprOperand(0); |
| 4784 | } else if (TL.hasAttrEnumOperand()) |
| 4785 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 4786 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4787 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4788 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4789 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4790 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 4791 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4792 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4793 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4794 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 4795 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4796 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 4797 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4798 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 4799 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4800 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4801 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 4802 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4803 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4804 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 4805 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4806 | Reader.GetTemplateArgumentLocInfo(F, |
| 4807 | TL.getTypePtr()->getArg(i).getKind(), |
| 4808 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4809 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4810 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 4811 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4812 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4813 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4814 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4815 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4816 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4817 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4818 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4819 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4820 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4821 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4822 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4823 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4824 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4825 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4826 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 4827 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4828 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4829 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4830 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4831 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4832 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4833 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4834 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 4835 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4836 | Reader.GetTemplateArgumentLocInfo(F, |
| 4837 | TL.getTypePtr()->getArg(I).getKind(), |
| 4838 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4839 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4840 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 4841 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 4842 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4843 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4844 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4845 | } |
| 4846 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 4847 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4848 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4849 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4850 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4851 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4852 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 4853 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4854 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 4855 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4856 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 4857 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 4858 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4859 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4860 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4861 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4862 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4863 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4864 | unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4865 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4866 | if (InfoTy.isNull()) |
| 4867 | return 0; |
| 4868 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4869 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4870 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4871 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4872 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4873 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4874 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4875 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4876 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4877 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 4878 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4879 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4880 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4881 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4882 | switch ((PredefinedTypeIDs)Index) { |
| 4883 | case PREDEF_TYPE_NULL_ID: return QualType(); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4884 | case PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; |
| 4885 | case PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4886 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4887 | case PREDEF_TYPE_CHAR_U_ID: |
| 4888 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4889 | // FIXME: Check that the signedness of CharTy is correct! |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4890 | T = Context.CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4891 | break; |
| 4892 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4893 | case PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; |
| 4894 | case PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; |
| 4895 | case PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; |
| 4896 | case PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; |
| 4897 | case PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; |
| 4898 | case PREDEF_TYPE_UINT128_ID: T = Context.UnsignedInt128Ty; break; |
| 4899 | case PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; |
| 4900 | case PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; |
| 4901 | case PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; |
| 4902 | case PREDEF_TYPE_INT_ID: T = Context.IntTy; break; |
| 4903 | case PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; |
| 4904 | case PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; |
| 4905 | case PREDEF_TYPE_INT128_ID: T = Context.Int128Ty; break; |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 4906 | case PREDEF_TYPE_HALF_ID: T = Context.HalfTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4907 | case PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; |
| 4908 | case PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; |
| 4909 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; |
| 4910 | case PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; |
| 4911 | case PREDEF_TYPE_BOUND_MEMBER: T = Context.BoundMemberTy; break; |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 4912 | case PREDEF_TYPE_PSEUDO_OBJECT: T = Context.PseudoObjectTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4913 | case PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; |
| 4914 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context.UnknownAnyTy; break; |
| 4915 | case PREDEF_TYPE_NULLPTR_ID: T = Context.NullPtrTy; break; |
| 4916 | case PREDEF_TYPE_CHAR16_ID: T = Context.Char16Ty; break; |
| 4917 | case PREDEF_TYPE_CHAR32_ID: T = Context.Char32Ty; break; |
| 4918 | case PREDEF_TYPE_OBJC_ID: T = Context.ObjCBuiltinIdTy; break; |
| 4919 | case PREDEF_TYPE_OBJC_CLASS: T = Context.ObjCBuiltinClassTy; break; |
| 4920 | case PREDEF_TYPE_OBJC_SEL: T = Context.ObjCBuiltinSelTy; break; |
| 4921 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4922 | |
| 4923 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4924 | T = Context.getAutoRRefDeductType(); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4925 | break; |
John McCall | 0ddaeb9 | 2011-10-17 18:09:15 +0000 | [diff] [blame] | 4926 | |
| 4927 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 4928 | T = Context.ARCUnbridgedCastTy; |
| 4929 | break; |
| 4930 | |
Meador Inge | fb40e3f | 2012-07-01 15:57:25 +0000 | [diff] [blame] | 4931 | case PREDEF_TYPE_VA_LIST_TAG: |
| 4932 | T = Context.getVaListTagType(); |
| 4933 | break; |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 4934 | |
| 4935 | case PREDEF_TYPE_BUILTIN_FN: |
| 4936 | T = Context.BuiltinFnTy; |
| 4937 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4938 | } |
| 4939 | |
| 4940 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4941 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4944 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4945 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4946 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4947 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4948 | if (TypesLoaded[Index].isNull()) |
| 4949 | return QualType(); |
| 4950 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4951 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4952 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4953 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 4954 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4955 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4956 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4957 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4958 | } |
| 4959 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4960 | QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4961 | return GetType(getGlobalTypeID(F, LocalID)); |
| 4962 | } |
| 4963 | |
| 4964 | serialization::TypeID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4965 | ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4966 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 4967 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 4968 | |
| 4969 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 4970 | return LocalID; |
| 4971 | |
| 4972 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4973 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 4974 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 4975 | |
| 4976 | unsigned GlobalIndex = LocalIndex + I->second; |
| 4977 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 4978 | } |
| 4979 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4980 | TemplateArgumentLocInfo |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4981 | ASTReader::GetTemplateArgumentLocInfo(ModuleFile &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4982 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4983 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4984 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4985 | switch (Kind) { |
| 4986 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4987 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4988 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4989 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4990 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4991 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4992 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4993 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4994 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4995 | SourceLocation()); |
| 4996 | } |
| 4997 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4998 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4999 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5000 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 5001 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 5002 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 5003 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5004 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5005 | case TemplateArgument::Null: |
| 5006 | case TemplateArgument::Integral: |
| 5007 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5008 | case TemplateArgument::NullPtr: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5009 | case TemplateArgument::Pack: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5010 | // FIXME: Is this right? |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5011 | return TemplateArgumentLocInfo(); |
| 5012 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 5013 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5014 | } |
| 5015 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5016 | TemplateArgumentLoc |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5017 | ASTReader::ReadTemplateArgumentLoc(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 5018 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5019 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5020 | |
| 5021 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 5022 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 5023 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 5024 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5025 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 5026 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5027 | } |
| 5028 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5029 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5030 | return GetDecl(ID); |
| 5031 | } |
| 5032 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5033 | uint64_t ASTReader::readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 5034 | unsigned &Idx){ |
| 5035 | if (Idx >= Record.size()) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5036 | return 0; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5037 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 5038 | unsigned LocalID = Record[Idx++]; |
| 5039 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5040 | } |
| 5041 | |
| 5042 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5043 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 5044 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5045 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5046 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5047 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 5048 | RecordData Record; |
| 5049 | unsigned Code = Cursor.ReadCode(); |
| 5050 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 5051 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 5052 | Error("Malformed AST file: missing C++ base specifiers"); |
| 5053 | return 0; |
| 5054 | } |
| 5055 | |
| 5056 | unsigned Idx = 0; |
| 5057 | unsigned NumBases = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5058 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5059 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 5060 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5061 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5062 | return Bases; |
| 5063 | } |
| 5064 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5065 | serialization::DeclID |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 5066 | ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5067 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5068 | return LocalID; |
| 5069 | |
| 5070 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5071 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5072 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 5073 | |
| 5074 | return LocalID + I->second; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5075 | } |
| 5076 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5077 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5078 | ModuleFile &M) const { |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5079 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(ID); |
| 5080 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 5081 | return &M == I->second; |
| 5082 | } |
| 5083 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 5084 | ModuleFile *ASTReader::getOwningModuleFile(Decl *D) { |
| 5085 | if (!D->isFromASTFile()) |
| 5086 | return 0; |
| 5087 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID()); |
| 5088 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 5089 | return I->second; |
| 5090 | } |
| 5091 | |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5092 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 5093 | if (ID < NUM_PREDEF_DECL_IDS) |
| 5094 | return SourceLocation(); |
| 5095 | |
| 5096 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 5097 | |
| 5098 | if (Index > DeclsLoaded.size()) { |
| 5099 | Error("declaration ID out-of-range for AST file"); |
| 5100 | return SourceLocation(); |
| 5101 | } |
| 5102 | |
| 5103 | if (Decl *D = DeclsLoaded[Index]) |
| 5104 | return D->getLocation(); |
| 5105 | |
| 5106 | unsigned RawLocation = 0; |
| 5107 | RecordLocation Rec = DeclCursorForID(ID, RawLocation); |
| 5108 | return ReadSourceLocation(*Rec.F, RawLocation); |
| 5109 | } |
| 5110 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5111 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5112 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 5113 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5114 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5115 | return 0; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5116 | |
| 5117 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5118 | return Context.getTranslationUnitDecl(); |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 5119 | |
| 5120 | case PREDEF_DECL_OBJC_ID_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5121 | return Context.getObjCIdDecl(); |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 5122 | |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 5123 | case PREDEF_DECL_OBJC_SEL_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5124 | return Context.getObjCSelDecl(); |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 5125 | |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 5126 | case PREDEF_DECL_OBJC_CLASS_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5127 | return Context.getObjCClassDecl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 5128 | |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 5129 | case PREDEF_DECL_OBJC_PROTOCOL_ID: |
| 5130 | return Context.getObjCProtocolDecl(); |
| 5131 | |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 5132 | case PREDEF_DECL_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5133 | return Context.getInt128Decl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 5134 | |
| 5135 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5136 | return Context.getUInt128Decl(); |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 5137 | |
| 5138 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5139 | return Context.getObjCInstanceTypeDecl(); |
Meador Inge | c5613b2 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 5140 | |
| 5141 | case PREDEF_DECL_BUILTIN_VA_LIST_ID: |
| 5142 | return Context.getBuiltinVaListDecl(); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5143 | } |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5144 | } |
| 5145 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5146 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 5147 | |
Richard Smith | 2fbf373 | 2011-12-20 04:39:57 +0000 | [diff] [blame] | 5148 | if (Index >= DeclsLoaded.size()) { |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5149 | assert(0 && "declaration ID out-of-range for AST file"); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5150 | Error("declaration ID out-of-range for AST file"); |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5151 | return 0; |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5152 | } |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5153 | |
Douglas Gregor | fd002a7 | 2011-12-16 22:37:11 +0000 | [diff] [blame] | 5154 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5155 | ReadDeclRecord(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5156 | if (DeserializationListener) |
| 5157 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 5158 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5159 | |
| 5160 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5161 | } |
| 5162 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 5163 | DeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
| 5164 | DeclID GlobalID) { |
| 5165 | if (GlobalID < NUM_PREDEF_DECL_IDS) |
| 5166 | return GlobalID; |
| 5167 | |
| 5168 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID); |
| 5169 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 5170 | ModuleFile *Owner = I->second; |
| 5171 | |
| 5172 | llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos |
| 5173 | = M.GlobalToLocalDeclIDs.find(Owner); |
| 5174 | if (Pos == M.GlobalToLocalDeclIDs.end()) |
| 5175 | return 0; |
| 5176 | |
| 5177 | return GlobalID - Owner->BaseDeclID + Pos->second; |
| 5178 | } |
| 5179 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5180 | serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5181 | const RecordData &Record, |
| 5182 | unsigned &Idx) { |
| 5183 | if (Idx >= Record.size()) { |
| 5184 | Error("Corrupted AST file"); |
| 5185 | return 0; |
| 5186 | } |
| 5187 | |
| 5188 | return getGlobalDeclID(F, Record[Idx++]); |
| 5189 | } |
| 5190 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 5191 | /// \brief Resolve the offset of a statement into a statement. |
| 5192 | /// |
| 5193 | /// This operation will read a new statement from the external |
| 5194 | /// source each time it is called, and is meant to be used via a |
| 5195 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5196 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 5197 | // Switch case IDs are per Decl. |
| 5198 | ClearSwitchCaseIDs(); |
| 5199 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 5200 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5201 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 5202 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 5203 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 5204 | } |
| 5205 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5206 | namespace { |
| 5207 | class FindExternalLexicalDeclsVisitor { |
| 5208 | ASTReader &Reader; |
| 5209 | const DeclContext *DC; |
| 5210 | bool (*isKindWeWant)(Decl::Kind); |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 5211 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5212 | SmallVectorImpl<Decl*> &Decls; |
| 5213 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 5214 | |
| 5215 | public: |
| 5216 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 5217 | bool (*isKindWeWant)(Decl::Kind), |
| 5218 | SmallVectorImpl<Decl*> &Decls) |
| 5219 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 5220 | { |
| 5221 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 5222 | PredefsVisited[I] = false; |
| 5223 | } |
| 5224 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5225 | static bool visit(ModuleFile &M, bool Preorder, void *UserData) { |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5226 | if (Preorder) |
| 5227 | return false; |
| 5228 | |
| 5229 | FindExternalLexicalDeclsVisitor *This |
| 5230 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 5231 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5232 | ModuleFile::DeclContextInfosMap::iterator Info |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5233 | = M.DeclContextInfos.find(This->DC); |
| 5234 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 5235 | return false; |
| 5236 | |
| 5237 | // Load all of the declaration IDs |
| 5238 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 5239 | *IDE = ID + Info->second.NumLexicalDecls; |
| 5240 | ID != IDE; ++ID) { |
| 5241 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 5242 | continue; |
| 5243 | |
| 5244 | // Don't add predefined declarations to the lexical context more |
| 5245 | // than once. |
| 5246 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 5247 | if (This->PredefsVisited[ID->second]) |
| 5248 | continue; |
| 5249 | |
| 5250 | This->PredefsVisited[ID->second] = true; |
| 5251 | } |
| 5252 | |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 5253 | if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) { |
| 5254 | if (!This->DC->isDeclInLexicalTraversal(D)) |
| 5255 | This->Decls.push_back(D); |
| 5256 | } |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5257 | } |
| 5258 | |
| 5259 | return false; |
| 5260 | } |
| 5261 | }; |
| 5262 | } |
| 5263 | |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 5264 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 5265 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5266 | SmallVectorImpl<Decl*> &Decls) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5267 | // There might be lexical decls in multiple modules, for the TU at |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5268 | // least. Walk all of the modules in the order they were loaded. |
| 5269 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 5270 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 5271 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 5272 | return ELR_Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5273 | } |
| 5274 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5275 | namespace { |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5276 | |
| 5277 | class DeclIDComp { |
| 5278 | ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5279 | ModuleFile &Mod; |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5280 | |
| 5281 | public: |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5282 | DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {} |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5283 | |
| 5284 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 5285 | SourceLocation LHS = getLocation(L); |
| 5286 | SourceLocation RHS = getLocation(R); |
| 5287 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5288 | } |
| 5289 | |
| 5290 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 5291 | SourceLocation RHS = getLocation(R); |
| 5292 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5293 | } |
| 5294 | |
| 5295 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 5296 | SourceLocation LHS = getLocation(L); |
| 5297 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5298 | } |
| 5299 | |
| 5300 | SourceLocation getLocation(LocalDeclID ID) const { |
| 5301 | return Reader.getSourceManager().getFileLoc( |
| 5302 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 5303 | } |
| 5304 | }; |
| 5305 | |
| 5306 | } |
| 5307 | |
| 5308 | void ASTReader::FindFileRegionDecls(FileID File, |
| 5309 | unsigned Offset, unsigned Length, |
| 5310 | SmallVectorImpl<Decl *> &Decls) { |
| 5311 | SourceManager &SM = getSourceManager(); |
| 5312 | |
| 5313 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 5314 | if (I == FileDeclIDs.end()) |
| 5315 | return; |
| 5316 | |
| 5317 | FileDeclsInfo &DInfo = I->second; |
| 5318 | if (DInfo.Decls.empty()) |
| 5319 | return; |
| 5320 | |
| 5321 | SourceLocation |
| 5322 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 5323 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 5324 | |
| 5325 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 5326 | ArrayRef<serialization::LocalDeclID>::iterator |
| 5327 | BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 5328 | BeginLoc, DIDComp); |
| 5329 | if (BeginIt != DInfo.Decls.begin()) |
| 5330 | --BeginIt; |
| 5331 | |
Argyrios Kyrtzidis | c14a03d | 2011-11-23 20:27:36 +0000 | [diff] [blame] | 5332 | // If we are pointing at a top-level decl inside an objc container, we need |
| 5333 | // to backtrack until we find it otherwise we will fail to report that the |
| 5334 | // region overlaps with an objc container. |
| 5335 | while (BeginIt != DInfo.Decls.begin() && |
| 5336 | GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt)) |
| 5337 | ->isTopLevelDeclInObjCContainer()) |
| 5338 | --BeginIt; |
| 5339 | |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5340 | ArrayRef<serialization::LocalDeclID>::iterator |
| 5341 | EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 5342 | EndLoc, DIDComp); |
| 5343 | if (EndIt != DInfo.Decls.end()) |
| 5344 | ++EndIt; |
| 5345 | |
| 5346 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 5347 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 5348 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 5349 | } |
| 5350 | |
| 5351 | namespace { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5352 | /// \brief ModuleFile visitor used to perform name lookup into a |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5353 | /// declaration context. |
| 5354 | class DeclContextNameLookupVisitor { |
| 5355 | ASTReader &Reader; |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5356 | llvm::SmallVectorImpl<const DeclContext *> &Contexts; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5357 | DeclarationName Name; |
| 5358 | SmallVectorImpl<NamedDecl *> &Decls; |
| 5359 | |
| 5360 | public: |
| 5361 | DeclContextNameLookupVisitor(ASTReader &Reader, |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5362 | SmallVectorImpl<const DeclContext *> &Contexts, |
| 5363 | DeclarationName Name, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5364 | SmallVectorImpl<NamedDecl *> &Decls) |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5365 | : Reader(Reader), Contexts(Contexts), Name(Name), Decls(Decls) { } |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5366 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5367 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5368 | DeclContextNameLookupVisitor *This |
| 5369 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 5370 | |
| 5371 | // Check whether we have any visible declaration information for |
| 5372 | // this context in this module. |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5373 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 5374 | bool FoundInfo = false; |
| 5375 | for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) { |
| 5376 | Info = M.DeclContextInfos.find(This->Contexts[I]); |
| 5377 | if (Info != M.DeclContextInfos.end() && |
| 5378 | Info->second.NameLookupTableData) { |
| 5379 | FoundInfo = true; |
| 5380 | break; |
| 5381 | } |
| 5382 | } |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5383 | |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5384 | if (!FoundInfo) |
| 5385 | return false; |
| 5386 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5387 | // Look for this name within this module. |
| 5388 | ASTDeclContextNameLookupTable *LookupTable = |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 5389 | Info->second.NameLookupTableData; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5390 | ASTDeclContextNameLookupTable::iterator Pos |
| 5391 | = LookupTable->find(This->Name); |
| 5392 | if (Pos == LookupTable->end()) |
| 5393 | return false; |
| 5394 | |
| 5395 | bool FoundAnything = false; |
| 5396 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 5397 | for (; Data.first != Data.second; ++Data.first) { |
| 5398 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 5399 | if (!ND) |
| 5400 | continue; |
| 5401 | |
| 5402 | if (ND->getDeclName() != This->Name) { |
Axel Naumann | 3dd82f7 | 2012-10-01 09:51:27 +0000 | [diff] [blame] | 5403 | // A name might be null because the decl's redeclarable part is |
| 5404 | // currently read before reading its name. The lookup is triggered by |
| 5405 | // building that decl (likely indirectly), and so it is later in the |
| 5406 | // sense of "already existing" and can be ignored here. |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5407 | continue; |
| 5408 | } |
| 5409 | |
| 5410 | // Record this declaration. |
| 5411 | FoundAnything = true; |
| 5412 | This->Decls.push_back(ND); |
| 5413 | } |
| 5414 | |
| 5415 | return FoundAnything; |
| 5416 | } |
| 5417 | }; |
| 5418 | } |
| 5419 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5420 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5421 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5422 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5423 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5424 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 5425 | if (!Name) |
| 5426 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 5427 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 5428 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5429 | SmallVector<NamedDecl *, 64> Decls; |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5430 | |
| 5431 | // Compute the declaration contexts we need to look into. Multiple such |
| 5432 | // declaration contexts occur when two declaration contexts from disjoint |
| 5433 | // modules get merged, e.g., when two namespaces with the same name are |
| 5434 | // independently defined in separate modules. |
| 5435 | SmallVector<const DeclContext *, 2> Contexts; |
| 5436 | Contexts.push_back(DC); |
| 5437 | |
| 5438 | if (DC->isNamespace()) { |
| 5439 | MergedDeclsMap::iterator Merged |
| 5440 | = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
| 5441 | if (Merged != MergedDecls.end()) { |
| 5442 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 5443 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 5444 | } |
| 5445 | } |
| 5446 | |
| 5447 | DeclContextNameLookupVisitor Visitor(*this, Contexts, Name, Decls); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5448 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 5449 | ++NumVisibleDeclContextsRead; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 5450 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5451 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5452 | } |
| 5453 | |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5454 | namespace { |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5455 | /// \brief ModuleFile visitor used to retrieve all visible names in a |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5456 | /// declaration context. |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5457 | class DeclContextAllNamesVisitor { |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5458 | ASTReader &Reader; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5459 | llvm::SmallVectorImpl<const DeclContext *> &Contexts; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5460 | llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8> > &Decls; |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5461 | |
| 5462 | public: |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5463 | DeclContextAllNamesVisitor(ASTReader &Reader, |
| 5464 | SmallVectorImpl<const DeclContext *> &Contexts, |
| 5465 | llvm::DenseMap<DeclarationName, |
| 5466 | SmallVector<NamedDecl *, 8> > &Decls) |
| 5467 | : Reader(Reader), Contexts(Contexts), Decls(Decls) { } |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5468 | |
| 5469 | static bool visit(ModuleFile &M, void *UserData) { |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5470 | DeclContextAllNamesVisitor *This |
| 5471 | = static_cast<DeclContextAllNamesVisitor *>(UserData); |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5472 | |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5473 | // Check whether we have any visible declaration information for |
| 5474 | // this context in this module. |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5475 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 5476 | bool FoundInfo = false; |
| 5477 | for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) { |
| 5478 | Info = M.DeclContextInfos.find(This->Contexts[I]); |
| 5479 | if (Info != M.DeclContextInfos.end() && |
| 5480 | Info->second.NameLookupTableData) { |
| 5481 | FoundInfo = true; |
| 5482 | break; |
| 5483 | } |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5484 | } |
| 5485 | |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5486 | if (!FoundInfo) |
| 5487 | return false; |
| 5488 | |
| 5489 | ASTDeclContextNameLookupTable *LookupTable = |
| 5490 | Info->second.NameLookupTableData; |
| 5491 | bool FoundAnything = false; |
| 5492 | for (ASTDeclContextNameLookupTable::data_iterator |
| 5493 | I = LookupTable->data_begin(), E = LookupTable->data_end(); |
| 5494 | I != E; ++I) { |
| 5495 | ASTDeclContextNameLookupTrait::data_type Data = *I; |
| 5496 | for (; Data.first != Data.second; ++Data.first) { |
| 5497 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, |
| 5498 | *Data.first); |
| 5499 | if (!ND) |
| 5500 | continue; |
| 5501 | |
| 5502 | // Record this declaration. |
| 5503 | FoundAnything = true; |
| 5504 | This->Decls[ND->getDeclName()].push_back(ND); |
| 5505 | } |
| 5506 | } |
| 5507 | |
| 5508 | return FoundAnything; |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5509 | } |
| 5510 | }; |
| 5511 | } |
| 5512 | |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5513 | void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5514 | if (!DC->hasExternalVisibleStorage()) |
| 5515 | return; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5516 | llvm::DenseMap<DeclarationName, llvm::SmallVector<NamedDecl*, 8> > Decls; |
| 5517 | |
| 5518 | // Compute the declaration contexts we need to look into. Multiple such |
| 5519 | // declaration contexts occur when two declaration contexts from disjoint |
| 5520 | // modules get merged, e.g., when two namespaces with the same name are |
| 5521 | // independently defined in separate modules. |
| 5522 | SmallVector<const DeclContext *, 2> Contexts; |
| 5523 | Contexts.push_back(DC); |
| 5524 | |
| 5525 | if (DC->isNamespace()) { |
| 5526 | MergedDeclsMap::iterator Merged |
| 5527 | = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
| 5528 | if (Merged != MergedDecls.end()) { |
| 5529 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 5530 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 5531 | } |
| 5532 | } |
| 5533 | |
| 5534 | DeclContextAllNamesVisitor Visitor(*this, Contexts, Decls); |
| 5535 | ModuleMgr.visit(&DeclContextAllNamesVisitor::visit, &Visitor); |
| 5536 | ++NumVisibleDeclContextsRead; |
| 5537 | |
| 5538 | for (llvm::DenseMap<DeclarationName, |
| 5539 | llvm::SmallVector<NamedDecl*, 8> >::iterator |
| 5540 | I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
| 5541 | SetExternalVisibleDeclsForName(DC, I->first, I->second); |
| 5542 | } |
Argyrios Kyrtzidis | 394e539 | 2012-04-26 18:34:14 +0000 | [diff] [blame] | 5543 | const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false); |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5544 | } |
| 5545 | |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5546 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 5547 | /// before receiving the implementation, and codegen depends on this. |
| 5548 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 5549 | /// implementation before passing the deserialized implementation decl. |
| 5550 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 5551 | ASTConsumer *Consumer) { |
| 5552 | assert(ImplD && Consumer); |
| 5553 | |
| 5554 | for (ObjCImplDecl::method_iterator |
| 5555 | I = ImplD->meth_begin(), E = ImplD->meth_end(); I != E; ++I) |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 5556 | Consumer->HandleInterestingDecl(DeclGroupRef(*I)); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5557 | |
| 5558 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 5559 | } |
| 5560 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5561 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5562 | assert(Consumer); |
| 5563 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5564 | Decl *D = InterestingDecls.front(); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5565 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5566 | |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 5567 | PassInterestingDeclToConsumer(D); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5568 | } |
| 5569 | } |
| 5570 | |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 5571 | void ASTReader::PassInterestingDeclToConsumer(Decl *D) { |
| 5572 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 5573 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 5574 | else |
| 5575 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
| 5576 | } |
| 5577 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5578 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 5579 | this->Consumer = Consumer; |
| 5580 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5581 | if (!Consumer) |
| 5582 | return; |
| 5583 | |
| 5584 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5585 | // Force deserialization of this decl, which will cause it to be queued for |
| 5586 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 5587 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5588 | } |
Douglas Gregor | 1a995dd | 2011-09-15 18:47:32 +0000 | [diff] [blame] | 5589 | ExternalDefinitions.clear(); |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 5590 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5591 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5592 | } |
| 5593 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5594 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5595 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5596 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5597 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5598 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5599 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5600 | unsigned NumDeclsLoaded |
| 5601 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 5602 | (Decl *)0); |
| 5603 | unsigned NumIdentifiersLoaded |
| 5604 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 5605 | IdentifiersLoaded.end(), |
| 5606 | (IdentifierInfo *)0); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5607 | unsigned NumMacrosLoaded |
| 5608 | = MacrosLoaded.size() - std::count(MacrosLoaded.begin(), |
| 5609 | MacrosLoaded.end(), |
| 5610 | (MacroInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5611 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5612 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 5613 | SelectorsLoaded.end(), |
| 5614 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 5615 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 5616 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 5617 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 5618 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 5619 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 5620 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 5621 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5622 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5623 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5624 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 5625 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 5626 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5627 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5628 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 5629 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5630 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5631 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5632 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 5633 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5634 | if (!MacrosLoaded.empty()) |
| 5635 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 5636 | NumMacrosLoaded, (unsigned)MacrosLoaded.size(), |
| 5637 | ((float)NumMacrosLoaded/MacrosLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5638 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5639 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5640 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 5641 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5642 | if (TotalNumStatements) |
| 5643 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 5644 | NumStatementsRead, TotalNumStatements, |
| 5645 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 5646 | if (TotalNumMacros) |
| 5647 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 5648 | NumMacrosRead, TotalNumMacros, |
| 5649 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 5650 | if (TotalLexicalDeclContexts) |
| 5651 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 5652 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 5653 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 5654 | * 100)); |
| 5655 | if (TotalVisibleDeclContexts) |
| 5656 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 5657 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 5658 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 5659 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5660 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5661 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5662 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 5663 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5664 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5665 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5666 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5667 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5668 | dump(); |
| 5669 | std::fprintf(stderr, "\n"); |
| 5670 | } |
| 5671 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5672 | template<typename Key, typename ModuleFile, unsigned InitialCapacity> |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5673 | static void |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5674 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5675 | const ContinuousRangeMap<Key, ModuleFile *, |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5676 | InitialCapacity> &Map) { |
| 5677 | if (Map.begin() == Map.end()) |
| 5678 | return; |
| 5679 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5680 | typedef ContinuousRangeMap<Key, ModuleFile *, InitialCapacity> MapType; |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5681 | llvm::errs() << Name << ":\n"; |
| 5682 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 5683 | I != IEnd; ++I) { |
| 5684 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 5685 | << "\n"; |
| 5686 | } |
| 5687 | } |
| 5688 | |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5689 | void ASTReader::dump() { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5690 | llvm::errs() << "*** PCH/ModuleFile Remappings:\n"; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5691 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5692 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 5693 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5694 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5695 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5696 | dumpModuleIDMap("Global macro map", GlobalMacroMap); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5697 | dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5698 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5699 | dumpModuleIDMap("Global preprocessed entity map", |
| 5700 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 8df5c9b | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 5701 | |
| 5702 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 5703 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 5704 | MEnd = ModuleMgr.end(); |
| 5705 | M != MEnd; ++M) |
| 5706 | (*M)->dump(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5707 | } |
| 5708 | |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5709 | /// Return the amount of memory used by memory buffers, breaking down |
| 5710 | /// by heap-backed versus mmap'ed memory. |
| 5711 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5712 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 5713 | E = ModuleMgr.end(); I != E; ++I) { |
| 5714 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5715 | size_t bytes = buf->getBufferSize(); |
| 5716 | switch (buf->getBufferKind()) { |
| 5717 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 5718 | sizes.malloc_bytes += bytes; |
| 5719 | break; |
| 5720 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 5721 | sizes.mmap_bytes += bytes; |
| 5722 | break; |
| 5723 | } |
| 5724 | } |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5725 | } |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5726 | } |
| 5727 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5728 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5729 | SemaObj = &S; |
Axel Naumann | 0ec56b7 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 5730 | S.addExternalSource(this); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5731 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 5732 | // Makes sure any declarations that were deserialized "too early" |
| 5733 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 5734 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5735 | SemaObj->pushExternalDeclIntoScope(PreloadedDecls[I], |
| 5736 | PreloadedDecls[I]->getDeclName()); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5737 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 5738 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 5739 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5740 | // Load the offsets of the declarations that Sema references. |
| 5741 | // They will be lazily deserialized when needed. |
| 5742 | if (!SemaDeclRefs.empty()) { |
| 5743 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | 1e5b6f6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 5744 | if (!SemaObj->StdNamespace) |
| 5745 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 5746 | if (!SemaObj->StdBadAlloc) |
| 5747 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5748 | } |
| 5749 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 5750 | if (!FPPragmaOptions.empty()) { |
| 5751 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 5752 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 5753 | } |
| 5754 | |
| 5755 | if (!OpenCLExtensions.empty()) { |
| 5756 | unsigned I = 0; |
| 5757 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 5758 | #include "clang/Basic/OpenCLExtensions.def" |
| 5759 | |
| 5760 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 5761 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5762 | } |
| 5763 | |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5764 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 5765 | // Note that we are loading an identifier. |
| 5766 | Deserializing AnIdentifier(this); |
| 5767 | |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 5768 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart), |
| 5769 | /*PriorGeneration=*/0); |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5770 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5771 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 5772 | markIdentifierUpToDate(II); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5773 | return II; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5774 | } |
| 5775 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5776 | namespace clang { |
| 5777 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 5778 | /// identifiers stored within a set of AST files. |
| 5779 | class ASTIdentifierIterator : public IdentifierIterator { |
| 5780 | /// \brief The AST reader whose identifiers are being enumerated. |
| 5781 | const ASTReader &Reader; |
| 5782 | |
| 5783 | /// \brief The current index into the chain of AST files stored in |
| 5784 | /// the AST reader. |
| 5785 | unsigned Index; |
| 5786 | |
| 5787 | /// \brief The current position within the identifier lookup table |
| 5788 | /// of the current AST file. |
| 5789 | ASTIdentifierLookupTable::key_iterator Current; |
| 5790 | |
| 5791 | /// \brief The end position within the identifier lookup table of |
| 5792 | /// the current AST file. |
| 5793 | ASTIdentifierLookupTable::key_iterator End; |
| 5794 | |
| 5795 | public: |
| 5796 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 5797 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5798 | virtual StringRef Next(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5799 | }; |
| 5800 | } |
| 5801 | |
| 5802 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5803 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5804 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5805 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5806 | Current = IdTable->key_begin(); |
| 5807 | End = IdTable->key_end(); |
| 5808 | } |
| 5809 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5810 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5811 | while (Current == End) { |
| 5812 | // If we have exhausted all of our AST files, we're done. |
| 5813 | if (Index == 0) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5814 | return StringRef(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5815 | |
| 5816 | --Index; |
| 5817 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5818 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 5819 | IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5820 | Current = IdTable->key_begin(); |
| 5821 | End = IdTable->key_end(); |
| 5822 | } |
| 5823 | |
| 5824 | // We have any identifiers remaining in the current AST file; return |
| 5825 | // the next one. |
| 5826 | std::pair<const char*, unsigned> Key = *Current; |
| 5827 | ++Current; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5828 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5829 | } |
| 5830 | |
| 5831 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 5832 | return new ASTIdentifierIterator(*this); |
| 5833 | } |
| 5834 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5835 | namespace clang { namespace serialization { |
| 5836 | class ReadMethodPoolVisitor { |
| 5837 | ASTReader &Reader; |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5838 | Selector Sel; |
| 5839 | unsigned PriorGeneration; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5840 | llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 5841 | llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5842 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5843 | public: |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5844 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, |
| 5845 | unsigned PriorGeneration) |
| 5846 | : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration) { } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5847 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5848 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5849 | ReadMethodPoolVisitor *This |
| 5850 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 5851 | |
| 5852 | if (!M.SelectorLookupTable) |
| 5853 | return false; |
| 5854 | |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5855 | // If we've already searched this module file, skip it now. |
| 5856 | if (M.Generation <= This->PriorGeneration) |
| 5857 | return true; |
| 5858 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5859 | ASTSelectorLookupTable *PoolTable |
| 5860 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 5861 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 5862 | if (Pos == PoolTable->end()) |
| 5863 | return false; |
| 5864 | |
| 5865 | ++This->Reader.NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5866 | // FIXME: Not quite happy with the statistics here. We probably should |
| 5867 | // disable this tracking when called via LoadSelector. |
| 5868 | // Also, should entries without methods count as misses? |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5869 | ++This->Reader.NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5870 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5871 | if (This->Reader.DeserializationListener) |
| 5872 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 5873 | This->Sel); |
| 5874 | |
| 5875 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 5876 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 5877 | return true; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5878 | } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5879 | |
| 5880 | /// \brief Retrieve the instance methods found by this visitor. |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5881 | ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { |
| 5882 | return InstanceMethods; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5883 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5884 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5885 | /// \brief Retrieve the instance methods found by this visitor. |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5886 | ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { |
| 5887 | return FactoryMethods; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5888 | } |
| 5889 | }; |
| 5890 | } } // end namespace clang::serialization |
| 5891 | |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5892 | /// \brief Add the given set of methods to the method list. |
| 5893 | static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, |
| 5894 | ObjCMethodList &List) { |
| 5895 | for (unsigned I = 0, N = Methods.size(); I != N; ++I) { |
| 5896 | S.addMethodToGlobalList(&List, Methods[I]); |
| 5897 | } |
| 5898 | } |
| 5899 | |
| 5900 | void ASTReader::ReadMethodPool(Selector Sel) { |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5901 | // Get the selector generation and update it to the current generation. |
| 5902 | unsigned &Generation = SelectorGeneration[Sel]; |
| 5903 | unsigned PriorGeneration = Generation; |
| 5904 | Generation = CurrentGeneration; |
| 5905 | |
| 5906 | // Search for methods defined with this selector. |
| 5907 | ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration); |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5908 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5909 | |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5910 | if (Visitor.getInstanceMethods().empty() && |
| 5911 | Visitor.getFactoryMethods().empty()) { |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5912 | ++NumMethodPoolMisses; |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5913 | return; |
| 5914 | } |
| 5915 | |
| 5916 | if (!getSema()) |
| 5917 | return; |
| 5918 | |
| 5919 | Sema &S = *getSema(); |
| 5920 | Sema::GlobalMethodPool::iterator Pos |
| 5921 | = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; |
| 5922 | |
| 5923 | addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); |
| 5924 | addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5925 | } |
| 5926 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 5927 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5928 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 5929 | Namespaces.clear(); |
| 5930 | |
| 5931 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 5932 | if (NamespaceDecl *Namespace |
| 5933 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 5934 | Namespaces.push_back(Namespace); |
| 5935 | } |
| 5936 | } |
| 5937 | |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 5938 | void ASTReader::ReadTentativeDefinitions( |
| 5939 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 5940 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 5941 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 5942 | if (Var) |
| 5943 | TentativeDefs.push_back(Var); |
| 5944 | } |
| 5945 | TentativeDefinitions.clear(); |
| 5946 | } |
| 5947 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 5948 | void ASTReader::ReadUnusedFileScopedDecls( |
| 5949 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 5950 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 5951 | DeclaratorDecl *D |
| 5952 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 5953 | if (D) |
| 5954 | Decls.push_back(D); |
| 5955 | } |
| 5956 | UnusedFileScopedDecls.clear(); |
| 5957 | } |
| 5958 | |
Douglas Gregor | 0129b56 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 5959 | void ASTReader::ReadDelegatingConstructors( |
| 5960 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 5961 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 5962 | CXXConstructorDecl *D |
| 5963 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 5964 | if (D) |
| 5965 | Decls.push_back(D); |
| 5966 | } |
| 5967 | DelegatingCtorDecls.clear(); |
| 5968 | } |
| 5969 | |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 5970 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 5971 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 5972 | TypedefNameDecl *D |
| 5973 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 5974 | if (D) |
| 5975 | Decls.push_back(D); |
| 5976 | } |
| 5977 | ExtVectorDecls.clear(); |
| 5978 | } |
| 5979 | |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 5980 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 5981 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 5982 | CXXRecordDecl *D |
| 5983 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 5984 | if (D) |
| 5985 | Decls.push_back(D); |
| 5986 | } |
| 5987 | DynamicClasses.clear(); |
| 5988 | } |
| 5989 | |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 5990 | void |
| 5991 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 5992 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 5993 | NamedDecl *D |
| 5994 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 5995 | if (D) |
| 5996 | Decls.push_back(D); |
| 5997 | } |
| 5998 | LocallyScopedExternalDecls.clear(); |
| 5999 | } |
| 6000 | |
Douglas Gregor | 5b9dc7c | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 6001 | void ASTReader::ReadReferencedSelectors( |
| 6002 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 6003 | if (ReferencedSelectorsData.empty()) |
| 6004 | return; |
| 6005 | |
| 6006 | // If there are @selector references added them to its pool. This is for |
| 6007 | // implementation of -Wselector. |
| 6008 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 6009 | unsigned I = 0; |
| 6010 | while (I < DataSize) { |
| 6011 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 6012 | SourceLocation SelLoc |
| 6013 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 6014 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 6015 | } |
| 6016 | ReferencedSelectorsData.clear(); |
| 6017 | } |
| 6018 | |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 6019 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 6020 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 6021 | if (WeakUndeclaredIdentifiers.empty()) |
| 6022 | return; |
| 6023 | |
| 6024 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 6025 | IdentifierInfo *WeakId |
| 6026 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 6027 | IdentifierInfo *AliasId |
| 6028 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 6029 | SourceLocation Loc |
| 6030 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 6031 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 6032 | WeakInfo WI(AliasId, Loc); |
| 6033 | WI.setUsed(Used); |
| 6034 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 6035 | } |
| 6036 | WeakUndeclaredIdentifiers.clear(); |
| 6037 | } |
| 6038 | |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 6039 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 6040 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 6041 | ExternalVTableUse VT; |
| 6042 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 6043 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 6044 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 6045 | VTables.push_back(VT); |
| 6046 | } |
| 6047 | |
| 6048 | VTableUses.clear(); |
| 6049 | } |
| 6050 | |
Douglas Gregor | 6e4a3f5 | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 6051 | void ASTReader::ReadPendingInstantiations( |
| 6052 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 6053 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 6054 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 6055 | SourceLocation Loc |
| 6056 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 6057 | |
Douglas Gregor | e5fa3c2 | 2012-10-03 18:34:48 +0000 | [diff] [blame] | 6058 | Pending.push_back(std::make_pair(D, Loc)); |
Douglas Gregor | 6e4a3f5 | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 6059 | } |
| 6060 | PendingInstantiations.clear(); |
| 6061 | } |
| 6062 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6063 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 6064 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 6065 | ReadMethodPool(Sel); |
| 6066 | } |
| 6067 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6068 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6069 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 6070 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 6071 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 6072 | if (DeserializationListener) |
| 6073 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6074 | } |
| 6075 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6076 | /// \brief Set the globally-visible declarations associated with the given |
| 6077 | /// identifier. |
| 6078 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 6079 | /// 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] | 6080 | /// 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] | 6081 | /// them. |
| 6082 | /// |
| 6083 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 6084 | /// declarations. |
| 6085 | /// |
| 6086 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 6087 | /// visible at global scope. |
| 6088 | /// |
| 6089 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 6090 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 6091 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6092 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6093 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6094 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6095 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 6096 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6097 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 6098 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 6099 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 6100 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6101 | return; |
| 6102 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6103 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6104 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 6105 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 6106 | if (SemaObj) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 6107 | // Introduce this declaration into the translation-unit scope |
| 6108 | // and add it to the declaration chain for this identifier, so |
| 6109 | // that (unqualified) name lookup will find it. |
| 6110 | SemaObj->pushExternalDeclIntoScope(D, II); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6111 | } else { |
| 6112 | // Queue this declaration so that it will be added to the |
| 6113 | // translation unit scope and identifier's declaration chain |
| 6114 | // once a Sema object is known. |
| 6115 | PreloadedDecls.push_back(D); |
| 6116 | } |
| 6117 | } |
| 6118 | } |
| 6119 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6120 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 6121 | if (ID == 0) |
| 6122 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6123 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 6124 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 6125 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 6126 | return 0; |
| 6127 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6128 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 6129 | ID -= 1; |
| 6130 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 6131 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 6132 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6133 | ModuleFile *M = I->second; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 6134 | unsigned Index = ID - M->BaseIdentifierID; |
| 6135 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 6136 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 6137 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 6138 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 6139 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 6140 | // unsigned integers. This is important to avoid integer overflow when |
| 6141 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 6142 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 6143 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 6144 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 6145 | IdentifiersLoaded[ID] |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 6146 | = &PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 6147 | if (DeserializationListener) |
| 6148 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 6149 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6150 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 6151 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6152 | } |
| 6153 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6154 | IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6155 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 6156 | } |
| 6157 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6158 | IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 6159 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 6160 | return LocalID; |
| 6161 | |
| 6162 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6163 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 6164 | assert(I != M.IdentifierRemap.end() |
| 6165 | && "Invalid index into identifier index remap"); |
| 6166 | |
| 6167 | return LocalID + I->second; |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6168 | } |
| 6169 | |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 6170 | MacroInfo *ASTReader::getMacro(MacroID ID, MacroInfo *Hint) { |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6171 | if (ID == 0) |
| 6172 | return 0; |
| 6173 | |
| 6174 | if (MacrosLoaded.empty()) { |
| 6175 | Error("no macro table in AST file"); |
| 6176 | return 0; |
| 6177 | } |
| 6178 | |
| 6179 | ID -= NUM_PREDEF_MACRO_IDS; |
| 6180 | if (!MacrosLoaded[ID]) { |
| 6181 | GlobalMacroMapType::iterator I |
| 6182 | = GlobalMacroMap.find(ID + NUM_PREDEF_MACRO_IDS); |
| 6183 | assert(I != GlobalMacroMap.end() && "Corrupted global macro map"); |
| 6184 | ModuleFile *M = I->second; |
| 6185 | unsigned Index = ID - M->BaseMacroID; |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 6186 | ReadMacroRecord(*M, M->MacroOffsets[Index], Hint); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | return MacrosLoaded[ID]; |
| 6190 | } |
| 6191 | |
| 6192 | MacroID ASTReader::getGlobalMacroID(ModuleFile &M, unsigned LocalID) { |
| 6193 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 6194 | return LocalID; |
| 6195 | |
| 6196 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6197 | = M.MacroRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 6198 | assert(I != M.MacroRemap.end() && "Invalid index into macro index remap"); |
| 6199 | |
| 6200 | return LocalID + I->second; |
| 6201 | } |
| 6202 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 6203 | serialization::SubmoduleID |
| 6204 | ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) { |
| 6205 | if (LocalID < NUM_PREDEF_SUBMODULE_IDS) |
| 6206 | return LocalID; |
| 6207 | |
| 6208 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6209 | = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS); |
| 6210 | assert(I != M.SubmoduleRemap.end() |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6211 | && "Invalid index into submodule index remap"); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 6212 | |
| 6213 | return LocalID + I->second; |
| 6214 | } |
| 6215 | |
| 6216 | Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { |
| 6217 | if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) { |
| 6218 | assert(GlobalID == 0 && "Unhandled global submodule ID"); |
| 6219 | return 0; |
| 6220 | } |
| 6221 | |
| 6222 | if (GlobalID > SubmodulesLoaded.size()) { |
| 6223 | Error("submodule ID out of range in AST file"); |
| 6224 | return 0; |
| 6225 | } |
| 6226 | |
| 6227 | return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; |
| 6228 | } |
| 6229 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6230 | Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 6231 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 6232 | } |
| 6233 | |
| 6234 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 6235 | if (ID == 0) |
| 6236 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6237 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 6238 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 6239 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 6240 | return Selector(); |
| 6241 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 6242 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 6243 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 6244 | // Load this selector from the selector table. |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 6245 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 6246 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6247 | ModuleFile &M = *I->second; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 6248 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 6249 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 6250 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 6251 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 6252 | if (DeserializationListener) |
| 6253 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 6254 | } |
| 6255 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 6256 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 6257 | } |
| 6258 | |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 6259 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 6260 | return DecodeSelector(ID); |
| 6261 | } |
| 6262 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6263 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 6264 | // ID 0 (the null selector) is considered an external selector. |
| 6265 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 6266 | } |
| 6267 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 6268 | serialization::SelectorID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6269 | ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 6270 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 6271 | return LocalID; |
| 6272 | |
| 6273 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6274 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 6275 | assert(I != M.SelectorRemap.end() |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6276 | && "Invalid index into selector index remap"); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 6277 | |
| 6278 | return LocalID + I->second; |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 6279 | } |
| 6280 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6281 | DeclarationName |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6282 | ASTReader::ReadDeclarationName(ModuleFile &F, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6283 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6284 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 6285 | switch (Kind) { |
| 6286 | case DeclarationName::Identifier: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6287 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6288 | |
| 6289 | case DeclarationName::ObjCZeroArgSelector: |
| 6290 | case DeclarationName::ObjCOneArgSelector: |
| 6291 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 6292 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6293 | |
| 6294 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6295 | return Context.DeclarationNames.getCXXConstructorName( |
| 6296 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6297 | |
| 6298 | case DeclarationName::CXXDestructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6299 | return Context.DeclarationNames.getCXXDestructorName( |
| 6300 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6301 | |
| 6302 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6303 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 6304 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6305 | |
| 6306 | case DeclarationName::CXXOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6307 | return Context.DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6308 | (OverloadedOperatorKind)Record[Idx++]); |
| 6309 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 6310 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6311 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6312 | GetIdentifierInfo(F, Record, Idx)); |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 6313 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6314 | case DeclarationName::CXXUsingDirective: |
| 6315 | return DeclarationName::getUsingDirectiveName(); |
| 6316 | } |
| 6317 | |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 6318 | llvm_unreachable("Invalid NameKind!"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6319 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 6320 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6321 | void ASTReader::ReadDeclarationNameLoc(ModuleFile &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6322 | DeclarationNameLoc &DNLoc, |
| 6323 | DeclarationName Name, |
| 6324 | const RecordData &Record, unsigned &Idx) { |
| 6325 | switch (Name.getNameKind()) { |
| 6326 | case DeclarationName::CXXConstructorName: |
| 6327 | case DeclarationName::CXXDestructorName: |
| 6328 | case DeclarationName::CXXConversionFunctionName: |
| 6329 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 6330 | break; |
| 6331 | |
| 6332 | case DeclarationName::CXXOperatorName: |
| 6333 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 6334 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 6335 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 6336 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 6337 | break; |
| 6338 | |
| 6339 | case DeclarationName::CXXLiteralOperatorName: |
| 6340 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 6341 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 6342 | break; |
| 6343 | |
| 6344 | case DeclarationName::Identifier: |
| 6345 | case DeclarationName::ObjCZeroArgSelector: |
| 6346 | case DeclarationName::ObjCOneArgSelector: |
| 6347 | case DeclarationName::ObjCMultiArgSelector: |
| 6348 | case DeclarationName::CXXUsingDirective: |
| 6349 | break; |
| 6350 | } |
| 6351 | } |
| 6352 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6353 | void ASTReader::ReadDeclarationNameInfo(ModuleFile &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6354 | DeclarationNameInfo &NameInfo, |
| 6355 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6356 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6357 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 6358 | DeclarationNameLoc DNLoc; |
| 6359 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 6360 | NameInfo.setInfo(DNLoc); |
| 6361 | } |
| 6362 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6363 | void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6364 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 6365 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6366 | unsigned NumTPLists = Record[Idx++]; |
| 6367 | Info.NumTemplParamLists = NumTPLists; |
| 6368 | if (NumTPLists) { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6369 | Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6370 | for (unsigned i=0; i != NumTPLists; ++i) |
| 6371 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 6372 | } |
| 6373 | } |
| 6374 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6375 | TemplateName |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6376 | ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6377 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6378 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6379 | switch (Kind) { |
| 6380 | case TemplateName::Template: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6381 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6382 | |
| 6383 | case TemplateName::OverloadedTemplate: { |
| 6384 | unsigned size = Record[Idx++]; |
| 6385 | UnresolvedSet<8> Decls; |
| 6386 | while (size--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6387 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6388 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6389 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6390 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6391 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6392 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6393 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6394 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6395 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6396 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6397 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6398 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6399 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6400 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6401 | if (Record[Idx++]) // isIdentifier |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6402 | return Context.getDependentTemplateName(NNS, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6403 | GetIdentifierInfo(F, Record, |
| 6404 | Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6405 | return Context.getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 6406 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6407 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6408 | |
| 6409 | case TemplateName::SubstTemplateTemplateParm: { |
| 6410 | TemplateTemplateParmDecl *param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6411 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6412 | if (!param) return TemplateName(); |
| 6413 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6414 | return Context.getSubstTemplateTemplateParm(param, replacement); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6415 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6416 | |
| 6417 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 6418 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6419 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6420 | if (!Param) |
| 6421 | return TemplateName(); |
| 6422 | |
| 6423 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 6424 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 6425 | return TemplateName(); |
| 6426 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6427 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6428 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6429 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6430 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 6431 | llvm_unreachable("Unhandled template name kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6432 | } |
| 6433 | |
| 6434 | TemplateArgument |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6435 | ASTReader::ReadTemplateArgument(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 6436 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 6437 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 6438 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6439 | case TemplateArgument::Null: |
| 6440 | return TemplateArgument(); |
| 6441 | case TemplateArgument::Type: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6442 | return TemplateArgument(readType(F, Record, Idx)); |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 6443 | case TemplateArgument::Declaration: { |
| 6444 | ValueDecl *D = ReadDeclAs<ValueDecl>(F, Record, Idx); |
| 6445 | bool ForReferenceParam = Record[Idx++]; |
| 6446 | return TemplateArgument(D, ForReferenceParam); |
| 6447 | } |
| 6448 | case TemplateArgument::NullPtr: |
| 6449 | return TemplateArgument(readType(F, Record, Idx), /*isNullPtr*/true); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 6450 | case TemplateArgument::Integral: { |
| 6451 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6452 | QualType T = readType(F, Record, Idx); |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 6453 | return TemplateArgument(Context, Value, T); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 6454 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 6455 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6456 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 6457 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6458 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 6459 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 6460 | if (unsigned NumExpansions = Record[Idx++]) |
| 6461 | NumTemplateExpansions = NumExpansions - 1; |
| 6462 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 6463 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6464 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6465 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6466 | case TemplateArgument::Pack: { |
| 6467 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6468 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 6469 | for (unsigned I = 0; I != NumArgs; ++I) |
| 6470 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 6471 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6472 | } |
| 6473 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6474 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 6475 | llvm_unreachable("Unhandled template argument kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6476 | } |
| 6477 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6478 | TemplateParameterList * |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6479 | ASTReader::ReadTemplateParameterList(ModuleFile &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6480 | const RecordData &Record, unsigned &Idx) { |
| 6481 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 6482 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 6483 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6484 | |
| 6485 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6486 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6487 | Params.reserve(NumParams); |
| 6488 | while (NumParams--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6489 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6490 | |
| 6491 | TemplateParameterList* TemplateParams = |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6492 | TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6493 | Params.data(), Params.size(), RAngleLoc); |
| 6494 | return TemplateParams; |
| 6495 | } |
| 6496 | |
| 6497 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6498 | ASTReader:: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6499 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6500 | ModuleFile &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6501 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6502 | unsigned NumTemplateArgs = Record[Idx++]; |
| 6503 | TemplArgs.reserve(NumTemplateArgs); |
| 6504 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6505 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6506 | } |
| 6507 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6508 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6509 | void ASTReader::ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6510 | const RecordData &Record, unsigned &Idx) { |
| 6511 | unsigned NumDecls = Record[Idx++]; |
| 6512 | while (NumDecls--) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6513 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6514 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 6515 | Set.addDecl(D, AS); |
| 6516 | } |
| 6517 | } |
| 6518 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6519 | CXXBaseSpecifier |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6520 | ASTReader::ReadCXXBaseSpecifier(ModuleFile &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 6521 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6522 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 6523 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 6524 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6525 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6526 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 6527 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 6528 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6529 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 6530 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6531 | Result.setInheritConstructors(inheritConstructors); |
| 6532 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6533 | } |
| 6534 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6535 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6536 | ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6537 | unsigned &Idx) { |
| 6538 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6539 | unsigned NumInitializers = Record[Idx++]; |
| 6540 | if (NumInitializers) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6541 | CtorInitializers |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6542 | = new (Context) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6543 | for (unsigned i=0; i != NumInitializers; ++i) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6544 | TypeSourceInfo *TInfo = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6545 | bool IsBaseVirtual = false; |
| 6546 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6547 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6548 | |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6549 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 6550 | switch (Type) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6551 | case CTOR_INITIALIZER_BASE: |
| 6552 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6553 | IsBaseVirtual = Record[Idx++]; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6554 | break; |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6555 | |
| 6556 | case CTOR_INITIALIZER_DELEGATING: |
| 6557 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6558 | break; |
| 6559 | |
| 6560 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6561 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6562 | break; |
| 6563 | |
| 6564 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6565 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6566 | break; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6567 | } |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6568 | |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 6569 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6570 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6571 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 6572 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6573 | bool IsWritten = Record[Idx++]; |
| 6574 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6575 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6576 | if (IsWritten) { |
| 6577 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 6578 | } else { |
| 6579 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 6580 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 6581 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6582 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6583 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6584 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6585 | CXXCtorInitializer *BOMInit; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6586 | if (Type == CTOR_INITIALIZER_BASE) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6587 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, IsBaseVirtual, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6588 | LParenLoc, Init, RParenLoc, |
| 6589 | MemberOrEllipsisLoc); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6590 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6591 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, LParenLoc, |
| 6592 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6593 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6594 | if (Member) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6595 | BOMInit = new (Context) CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6596 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6597 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6598 | BOMInit = new (Context) CXXCtorInitializer(Context, IndirectMember, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6599 | MemberOrEllipsisLoc, LParenLoc, |
| 6600 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6601 | } else { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6602 | BOMInit = CXXCtorInitializer::Create(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6603 | LParenLoc, Init, RParenLoc, |
| 6604 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6605 | } |
| 6606 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 6607 | if (IsWritten) |
| 6608 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6609 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6610 | } |
| 6611 | } |
| 6612 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6613 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6614 | } |
| 6615 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6616 | NestedNameSpecifier * |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6617 | ASTReader::ReadNestedNameSpecifier(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6618 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6619 | unsigned N = Record[Idx++]; |
| 6620 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 6621 | for (unsigned I = 0; I != N; ++I) { |
| 6622 | NestedNameSpecifier::SpecifierKind Kind |
| 6623 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 6624 | switch (Kind) { |
| 6625 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6626 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6627 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6628 | break; |
| 6629 | } |
| 6630 | |
| 6631 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6632 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6633 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6634 | break; |
| 6635 | } |
| 6636 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 6637 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6638 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6639 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 6640 | break; |
| 6641 | } |
| 6642 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6643 | case NestedNameSpecifier::TypeSpec: |
| 6644 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6645 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 6646 | if (!T) |
| 6647 | return 0; |
| 6648 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6649 | bool Template = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6650 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6651 | break; |
| 6652 | } |
| 6653 | |
| 6654 | case NestedNameSpecifier::Global: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6655 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6656 | // No associated value, and there can't be a prefix. |
| 6657 | break; |
| 6658 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6659 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 6660 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6661 | } |
| 6662 | return NNS; |
| 6663 | } |
| 6664 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6665 | NestedNameSpecifierLoc |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6666 | ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6667 | unsigned &Idx) { |
| 6668 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6669 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6670 | for (unsigned I = 0; I != N; ++I) { |
| 6671 | NestedNameSpecifier::SpecifierKind Kind |
| 6672 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 6673 | switch (Kind) { |
| 6674 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6675 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6676 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6677 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6678 | break; |
| 6679 | } |
| 6680 | |
| 6681 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6682 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6683 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6684 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6685 | break; |
| 6686 | } |
| 6687 | |
| 6688 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6689 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6690 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6691 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6692 | break; |
| 6693 | } |
| 6694 | |
| 6695 | case NestedNameSpecifier::TypeSpec: |
| 6696 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6697 | bool Template = Record[Idx++]; |
| 6698 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 6699 | if (!T) |
| 6700 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6701 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6702 | |
| 6703 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6704 | Builder.Extend(Context, |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6705 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 6706 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6707 | break; |
| 6708 | } |
| 6709 | |
| 6710 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6711 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6712 | Builder.MakeGlobal(Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6713 | break; |
| 6714 | } |
| 6715 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6716 | } |
| 6717 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6718 | return Builder.getWithLocInContext(Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6719 | } |
| 6720 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6721 | SourceRange |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6722 | ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6723 | unsigned &Idx) { |
| 6724 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 6725 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 6726 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6727 | } |
| 6728 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6729 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6730 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6731 | unsigned BitWidth = Record[Idx++]; |
| 6732 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 6733 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 6734 | Idx += NumWords; |
| 6735 | return Result; |
| 6736 | } |
| 6737 | |
| 6738 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6739 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6740 | bool isUnsigned = Record[Idx++]; |
| 6741 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 6742 | } |
| 6743 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 6744 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6745 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 6746 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 6747 | } |
| 6748 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6749 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6750 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6751 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 6752 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6753 | Idx += Len; |
| 6754 | return Result; |
| 6755 | } |
| 6756 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 6757 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 6758 | unsigned &Idx) { |
| 6759 | unsigned Major = Record[Idx++]; |
| 6760 | unsigned Minor = Record[Idx++]; |
| 6761 | unsigned Subminor = Record[Idx++]; |
| 6762 | if (Minor == 0) |
| 6763 | return VersionTuple(Major); |
| 6764 | if (Subminor == 0) |
| 6765 | return VersionTuple(Major, Minor - 1); |
| 6766 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 6767 | } |
| 6768 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6769 | CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6770 | const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 6771 | unsigned &Idx) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6772 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6773 | return CXXTemporary::Create(Context, Decl); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 6774 | } |
| 6775 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6776 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 6777 | return Diag(SourceLocation(), DiagID); |
| 6778 | } |
| 6779 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6780 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6781 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 6782 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6783 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6784 | /// \brief Retrieve the identifier table associated with the |
| 6785 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6786 | IdentifierTable &ASTReader::getIdentifierTable() { |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 6787 | return PP.getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6788 | } |
| 6789 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6790 | /// \brief Record that the given ID maps to the given switch-case |
| 6791 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6792 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6793 | assert((*CurrSwitchCaseStmts)[ID] == 0 && |
| 6794 | "Already have a SwitchCase with this ID"); |
| 6795 | (*CurrSwitchCaseStmts)[ID] = SC; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6796 | } |
| 6797 | |
| 6798 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6799 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6800 | assert((*CurrSwitchCaseStmts)[ID] != 0 && "No SwitchCase with this ID"); |
| 6801 | return (*CurrSwitchCaseStmts)[ID]; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6802 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 6803 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 6804 | void ASTReader::ClearSwitchCaseIDs() { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6805 | CurrSwitchCaseStmts->clear(); |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 6806 | } |
| 6807 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6808 | void ASTReader::ReadComments() { |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 6809 | std::vector<RawComment *> Comments; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6810 | for (SmallVectorImpl<std::pair<llvm::BitstreamCursor, |
| 6811 | serialization::ModuleFile *> >::iterator |
| 6812 | I = CommentsCursors.begin(), |
| 6813 | E = CommentsCursors.end(); |
| 6814 | I != E; ++I) { |
| 6815 | llvm::BitstreamCursor &Cursor = I->first; |
| 6816 | serialization::ModuleFile &F = *I->second; |
| 6817 | SavedStreamPosition SavedPosition(Cursor); |
| 6818 | |
| 6819 | RecordData Record; |
| 6820 | while (true) { |
| 6821 | unsigned Code = Cursor.ReadCode(); |
| 6822 | if (Code == llvm::bitc::END_BLOCK) |
| 6823 | break; |
| 6824 | |
| 6825 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 6826 | // No known subblocks, always skip them. |
| 6827 | Cursor.ReadSubBlockID(); |
| 6828 | if (Cursor.SkipBlock()) { |
| 6829 | Error("malformed block record in AST file"); |
| 6830 | return; |
| 6831 | } |
| 6832 | continue; |
| 6833 | } |
| 6834 | |
| 6835 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 6836 | Cursor.ReadAbbrevRecord(); |
| 6837 | continue; |
| 6838 | } |
| 6839 | |
| 6840 | // Read a record. |
| 6841 | Record.clear(); |
| 6842 | switch ((CommentRecordTypes) Cursor.ReadRecord(Code, Record)) { |
Chandler Carruth | 13691bb | 2012-06-20 06:47:54 +0000 | [diff] [blame] | 6843 | case COMMENTS_RAW_COMMENT: { |
| 6844 | unsigned Idx = 0; |
| 6845 | SourceRange SR = ReadSourceRange(F, Record, Idx); |
| 6846 | RawComment::CommentKind Kind = |
| 6847 | (RawComment::CommentKind) Record[Idx++]; |
| 6848 | bool IsTrailingComment = Record[Idx++]; |
| 6849 | bool IsAlmostTrailingComment = Record[Idx++]; |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 6850 | Comments.push_back(new (Context) RawComment(SR, Kind, |
| 6851 | IsTrailingComment, |
| 6852 | IsAlmostTrailingComment)); |
Chandler Carruth | 13691bb | 2012-06-20 06:47:54 +0000 | [diff] [blame] | 6853 | break; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6854 | } |
| 6855 | } |
| 6856 | } |
| 6857 | } |
| 6858 | Context.Comments.addCommentsToFront(Comments); |
| 6859 | } |
| 6860 | |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6861 | void ASTReader::finishPendingActions() { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 6862 | while (!PendingIdentifierInfos.empty() || !PendingDeclChains.empty() || |
| 6863 | !PendingMacroIDs.empty()) { |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6864 | // If any identifiers with corresponding top-level declarations have |
| 6865 | // been loaded, load those declarations now. |
| 6866 | while (!PendingIdentifierInfos.empty()) { |
| 6867 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 6868 | PendingIdentifierInfos.front().DeclIDs, true); |
| 6869 | PendingIdentifierInfos.pop_front(); |
| 6870 | } |
| 6871 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 6872 | // Load pending declaration chains. |
| 6873 | for (unsigned I = 0; I != PendingDeclChains.size(); ++I) { |
| 6874 | loadPendingDeclChain(PendingDeclChains[I]); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6875 | PendingDeclChainsKnown.erase(PendingDeclChains[I]); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 6876 | } |
| 6877 | PendingDeclChains.clear(); |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 6878 | |
| 6879 | // Load any pending macro definitions. |
Douglas Gregor | e9652bf | 2012-10-11 17:31:34 +0000 | [diff] [blame] | 6880 | for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) { |
| 6881 | // FIXME: std::move here |
| 6882 | SmallVector<MacroID, 2> GlobalIDs = PendingMacroIDs.begin()[I].second; |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 6883 | MacroInfo *Hint = 0; |
Douglas Gregor | e9652bf | 2012-10-11 17:31:34 +0000 | [diff] [blame] | 6884 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
| 6885 | ++IDIdx) { |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 6886 | Hint = getMacro(GlobalIDs[IDIdx], Hint); |
Douglas Gregor | e9652bf | 2012-10-11 17:31:34 +0000 | [diff] [blame] | 6887 | } |
| 6888 | } |
| 6889 | PendingMacroIDs.clear(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6890 | } |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6891 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 6892 | // If we deserialized any C++ or Objective-C class definitions, any |
| 6893 | // Objective-C protocol definitions, or any redeclarable templates, make sure |
| 6894 | // that all redeclarations point to the definitions. Note that this can only |
| 6895 | // happen now, after the redeclaration chains have been fully wired. |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6896 | for (llvm::SmallPtrSet<Decl *, 4>::iterator D = PendingDefinitions.begin(), |
| 6897 | DEnd = PendingDefinitions.end(); |
| 6898 | D != DEnd; ++D) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6899 | if (TagDecl *TD = dyn_cast<TagDecl>(*D)) { |
| 6900 | if (const TagType *TagT = dyn_cast<TagType>(TD->TypeForDecl)) { |
| 6901 | // Make sure that the TagType points at the definition. |
| 6902 | const_cast<TagType*>(TagT)->decl = TD; |
| 6903 | } |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6904 | |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6905 | if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(*D)) { |
| 6906 | for (CXXRecordDecl::redecl_iterator R = RD->redecls_begin(), |
| 6907 | REnd = RD->redecls_end(); |
| 6908 | R != REnd; ++R) |
| 6909 | cast<CXXRecordDecl>(*R)->DefinitionData = RD->DefinitionData; |
| 6910 | |
| 6911 | } |
| 6912 | |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6913 | continue; |
| 6914 | } |
| 6915 | |
Douglas Gregor | 1d784b2 | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 6916 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(*D)) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6917 | // Make sure that the ObjCInterfaceType points at the definition. |
| 6918 | const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl)) |
| 6919 | ->Decl = ID; |
| 6920 | |
Douglas Gregor | 1d784b2 | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 6921 | for (ObjCInterfaceDecl::redecl_iterator R = ID->redecls_begin(), |
| 6922 | REnd = ID->redecls_end(); |
| 6923 | R != REnd; ++R) |
| 6924 | R->Data = ID->Data; |
| 6925 | |
| 6926 | continue; |
| 6927 | } |
| 6928 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 6929 | if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(*D)) { |
| 6930 | for (ObjCProtocolDecl::redecl_iterator R = PD->redecls_begin(), |
| 6931 | REnd = PD->redecls_end(); |
| 6932 | R != REnd; ++R) |
| 6933 | R->Data = PD->Data; |
| 6934 | |
| 6935 | continue; |
| 6936 | } |
| 6937 | |
| 6938 | RedeclarableTemplateDecl *RTD |
| 6939 | = cast<RedeclarableTemplateDecl>(*D)->getCanonicalDecl(); |
| 6940 | for (RedeclarableTemplateDecl::redecl_iterator R = RTD->redecls_begin(), |
| 6941 | REnd = RTD->redecls_end(); |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6942 | R != REnd; ++R) |
Douglas Gregor | 5456b0fe | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 6943 | R->Common = RTD->Common; |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6944 | } |
| 6945 | PendingDefinitions.clear(); |
Douglas Gregor | 5456b0fe | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 6946 | |
| 6947 | // Load the bodies of any functions or methods we've encountered. We do |
| 6948 | // this now (delayed) so that we can be sure that the declaration chains |
| 6949 | // have been fully wired up. |
Douglas Gregor | ce12d2f | 2012-10-09 17:50:23 +0000 | [diff] [blame] | 6950 | for (PendingBodiesMap::iterator PB = PendingBodies.begin(), |
| 6951 | PBEnd = PendingBodies.end(); |
Douglas Gregor | 5456b0fe | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 6952 | PB != PBEnd; ++PB) { |
| 6953 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) { |
| 6954 | // FIXME: Check for =delete/=default? |
| 6955 | // FIXME: Complain about ODR violations here? |
| 6956 | if (!getContext().getLangOpts().Modules || !FD->hasBody()) |
| 6957 | FD->setLazyBody(PB->second); |
| 6958 | continue; |
| 6959 | } |
| 6960 | |
| 6961 | ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first); |
| 6962 | if (!getContext().getLangOpts().Modules || !MD->hasBody()) |
| 6963 | MD->setLazyBody(PB->second); |
| 6964 | } |
| 6965 | PendingBodies.clear(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6966 | } |
| 6967 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6968 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 6969 | assert(NumCurrentElementsDeserializing && |
| 6970 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 6971 | if (NumCurrentElementsDeserializing == 1) { |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6972 | // We decrease NumCurrentElementsDeserializing only after pending actions |
| 6973 | // are finished, to avoid recursively re-calling finishPendingActions(). |
| 6974 | finishPendingActions(); |
| 6975 | } |
| 6976 | --NumCurrentElementsDeserializing; |
Argyrios Kyrtzidis | 7116833 | 2011-12-17 04:13:28 +0000 | [diff] [blame] | 6977 | |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6978 | if (NumCurrentElementsDeserializing == 0 && |
| 6979 | Consumer && !PassingDeclsToConsumer) { |
| 6980 | // Guard variable to avoid recursively redoing the process of passing |
| 6981 | // decls to consumer. |
| 6982 | SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer, |
| 6983 | true); |
Argyrios Kyrtzidis | 7116833 | 2011-12-17 04:13:28 +0000 | [diff] [blame] | 6984 | |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6985 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 6986 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 6987 | // decls to the consumer. |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6988 | Decl *D = InterestingDecls.front(); |
| 6989 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6990 | PassInterestingDeclToConsumer(D); |
| 6991 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6992 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6993 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 6994 | |
Douglas Gregor | f8a1e51 | 2011-09-02 00:26:20 +0000 | [diff] [blame] | 6995 | ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 6996 | StringRef isysroot, bool DisableValidation, |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 6997 | bool DisableStatCache, bool AllowASTWithCompilerErrors) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6998 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 6999 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 7000 | Diags(PP.getDiagnostics()), SemaObj(0), PP(PP), Context(Context), |
Argyrios Kyrtzidis | d64c26f | 2012-10-03 01:58:42 +0000 | [diff] [blame] | 7001 | Consumer(0), ModuleMgr(PP.getFileManager()), |
Douglas Gregor | caed060 | 2012-10-18 21:31:35 +0000 | [diff] [blame] | 7002 | isysroot(isysroot), DisableValidation(DisableValidation), |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 7003 | DisableStatCache(DisableStatCache), |
| 7004 | AllowASTWithCompilerErrors(AllowASTWithCompilerErrors), |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 7005 | CurrentGeneration(0), CurrSwitchCaseStmts(&SwitchCaseStmts), |
| 7006 | NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 7007 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 7008 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 7009 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 7010 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 7011 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 7012 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 7013 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 7014 | PassingDeclsToConsumer(false), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 7015 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 7016 | { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 7017 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 7018 | } |
| 7019 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 7020 | ASTReader::~ASTReader() { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 7021 | for (DeclContextVisibleUpdatesPending::iterator |
| 7022 | I = PendingVisibleUpdates.begin(), |
| 7023 | E = PendingVisibleUpdates.end(); |
| 7024 | I != E; ++I) { |
| 7025 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 7026 | F = I->second.end(); |
| 7027 | J != F; ++J) |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 7028 | delete J->first; |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 7029 | } |
| 7030 | } |