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 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 772 | /// \brief Read a source manager block |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 773 | bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 774 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 775 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 776 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 777 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 778 | // Set the source-location entry cursor to the current position in |
| 779 | // the stream. This cursor will be used to read the contents of the |
| 780 | // source manager block initially, and then lazily read |
| 781 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 782 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 783 | |
| 784 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 785 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 786 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 787 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 791 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 792 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 793 | return true; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 794 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 795 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 796 | RecordData Record; |
| 797 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 798 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 799 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 800 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 801 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 802 | return true; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 803 | } |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 804 | return false; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 805 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 806 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 807 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 808 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 809 | SLocEntryCursor.ReadSubBlockID(); |
| 810 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 811 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 812 | return true; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 813 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 814 | continue; |
| 815 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 816 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 817 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 818 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 819 | continue; |
| 820 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 821 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 822 | // Read a record. |
| 823 | const char *BlobStart; |
| 824 | unsigned BlobLen; |
| 825 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 826 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 827 | default: // Default behavior: ignore. |
| 828 | break; |
| 829 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 830 | case SM_SLOC_FILE_ENTRY: |
| 831 | case SM_SLOC_BUFFER_ENTRY: |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 832 | case SM_SLOC_EXPANSION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 833 | // Once we hit one of the source location entries, we're done. |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 834 | return false; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | } |
| 838 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 839 | /// \brief If a header file is not found at the path that we expect it to be |
| 840 | /// and the PCH file was moved from its original location, try to resolve the |
| 841 | /// file by assuming that header+PCH were moved together and the header is in |
| 842 | /// the same place relative to the PCH. |
| 843 | static std::string |
| 844 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 845 | const std::string &OriginalDir, |
| 846 | const std::string &CurrDir) { |
| 847 | assert(OriginalDir != CurrDir && |
| 848 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 849 | using namespace llvm::sys; |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 850 | SmallString<128> filePath(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 851 | fs::make_absolute(filePath); |
| 852 | assert(path::is_absolute(OriginalDir)); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 853 | SmallString<128> currPCHPath(CurrDir); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 854 | |
| 855 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 856 | fileDirE = path::end(path::parent_path(filePath)); |
| 857 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 858 | origDirE = path::end(OriginalDir); |
| 859 | // Skip the common path components from filePath and OriginalDir. |
| 860 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 861 | *fileDirI == *origDirI) { |
| 862 | ++fileDirI; |
| 863 | ++origDirI; |
| 864 | } |
| 865 | for (; origDirI != origDirE; ++origDirI) |
| 866 | path::append(currPCHPath, ".."); |
| 867 | path::append(currPCHPath, fileDirI, fileDirE); |
| 868 | path::append(currPCHPath, path::filename(Filename)); |
| 869 | return currPCHPath.str(); |
| 870 | } |
| 871 | |
Douglas Gregor | 8b53d14 | 2012-10-22 22:53:10 +0000 | [diff] [blame] | 872 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 873 | if (ID == 0) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 874 | return false; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 875 | |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 876 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 877 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 878 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 879 | } |
| 880 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 881 | ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 882 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 883 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 884 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 885 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 886 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 887 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 888 | if (Code == llvm::bitc::END_BLOCK || |
| 889 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 890 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 891 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 892 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 893 | } |
| 894 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 895 | RecordData Record; |
| 896 | const char *BlobStart; |
| 897 | unsigned BlobLen; |
| 898 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 899 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 900 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 901 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 902 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 903 | case SM_SLOC_FILE_ENTRY: { |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 904 | // We will detect whether a file changed and return 'Failure' for it, but |
| 905 | // we will also try to fail gracefully by setting up the SLocEntry. |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 906 | unsigned InputID = Record[4]; |
| 907 | InputFile IF = getInputFile(*F, InputID); |
| 908 | const FileEntry *File = IF.getPointer(); |
| 909 | bool OverriddenBuffer = IF.getInt(); |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 910 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 911 | if (!IF.getPointer()) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 912 | return true; |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 913 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 914 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 915 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 916 | // This is the module's main file. |
| 917 | IncludeLoc = getImportLocation(F); |
| 918 | } |
Argyrios Kyrtzidis | ff39896 | 2012-07-11 20:59:04 +0000 | [diff] [blame] | 919 | SrcMgr::CharacteristicKind |
| 920 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 921 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter, |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 922 | ID, BaseOffset + Record[0]); |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 923 | SrcMgr::FileInfo &FileInfo = |
| 924 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 925 | FileInfo.NumCreatedFIDs = Record[5]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 926 | if (Record[3]) |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 927 | FileInfo.setHasLineDirectives(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 928 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 929 | const DeclID *FirstDecl = F->FileSortedDecls + Record[6]; |
| 930 | unsigned NumFileDecls = Record[7]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 931 | if (NumFileDecls) { |
| 932 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
Argyrios Kyrtzidis | 9d128d0 | 2011-10-31 07:20:08 +0000 | [diff] [blame] | 933 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 934 | NumFileDecls)); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 935 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 936 | |
Douglas Gregor | 35f9ae6 | 2011-11-17 01:44:33 +0000 | [diff] [blame] | 937 | const SrcMgr::ContentCache *ContentCache |
Argyrios Kyrtzidis | ff39896 | 2012-07-11 20:59:04 +0000 | [diff] [blame] | 938 | = SourceMgr.getOrCreateContentCache(File, |
| 939 | /*isSystemFile=*/FileCharacter != SrcMgr::C_User); |
Douglas Gregor | 35f9ae6 | 2011-11-17 01:44:33 +0000 | [diff] [blame] | 940 | if (OverriddenBuffer && !ContentCache->BufferOverridden && |
| 941 | ContentCache->ContentsEntry == ContentCache->OrigEntry) { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 942 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 943 | Record.clear(); |
| 944 | unsigned RecCode |
| 945 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
| 946 | |
| 947 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
| 948 | Error("AST record has invalid code"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 949 | return true; |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | llvm::MemoryBuffer *Buffer |
| 953 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 954 | File->getName()); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 955 | SourceMgr.overrideFileContents(File, Buffer); |
| 956 | } |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 957 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 958 | break; |
| 959 | } |
| 960 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 961 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 962 | const char *Name = BlobStart; |
| 963 | unsigned Offset = Record[0]; |
Argyrios Kyrtzidis | 23de7ce | 2012-11-06 00:35:04 +0000 | [diff] [blame] | 964 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 965 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 966 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 967 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 968 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 969 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 970 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 971 | Error("AST record has invalid code"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 972 | return true; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 973 | } |
| 974 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 975 | llvm::MemoryBuffer *Buffer |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 976 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
| 977 | Name); |
Argyrios Kyrtzidis | 23de7ce | 2012-11-06 00:35:04 +0000 | [diff] [blame] | 978 | SourceMgr.createFileIDForMemBuffer(Buffer, ID, BaseOffset + Offset, |
| 979 | IncludeLoc); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 980 | break; |
| 981 | } |
| 982 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 983 | case SM_SLOC_EXPANSION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 984 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Chandler Carruth | bf340e4 | 2011-07-26 03:03:05 +0000 | [diff] [blame] | 985 | SourceMgr.createExpansionLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 986 | ReadSourceLocation(*F, Record[2]), |
| 987 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 988 | Record[4], |
| 989 | ID, |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 990 | BaseOffset + Record[0]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 991 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 992 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 995 | return false; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 996 | } |
| 997 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 998 | /// \brief Find the location where the module F is imported. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 999 | SourceLocation ASTReader::getImportLocation(ModuleFile *F) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1000 | if (F->ImportLoc.isValid()) |
| 1001 | return F->ImportLoc; |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1002 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1003 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1004 | // location of its includer. |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1005 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1006 | // Main file is the importer. We assume that it is the first entry in the |
| 1007 | // entry table. We can't ask the manager, because at the time of PCH loading |
| 1008 | // the main file entry doesn't exist yet. |
| 1009 | // The very first entry is the invalid instantiation loc, which takes up |
| 1010 | // offsets 0 and 1. |
| 1011 | return SourceLocation::getFromRawEncoding(2U); |
| 1012 | } |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1013 | //return F->Loaders[0]->FirstLoc; |
| 1014 | return F->ImportedBy[0]->FirstLoc; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1017 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1018 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1019 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1020 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1021 | unsigned BlockID) { |
| 1022 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1023 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1024 | return Failure; |
| 1025 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1026 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1027 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1028 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1029 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1030 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1031 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1032 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1033 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1034 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1035 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1036 | Cursor.ReadAbbrevRecord(); |
| 1037 | } |
| 1038 | } |
| 1039 | |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 1040 | void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset, |
| 1041 | MacroInfo *Hint) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1042 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1043 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1044 | // Keep track of where we are in the stream, then jump back there |
| 1045 | // after reading this macro. |
| 1046 | SavedStreamPosition SavedPosition(Stream); |
| 1047 | |
| 1048 | Stream.JumpToBit(Offset); |
| 1049 | RecordData Record; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1050 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1051 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1052 | |
Douglas Gregor | e8219a6 | 2012-10-11 21:07:39 +0000 | [diff] [blame] | 1053 | // RAII object to add the loaded macro information once we're done |
| 1054 | // adding tokens. |
| 1055 | struct AddLoadedMacroInfoRAII { |
| 1056 | Preprocessor &PP; |
| 1057 | MacroInfo *Hint; |
| 1058 | MacroInfo *MI; |
| 1059 | IdentifierInfo *II; |
| 1060 | |
| 1061 | AddLoadedMacroInfoRAII(Preprocessor &PP, MacroInfo *Hint) |
| 1062 | : PP(PP), Hint(Hint), MI(), II() { } |
| 1063 | ~AddLoadedMacroInfoRAII( ) { |
| 1064 | if (MI) { |
| 1065 | // Finally, install the macro. |
| 1066 | PP.addLoadedMacroInfo(II, MI, Hint); |
| 1067 | } |
| 1068 | } |
| 1069 | } AddLoadedMacroInfo(PP, Hint); |
| 1070 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1071 | while (true) { |
| 1072 | unsigned Code = Stream.ReadCode(); |
| 1073 | switch (Code) { |
| 1074 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1075 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1076 | |
| 1077 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1078 | // No known subblocks, always skip them. |
| 1079 | Stream.ReadSubBlockID(); |
| 1080 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1081 | Error("malformed block record in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1082 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1083 | } |
| 1084 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1085 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1086 | case llvm::bitc::DEFINE_ABBREV: |
| 1087 | Stream.ReadAbbrevRecord(); |
| 1088 | continue; |
| 1089 | default: break; |
| 1090 | } |
| 1091 | |
| 1092 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1093 | const char *BlobStart = 0; |
| 1094 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1095 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1096 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1097 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1098 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1099 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1100 | case PP_MACRO_OBJECT_LIKE: |
| 1101 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1102 | // If we already have a macro, that means that we've hit the end |
| 1103 | // of the definition of the macro we were looking for. We're |
| 1104 | // done. |
| 1105 | if (Macro) |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1106 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1107 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1108 | IdentifierInfo *II = getLocalIdentifier(F, Record[0]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1109 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1110 | Error("macro must have a name in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1111 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1112 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1113 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1114 | unsigned GlobalID = getGlobalMacroID(F, Record[1]); |
| 1115 | |
| 1116 | // If this macro has already been loaded, don't do so again. |
| 1117 | if (MacrosLoaded[GlobalID - NUM_PREDEF_MACRO_IDS]) |
| 1118 | return; |
| 1119 | |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1120 | SubmoduleID GlobalSubmoduleID = getGlobalSubmoduleID(F, Record[2]); |
| 1121 | unsigned NextIndex = 3; |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1122 | SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1123 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1124 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1125 | // Record this macro. |
| 1126 | MacrosLoaded[GlobalID - NUM_PREDEF_MACRO_IDS] = MI; |
| 1127 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1128 | SourceLocation UndefLoc = ReadSourceLocation(F, Record, NextIndex); |
| 1129 | if (UndefLoc.isValid()) |
| 1130 | MI->setUndefLoc(UndefLoc); |
| 1131 | |
| 1132 | MI->setIsUsed(Record[NextIndex++]); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1133 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1134 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1135 | bool IsPublic = Record[NextIndex++]; |
Douglas Gregor | aa93a87 | 2011-10-17 15:32:29 +0000 | [diff] [blame] | 1136 | MI->setVisibility(IsPublic, ReadSourceLocation(F, Record, NextIndex)); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1137 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1138 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1139 | // Decode function-like macro info. |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1140 | bool isC99VarArgs = Record[NextIndex++]; |
| 1141 | bool isGNUVarArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1142 | MacroArgs.clear(); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1143 | unsigned NumArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1144 | for (unsigned i = 0; i != NumArgs; ++i) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1145 | MacroArgs.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1146 | |
| 1147 | // Install function-like macro info. |
| 1148 | MI->setIsFunctionLike(); |
| 1149 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1150 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1151 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1152 | PP.getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1153 | } |
| 1154 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1155 | if (DeserializationListener) |
| 1156 | DeserializationListener->MacroRead(GlobalID, MI); |
| 1157 | |
| 1158 | // If an update record marked this as undefined, do so now. |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1159 | // FIXME: Only if the submodule this update came from is visible? |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1160 | MacroUpdatesMap::iterator Update = MacroUpdates.find(GlobalID); |
| 1161 | if (Update != MacroUpdates.end()) { |
| 1162 | if (MI->getUndefLoc().isInvalid()) { |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 1163 | for (unsigned I = 0, N = Update->second.size(); I != N; ++I) { |
| 1164 | bool Hidden = false; |
| 1165 | if (unsigned SubmoduleID = Update->second[I].first) { |
| 1166 | if (Module *Owner = getSubmodule(SubmoduleID)) { |
| 1167 | if (Owner->NameVisibility == Module::Hidden) { |
| 1168 | // Note that this #undef is hidden. |
| 1169 | Hidden = true; |
| 1170 | |
| 1171 | // Record this hiding for later. |
| 1172 | HiddenNamesMap[Owner].push_back( |
| 1173 | HiddenName(II, MI, Update->second[I].second.UndefLoc)); |
| 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | if (!Hidden) { |
| 1179 | MI->setUndefLoc(Update->second[I].second.UndefLoc); |
| 1180 | if (PPMutationListener *Listener = PP.getPPMutationListener()) |
| 1181 | Listener->UndefinedMacro(MI); |
| 1182 | break; |
| 1183 | } |
| 1184 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1185 | } |
| 1186 | MacroUpdates.erase(Update); |
| 1187 | } |
| 1188 | |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1189 | // Determine whether this macro definition is visible. |
| 1190 | bool Hidden = !MI->isPublic(); |
| 1191 | if (!Hidden && GlobalSubmoduleID) { |
| 1192 | if (Module *Owner = getSubmodule(GlobalSubmoduleID)) { |
| 1193 | if (Owner->NameVisibility == Module::Hidden) { |
| 1194 | // The owning module is not visible, and this macro definition |
| 1195 | // should not be, either. |
| 1196 | Hidden = true; |
| 1197 | |
| 1198 | // Note that this macro definition was hidden because its owning |
| 1199 | // module is not yet visible. |
| 1200 | HiddenNamesMap[Owner].push_back(HiddenName(II, MI)); |
| 1201 | } |
| 1202 | } |
| 1203 | } |
| 1204 | MI->setHidden(Hidden); |
| 1205 | |
Douglas Gregor | e8219a6 | 2012-10-11 21:07:39 +0000 | [diff] [blame] | 1206 | // Make sure we install the macro once we're done. |
| 1207 | AddLoadedMacroInfo.MI = MI; |
| 1208 | AddLoadedMacroInfo.II = II; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1209 | |
| 1210 | // Remember that we saw this macro last so that we add the tokens that |
| 1211 | // form its body to it. |
| 1212 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1213 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1214 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1215 | Record[NextIndex]) { |
| 1216 | // We have a macro definition. Register the association |
| 1217 | PreprocessedEntityID |
| 1218 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1219 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 1220 | PPRec.RegisterMacroDefinition(Macro, |
| 1221 | PPRec.getPPEntityID(GlobalID-1, /*isLoaded=*/true)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1222 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1223 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1224 | ++NumMacrosRead; |
| 1225 | break; |
| 1226 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1227 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1228 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1229 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1230 | // erroneous, just pretend we didn't see this. |
| 1231 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1232 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1233 | Token Tok; |
| 1234 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1235 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1236 | Tok.setLength(Record[1]); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1237 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[2])) |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1238 | Tok.setIdentifierInfo(II); |
| 1239 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1240 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1241 | Macro->AddTokenToBody(Tok); |
| 1242 | break; |
| 1243 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 1244 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1245 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1248 | PreprocessedEntityID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1249 | ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const { |
Argyrios Kyrtzidis | 1f6d225 | 2011-09-19 20:40:02 +0000 | [diff] [blame] | 1250 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1251 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1252 | assert(I != M.PreprocessedEntityRemap.end() |
| 1253 | && "Invalid index into preprocessed entity index remap"); |
| 1254 | |
| 1255 | return LocalID + I->second; |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1258 | unsigned HeaderFileInfoTrait::ComputeHash(const char *path) { |
| 1259 | return llvm::HashString(llvm::sys::path::filename(path)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1260 | } |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1261 | |
| 1262 | HeaderFileInfoTrait::internal_key_type |
| 1263 | HeaderFileInfoTrait::GetInternalKey(const char *path) { return path; } |
| 1264 | |
| 1265 | bool HeaderFileInfoTrait::EqualKey(internal_key_type a, internal_key_type b) { |
| 1266 | if (strcmp(a, b) == 0) |
| 1267 | return true; |
| 1268 | |
| 1269 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1270 | return false; |
Douglas Gregor | 99a922b | 2011-12-09 16:22:07 +0000 | [diff] [blame] | 1271 | |
| 1272 | // Determine whether the actual files are equivalent. |
| 1273 | bool Result = false; |
| 1274 | if (llvm::sys::fs::equivalent(a, b, Result)) |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1275 | return false; |
| 1276 | |
Douglas Gregor | 99a922b | 2011-12-09 16:22:07 +0000 | [diff] [blame] | 1277 | return Result; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | std::pair<unsigned, unsigned> |
| 1281 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 1282 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1283 | unsigned DataLen = (unsigned) *d++; |
| 1284 | return std::make_pair(KeyLen + 1, DataLen); |
| 1285 | } |
| 1286 | |
| 1287 | HeaderFileInfoTrait::data_type |
| 1288 | HeaderFileInfoTrait::ReadData(const internal_key_type, const unsigned char *d, |
| 1289 | unsigned DataLen) { |
| 1290 | const unsigned char *End = d + DataLen; |
| 1291 | using namespace clang::io; |
| 1292 | HeaderFileInfo HFI; |
| 1293 | unsigned Flags = *d++; |
| 1294 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1295 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1296 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1297 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1298 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
| 1299 | HFI.NumIncludes = ReadUnalignedLE16(d); |
Douglas Gregor | 541ba16 | 2011-10-17 18:53:12 +0000 | [diff] [blame] | 1300 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID(M, |
| 1301 | ReadUnalignedLE32(d)); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1302 | if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { |
| 1303 | // The framework offset is 1 greater than the actual offset, |
| 1304 | // since 0 is used as an indicator for "no framework name". |
| 1305 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1306 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1307 | } |
| 1308 | |
| 1309 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1310 | (void)End; |
| 1311 | |
| 1312 | // This HeaderFileInfo was externally loaded. |
| 1313 | HFI.External = true; |
| 1314 | return HFI; |
| 1315 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1316 | |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1317 | void ASTReader::setIdentifierIsMacro(IdentifierInfo *II, ArrayRef<MacroID> IDs){ |
| 1318 | II->setHadMacroDefinition(true); |
| 1319 | assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard"); |
| 1320 | PendingMacroIDs[II].append(IDs.begin(), IDs.end()); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1323 | void ASTReader::ReadDefinedMacros() { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1324 | // Note that we are loading defined macros. |
| 1325 | Deserializing Macros(this); |
| 1326 | |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1327 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1328 | E = ModuleMgr.rend(); I != E; ++I) { |
| 1329 | llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1330 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1331 | // If there was no preprocessor block, skip this file. |
| 1332 | if (!MacroCursor.getBitStreamReader()) |
| 1333 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1334 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1335 | llvm::BitstreamCursor Cursor = MacroCursor; |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1336 | Cursor.JumpToBit((*I)->MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1337 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1338 | RecordData Record; |
| 1339 | while (true) { |
| 1340 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1341 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1342 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1343 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1344 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1345 | // No known subblocks, always skip them. |
| 1346 | Cursor.ReadSubBlockID(); |
| 1347 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1348 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1349 | return; |
| 1350 | } |
| 1351 | continue; |
| 1352 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1353 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1354 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1355 | Cursor.ReadAbbrevRecord(); |
| 1356 | continue; |
| 1357 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1358 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1359 | // Read a record. |
| 1360 | const char *BlobStart; |
| 1361 | unsigned BlobLen; |
| 1362 | Record.clear(); |
| 1363 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1364 | default: // Default behavior: ignore. |
| 1365 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1366 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1367 | case PP_MACRO_OBJECT_LIKE: |
| 1368 | case PP_MACRO_FUNCTION_LIKE: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1369 | getLocalIdentifier(**I, Record[0]); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1370 | break; |
| 1371 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1372 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1373 | // Ignore tokens. |
| 1374 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1375 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1376 | } |
| 1377 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1380 | namespace { |
| 1381 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 1382 | class IdentifierLookupVisitor { |
| 1383 | StringRef Name; |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1384 | unsigned PriorGeneration; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1385 | IdentifierInfo *Found; |
| 1386 | public: |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1387 | IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration) |
| 1388 | : Name(Name), PriorGeneration(PriorGeneration), Found() { } |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1389 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1390 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1391 | IdentifierLookupVisitor *This |
| 1392 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 1393 | |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1394 | // If we've already searched this module file, skip it now. |
| 1395 | if (M.Generation <= This->PriorGeneration) |
| 1396 | return true; |
| 1397 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1398 | ASTIdentifierLookupTable *IdTable |
| 1399 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 1400 | if (!IdTable) |
| 1401 | return false; |
| 1402 | |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1403 | ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), |
| 1404 | M, This->Found); |
| 1405 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1406 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 1407 | This->Name.size()); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1408 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Trait); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1409 | if (Pos == IdTable->end()) |
| 1410 | return false; |
| 1411 | |
| 1412 | // Dereferencing the iterator has the effect of building the |
| 1413 | // IdentifierInfo node and populating it with the various |
| 1414 | // declarations it needs. |
| 1415 | This->Found = *Pos; |
| 1416 | return true; |
| 1417 | } |
| 1418 | |
| 1419 | // \brief Retrieve the identifier info found within the module |
| 1420 | // files. |
| 1421 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 1422 | }; |
| 1423 | } |
| 1424 | |
| 1425 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1426 | // Note that we are loading an identifier. |
| 1427 | Deserializing AnIdentifier(this); |
| 1428 | |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1429 | unsigned PriorGeneration = 0; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1430 | if (getContext().getLangOpts().Modules) |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1431 | PriorGeneration = IdentifierGeneration[&II]; |
| 1432 | |
| 1433 | IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration); |
| 1434 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
| 1435 | markIdentifierUpToDate(&II); |
| 1436 | } |
| 1437 | |
| 1438 | void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { |
| 1439 | if (!II) |
| 1440 | return; |
| 1441 | |
| 1442 | II->setOutOfDate(false); |
| 1443 | |
| 1444 | // Update the generation for this identifier. |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1445 | if (getContext().getLangOpts().Modules) |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1446 | IdentifierGeneration[II] = CurrentGeneration; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1449 | llvm::PointerIntPair<const FileEntry *, 1, bool> |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1450 | ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1451 | // If this ID is bogus, just return an empty input file. |
| 1452 | if (ID == 0 || ID > F.InputFilesLoaded.size()) |
| 1453 | return InputFile(); |
| 1454 | |
| 1455 | // If we've already loaded this input file, return it. |
| 1456 | if (F.InputFilesLoaded[ID-1].getPointer()) |
| 1457 | return F.InputFilesLoaded[ID-1]; |
| 1458 | |
| 1459 | // Go find this input file. |
| 1460 | llvm::BitstreamCursor &Cursor = F.InputFilesCursor; |
| 1461 | SavedStreamPosition SavedPosition(Cursor); |
| 1462 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
| 1463 | |
| 1464 | unsigned Code = Cursor.ReadCode(); |
| 1465 | RecordData Record; |
| 1466 | const char *BlobStart = 0; |
| 1467 | unsigned BlobLen = 0; |
| 1468 | switch ((InputFileRecordTypes)Cursor.ReadRecord(Code, Record, |
| 1469 | &BlobStart, &BlobLen)) { |
| 1470 | case INPUT_FILE: { |
| 1471 | unsigned StoredID = Record[0]; |
| 1472 | assert(ID == StoredID && "Bogus stored ID or offset"); |
NAKAMURA Takumi | 6b8194e | 2012-10-22 21:50:39 +0000 | [diff] [blame] | 1473 | (void)StoredID; |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1474 | off_t StoredSize = (off_t)Record[1]; |
| 1475 | time_t StoredTime = (time_t)Record[2]; |
| 1476 | bool Overridden = (bool)Record[3]; |
| 1477 | |
| 1478 | // Get the file entry for this input file. |
| 1479 | StringRef OrigFilename(BlobStart, BlobLen); |
| 1480 | std::string Filename = OrigFilename; |
| 1481 | MaybeAddSystemRootToFilename(F, Filename); |
| 1482 | const FileEntry *File |
| 1483 | = Overridden? FileMgr.getVirtualFile(Filename, StoredSize, StoredTime) |
| 1484 | : FileMgr.getFile(Filename, /*OpenFile=*/false); |
| 1485 | |
| 1486 | // If we didn't find the file, resolve it relative to the |
| 1487 | // original directory from which this AST file was created. |
| 1488 | if (File == 0 && !F.OriginalDir.empty() && !CurrentDir.empty() && |
| 1489 | F.OriginalDir != CurrentDir) { |
| 1490 | std::string Resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1491 | F.OriginalDir, |
| 1492 | CurrentDir); |
| 1493 | if (!Resolved.empty()) |
| 1494 | File = FileMgr.getFile(Resolved); |
| 1495 | } |
| 1496 | |
| 1497 | // For an overridden file, create a virtual file with the stored |
| 1498 | // size/timestamp. |
| 1499 | if (Overridden && File == 0) { |
| 1500 | File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime); |
| 1501 | } |
| 1502 | |
| 1503 | if (File == 0) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1504 | if (Complain) { |
| 1505 | std::string ErrorStr = "could not find file '"; |
| 1506 | ErrorStr += Filename; |
| 1507 | ErrorStr += "' referenced by AST file"; |
| 1508 | Error(ErrorStr.c_str()); |
| 1509 | } |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1510 | return InputFile(); |
| 1511 | } |
| 1512 | |
| 1513 | // Note that we've loaded this input file. |
| 1514 | F.InputFilesLoaded[ID-1] = InputFile(File, Overridden); |
| 1515 | |
| 1516 | // Check if there was a request to override the contents of the file |
| 1517 | // that was part of the precompiled header. Overridding such a file |
| 1518 | // can lead to problems when lexing using the source locations from the |
| 1519 | // PCH. |
| 1520 | SourceManager &SM = getSourceManager(); |
| 1521 | if (!Overridden && SM.isFileOverridden(File)) { |
| 1522 | Error(diag::err_fe_pch_file_overridden, Filename); |
| 1523 | // After emitting the diagnostic, recover by disabling the override so |
| 1524 | // that the original file will be used. |
| 1525 | SM.disableFileContentsOverride(File); |
| 1526 | // The FileEntry is a virtual file entry with the size of the contents |
| 1527 | // that would override the original contents. Set it to the original's |
| 1528 | // size/time. |
| 1529 | FileMgr.modifyFileEntry(const_cast<FileEntry*>(File), |
| 1530 | StoredSize, StoredTime); |
| 1531 | } |
| 1532 | |
| 1533 | // For an overridden file, there is nothing to validate. |
| 1534 | if (Overridden) |
| 1535 | return InputFile(File, Overridden); |
| 1536 | |
| 1537 | // The stat info from the FileEntry came from the cached stat |
| 1538 | // info of the PCH, so we cannot trust it. |
| 1539 | struct stat StatBuf; |
| 1540 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 1541 | StatBuf.st_size = File->getSize(); |
| 1542 | StatBuf.st_mtime = File->getModificationTime(); |
| 1543 | } |
| 1544 | |
| 1545 | if ((StoredSize != StatBuf.st_size |
| 1546 | #if !defined(LLVM_ON_WIN32) |
| 1547 | // In our regression testing, the Windows file system seems to |
| 1548 | // have inconsistent modification times that sometimes |
| 1549 | // erroneously trigger this error-handling path. |
| 1550 | || StoredTime != StatBuf.st_mtime |
| 1551 | #endif |
| 1552 | )) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1553 | if (Complain) |
| 1554 | Error(diag::err_fe_pch_file_modified, Filename); |
| 1555 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1556 | return InputFile(); |
| 1557 | } |
| 1558 | |
| 1559 | return InputFile(File, Overridden); |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | return InputFile(); |
| 1564 | } |
| 1565 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1566 | const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1567 | ModuleFile &M = ModuleMgr.getPrimaryModule(); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1568 | std::string Filename = filenameStrRef; |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1569 | MaybeAddSystemRootToFilename(M, Filename); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1570 | const FileEntry *File = FileMgr.getFile(Filename); |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1571 | if (File == 0 && !M.OriginalDir.empty() && !CurrentDir.empty() && |
| 1572 | M.OriginalDir != CurrentDir) { |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1573 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1574 | M.OriginalDir, |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1575 | CurrentDir); |
| 1576 | if (!resolved.empty()) |
| 1577 | File = FileMgr.getFile(resolved); |
| 1578 | } |
| 1579 | |
| 1580 | return File; |
| 1581 | } |
| 1582 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1583 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1584 | /// not an absolute path, add the system root to the beginning of the file |
| 1585 | /// name. |
Rafael Espindola | 848bc3a | 2012-10-30 00:38:13 +0000 | [diff] [blame] | 1586 | void ASTReader::MaybeAddSystemRootToFilename(ModuleFile &M, |
| 1587 | std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1588 | // 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] | 1589 | if (!M.RelocatablePCH) |
Rafael Espindola | 848bc3a | 2012-10-30 00:38:13 +0000 | [diff] [blame] | 1590 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1591 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1592 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Rafael Espindola | 848bc3a | 2012-10-30 00:38:13 +0000 | [diff] [blame] | 1593 | return; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1594 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1595 | if (isysroot.empty()) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1596 | // If no system root was given, default to '/' |
| 1597 | Filename.insert(Filename.begin(), '/'); |
Rafael Espindola | 848bc3a | 2012-10-30 00:38:13 +0000 | [diff] [blame] | 1598 | return; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1599 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1600 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1601 | unsigned Length = isysroot.size(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1602 | if (isysroot[Length - 1] != '/') |
| 1603 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1604 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1605 | Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end()); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1608 | ASTReader::ASTReadResult |
| 1609 | ASTReader::ReadControlBlock(ModuleFile &F, |
| 1610 | llvm::SmallVectorImpl<ModuleFile *> &Loaded, |
| 1611 | unsigned ClientLoadCapabilities) { |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1612 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1613 | |
| 1614 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
| 1615 | Error("malformed block record in AST file"); |
| 1616 | return Failure; |
| 1617 | } |
| 1618 | |
| 1619 | // Read all of the records and blocks in the control block. |
| 1620 | RecordData Record; |
| 1621 | while (!Stream.AtEndOfStream()) { |
| 1622 | unsigned Code = Stream.ReadCode(); |
| 1623 | if (Code == llvm::bitc::END_BLOCK) { |
| 1624 | if (Stream.ReadBlockEnd()) { |
| 1625 | Error("error at end of control block in AST file"); |
| 1626 | return Failure; |
| 1627 | } |
| 1628 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1629 | // Validate all of the input files. |
| 1630 | if (!DisableValidation) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1631 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1632 | for (unsigned I = 0, N = Record[0]; I < N; ++I) |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1633 | if (!getInputFile(F, I+1, Complain).getPointer()) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1634 | return OutOfDate; |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1637 | return Success; |
| 1638 | } |
| 1639 | |
| 1640 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1641 | switch (Stream.ReadSubBlockID()) { |
| 1642 | case INPUT_FILES_BLOCK_ID: |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1643 | F.InputFilesCursor = Stream; |
| 1644 | if (Stream.SkipBlock() || // Skip with the main cursor |
| 1645 | // Read the abbreviations |
| 1646 | ReadBlockAbbrevs(F.InputFilesCursor, INPUT_FILES_BLOCK_ID)) { |
| 1647 | Error("malformed block record in AST file"); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1648 | return Failure; |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1649 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1650 | continue; |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1651 | |
| 1652 | default: |
| 1653 | if (!Stream.SkipBlock()) |
| 1654 | continue; |
| 1655 | break; |
| 1656 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1657 | |
| 1658 | Error("malformed block record in AST file"); |
| 1659 | return Failure; |
| 1660 | } |
| 1661 | |
| 1662 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1663 | Stream.ReadAbbrevRecord(); |
| 1664 | continue; |
| 1665 | } |
| 1666 | |
| 1667 | // Read and process a record. |
| 1668 | Record.clear(); |
| 1669 | const char *BlobStart = 0; |
| 1670 | unsigned BlobLen = 0; |
| 1671 | switch ((ControlRecordTypes)Stream.ReadRecord(Code, Record, |
| 1672 | &BlobStart, &BlobLen)) { |
| 1673 | case METADATA: { |
| 1674 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1675 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
| 1676 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
| 1677 | : diag::warn_pch_version_too_new); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1678 | return VersionMismatch; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | bool hasErrors = Record[5]; |
| 1682 | if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) { |
| 1683 | Diag(diag::err_pch_with_compiler_errors); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1684 | return HadErrors; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
Douglas Gregor | caed060 | 2012-10-18 21:31:35 +0000 | [diff] [blame] | 1687 | F.RelocatablePCH = Record[4]; |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1688 | |
| 1689 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
| 1690 | StringRef ASTBranch(BlobStart, BlobLen); |
| 1691 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1692 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
| 1693 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1694 | return VersionMismatch; |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1695 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1696 | break; |
| 1697 | } |
| 1698 | |
| 1699 | case IMPORTS: { |
| 1700 | // Load each of the imported PCH files. |
| 1701 | unsigned Idx = 0, N = Record.size(); |
| 1702 | while (Idx < N) { |
| 1703 | // Read information about the AST file. |
| 1704 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 1705 | unsigned Length = Record[Idx++]; |
| 1706 | SmallString<128> ImportedFile(Record.begin() + Idx, |
| 1707 | Record.begin() + Idx + Length); |
| 1708 | Idx += Length; |
| 1709 | |
| 1710 | // Load the AST file. |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1711 | switch(ReadASTCore(ImportedFile, ImportedKind, &F, Loaded, |
| 1712 | ClientLoadCapabilities)) { |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1713 | case Failure: return Failure; |
| 1714 | // 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] | 1715 | case OutOfDate: return OutOfDate; |
| 1716 | case VersionMismatch: return VersionMismatch; |
| 1717 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 1718 | case HadErrors: return HadErrors; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1719 | case Success: break; |
| 1720 | } |
| 1721 | } |
| 1722 | break; |
| 1723 | } |
| 1724 | |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1725 | case LANGUAGE_OPTIONS: { |
| 1726 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 1727 | if (Listener && &F == *ModuleMgr.begin() && |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 1728 | ParseLanguageOptions(Record, Complain, *Listener) && |
| 1729 | !DisableValidation) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1730 | return ConfigurationMismatch; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1731 | break; |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 1732 | } |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1733 | |
Douglas Gregor | ee097c1 | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1734 | case TARGET_OPTIONS: { |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 1735 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 1736 | if (Listener && &F == *ModuleMgr.begin() && |
| 1737 | ParseTargetOptions(Record, Complain, *Listener) && |
| 1738 | !DisableValidation) |
| 1739 | return ConfigurationMismatch; |
Douglas Gregor | ee097c1 | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1740 | break; |
| 1741 | } |
| 1742 | |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1743 | case DIAGNOSTIC_OPTIONS: { |
| 1744 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 1745 | if (Listener && &F == *ModuleMgr.begin() && |
| 1746 | ParseDiagnosticOptions(Record, Complain, *Listener) && |
| 1747 | !DisableValidation) |
| 1748 | return ConfigurationMismatch; |
| 1749 | break; |
| 1750 | } |
Douglas Gregor | 1b2c3c0 | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1751 | |
| 1752 | case FILE_SYSTEM_OPTIONS: { |
| 1753 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 1754 | if (Listener && &F == *ModuleMgr.begin() && |
| 1755 | ParseFileSystemOptions(Record, Complain, *Listener) && |
| 1756 | !DisableValidation) |
| 1757 | return ConfigurationMismatch; |
| 1758 | break; |
| 1759 | } |
| 1760 | |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1761 | case HEADER_SEARCH_OPTIONS: { |
| 1762 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 1763 | if (Listener && &F == *ModuleMgr.begin() && |
| 1764 | ParseHeaderSearchOptions(Record, Complain, *Listener) && |
| 1765 | !DisableValidation) |
| 1766 | return ConfigurationMismatch; |
| 1767 | break; |
| 1768 | } |
| 1769 | |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1770 | case PREPROCESSOR_OPTIONS: { |
| 1771 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 1772 | if (Listener && &F == *ModuleMgr.begin() && |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 1773 | ParsePreprocessorOptions(Record, Complain, *Listener, |
| 1774 | SuggestedPredefines) && |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1775 | !DisableValidation) |
| 1776 | return ConfigurationMismatch; |
| 1777 | break; |
| 1778 | } |
| 1779 | |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1780 | case ORIGINAL_FILE: |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1781 | F.OriginalSourceFileID = FileID::get(Record[0]); |
| 1782 | F.ActualOriginalSourceFileName.assign(BlobStart, BlobLen); |
| 1783 | F.OriginalSourceFileName = F.ActualOriginalSourceFileName; |
| 1784 | MaybeAddSystemRootToFilename(F, F.OriginalSourceFileName); |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1785 | break; |
| 1786 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1787 | case ORIGINAL_PCH_DIR: |
Douglas Gregor | 69e1608 | 2012-10-18 21:47:16 +0000 | [diff] [blame] | 1788 | F.OriginalDir.assign(BlobStart, BlobLen); |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1789 | break; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1790 | |
Douglas Gregor | a930dc9 | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1791 | case INPUT_FILE_OFFSETS: |
| 1792 | F.InputFileOffsets = (const uint32_t *)BlobStart; |
| 1793 | F.InputFilesLoaded.resize(Record[0]); |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1794 | break; |
| 1795 | } |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | Error("premature end of bitstream in AST file"); |
| 1799 | return Failure; |
| 1800 | } |
| 1801 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1802 | bool ASTReader::ReadASTBlock(ModuleFile &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1803 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1804 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1805 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1806 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1807 | return true; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1808 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1809 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1810 | // Read all of the records and blocks for the AST file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1811 | RecordData Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1812 | while (!Stream.AtEndOfStream()) { |
| 1813 | unsigned Code = Stream.ReadCode(); |
| 1814 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1815 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1816 | Error("error at end of module block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1817 | return true; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1818 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1819 | |
Argyrios Kyrtzidis | 1f94124 | 2012-09-21 01:30:00 +0000 | [diff] [blame] | 1820 | DeclContext *DC = Context.getTranslationUnitDecl(); |
| 1821 | if (!DC->hasExternalVisibleStorage() && DC->hasExternalLexicalStorage()) |
| 1822 | DC->setMustBuildLookupTable(); |
| 1823 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1824 | return false; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1828 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1829 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1830 | // We lazily load the decls block, but we want to set up the |
| 1831 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1832 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1833 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1834 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1835 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1836 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1837 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1838 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1839 | return true; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1840 | } |
| 1841 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1842 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1843 | case DECL_UPDATES_BLOCK_ID: |
| 1844 | if (Stream.SkipBlock()) { |
| 1845 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1846 | return true; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1847 | } |
| 1848 | break; |
| 1849 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1850 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1851 | F.MacroCursor = Stream; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1852 | if (!PP.getExternalSource()) |
| 1853 | PP.setExternalSource(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1854 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1855 | if (Stream.SkipBlock() || |
| 1856 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1857 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1858 | return true; |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1859 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1860 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1861 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1862 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1863 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1864 | F.PreprocessorDetailCursor = Stream; |
| 1865 | if (Stream.SkipBlock() || |
| 1866 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1867 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1868 | Error("malformed preprocessor detail record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1869 | return true; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1870 | } |
| 1871 | F.PreprocessorDetailStartOffset |
| 1872 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1873 | |
| 1874 | if (!PP.getPreprocessingRecord()) |
Argyrios Kyrtzidis | c6c5452 | 2012-03-05 05:48:17 +0000 | [diff] [blame] | 1875 | PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1876 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 1877 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1878 | break; |
| 1879 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1880 | case SOURCE_MANAGER_BLOCK_ID: |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1881 | if (ReadSourceManagerBlock(F)) |
| 1882 | return true; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1883 | break; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1884 | |
| 1885 | case SUBMODULE_BLOCK_ID: |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1886 | if (ReadSubmoduleBlock(F)) |
| 1887 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1888 | break; |
| 1889 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 1890 | case COMMENTS_BLOCK_ID: { |
| 1891 | llvm::BitstreamCursor C = Stream; |
| 1892 | if (Stream.SkipBlock() || |
| 1893 | ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) { |
| 1894 | Error("malformed comments block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1895 | return true; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 1896 | } |
| 1897 | CommentsCursors.push_back(std::make_pair(C, &F)); |
| 1898 | break; |
| 1899 | } |
| 1900 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1901 | default: |
| 1902 | if (!Stream.SkipBlock()) |
| 1903 | break; |
| 1904 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1905 | return true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1906 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1907 | continue; |
| 1908 | } |
| 1909 | |
| 1910 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1911 | Stream.ReadAbbrevRecord(); |
| 1912 | continue; |
| 1913 | } |
| 1914 | |
| 1915 | // Read and process a record. |
| 1916 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1917 | const char *BlobStart = 0; |
| 1918 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1919 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1920 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1921 | default: // Default behavior: ignore. |
| 1922 | break; |
| 1923 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1924 | case TYPE_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1925 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1926 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1927 | return true; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1928 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1929 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1930 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1931 | unsigned LocalBaseTypeIndex = Record[1]; |
| 1932 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 1933 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1934 | if (F.LocalNumTypes > 0) { |
| 1935 | // Introduce the global -> local mapping for types within this module. |
| 1936 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 1937 | |
| 1938 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 1939 | F.TypeRemap.insertOrReplace( |
| 1940 | std::make_pair(LocalBaseTypeIndex, |
| 1941 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1942 | |
| 1943 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 1944 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1945 | break; |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1948 | case DECL_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1949 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1950 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 1951 | return true; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1952 | } |
Argyrios Kyrtzidis | 9d31fa7 | 2011-10-27 18:47:35 +0000 | [diff] [blame] | 1953 | F.DeclOffsets = (const DeclOffset *)BlobStart; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1954 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1955 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1956 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 96e973f | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 1957 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1958 | if (F.LocalNumDecls > 0) { |
| 1959 | // Introduce the global -> local mapping for declarations within this |
| 1960 | // module. |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1961 | GlobalDeclMap.insert( |
| 1962 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1963 | |
| 1964 | // Introduce the local -> global mapping for declarations within this |
| 1965 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 1966 | F.DeclRemap.insertOrReplace( |
| 1967 | std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1968 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 1969 | // Introduce the global -> local mapping for declarations within this |
| 1970 | // module. |
| 1971 | F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID; |
| 1972 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1973 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 1974 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1975 | break; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1976 | } |
| 1977 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1978 | case TU_UPDATE_LEXICAL: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1979 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1980 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
| 1981 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); |
| 1982 | Info.NumLexicalDecls |
| 1983 | = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1984 | TU->setHasExternalLexicalStorage(true); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1985 | break; |
| 1986 | } |
| 1987 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1988 | case UPDATE_VISIBLE: { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1989 | unsigned Idx = 0; |
| 1990 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 1991 | ASTDeclContextNameLookupTable *Table = |
| 1992 | ASTDeclContextNameLookupTable::Create( |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1993 | (const unsigned char *)BlobStart + Record[Idx++], |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1994 | (const unsigned char *)BlobStart, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1995 | ASTDeclContextNameLookupTrait(*this, F)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1996 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID) { // Is it the TU? |
| 1997 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1998 | F.DeclContextInfos[TU].NameLookupTableData = Table; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1999 | TU->setHasExternalVisibleStorage(true); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2000 | } else |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2001 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2002 | break; |
| 2003 | } |
| 2004 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2005 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2006 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2007 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2008 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2009 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2010 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2011 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2012 | ASTIdentifierLookupTrait(*this, F)); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2013 | |
| 2014 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2015 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2016 | break; |
| 2017 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2018 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2019 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2020 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2021 | return true; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2022 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2023 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2024 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2025 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2026 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 2027 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2028 | if (F.LocalNumIdentifiers > 0) { |
| 2029 | // Introduce the global -> local mapping for identifiers within this |
| 2030 | // module. |
| 2031 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 2032 | &F)); |
| 2033 | |
| 2034 | // Introduce the local -> global mapping for identifiers within this |
| 2035 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2036 | F.IdentifierRemap.insertOrReplace( |
| 2037 | std::make_pair(LocalBaseIdentifierID, |
| 2038 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2039 | |
| 2040 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2041 | + F.LocalNumIdentifiers); |
| 2042 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2043 | break; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2044 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2045 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2046 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2047 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2048 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2049 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2050 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2051 | case SPECIAL_TYPES: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 2052 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2053 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2054 | break; |
| 2055 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2056 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2057 | TotalNumStatements += Record[0]; |
| 2058 | TotalNumMacros += Record[1]; |
| 2059 | TotalLexicalDeclContexts += Record[2]; |
| 2060 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2061 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2062 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2063 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2064 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2065 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2066 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2067 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2068 | case DELEGATING_CTORS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2069 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2070 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2071 | break; |
| 2072 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2073 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 2074 | if (Record.size() % 4 != 0) { |
| 2075 | Error("invalid weak identifiers record"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2076 | return true; |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 2080 | // files. This isn't the way to do it :) |
| 2081 | WeakUndeclaredIdentifiers.clear(); |
| 2082 | |
| 2083 | // Translate the weak, undeclared identifiers into global IDs. |
| 2084 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2085 | WeakUndeclaredIdentifiers.push_back( |
| 2086 | getGlobalIdentifierID(F, Record[I++])); |
| 2087 | WeakUndeclaredIdentifiers.push_back( |
| 2088 | getGlobalIdentifierID(F, Record[I++])); |
| 2089 | WeakUndeclaredIdentifiers.push_back( |
| 2090 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2091 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2092 | } |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2093 | break; |
| 2094 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2095 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2096 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2097 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2098 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2099 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2100 | case SELECTOR_OFFSETS: { |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2101 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2102 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2103 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2104 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 2105 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2106 | if (F.LocalNumSelectors > 0) { |
| 2107 | // Introduce the global -> local mapping for selectors within this |
| 2108 | // module. |
| 2109 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 2110 | |
| 2111 | // Introduce the local -> global mapping for selectors within this |
| 2112 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2113 | F.SelectorRemap.insertOrReplace( |
| 2114 | std::make_pair(LocalBaseSelectorID, |
| 2115 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2116 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2117 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 2118 | } |
| 2119 | break; |
| 2120 | } |
| 2121 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2122 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2123 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2124 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2125 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2126 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2127 | F.SelectorLookupTableData + Record[0], |
| 2128 | F.SelectorLookupTableData, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2129 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2130 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2131 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2132 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2133 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 2134 | if (!Record.empty()) { |
| 2135 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2136 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 2137 | Record[Idx++])); |
| 2138 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2139 | getRawEncoding()); |
| 2140 | } |
| 2141 | } |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2142 | break; |
| 2143 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2144 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2145 | if (!Record.empty() && Listener) |
Argyrios Kyrtzidis | 62288ed | 2012-10-10 02:12:47 +0000 | [diff] [blame] | 2146 | Listener->ReadCounter(F, Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2147 | break; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2148 | |
| 2149 | case FILE_SORTED_DECLS: |
| 2150 | F.FileSortedDecls = (const DeclID *)BlobStart; |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2151 | F.NumFileSortedDecls = Record[0]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2152 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2153 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2154 | case SOURCE_LOCATION_OFFSETS: { |
| 2155 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2156 | F.LocalNumSLocEntries = Record[0]; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2157 | unsigned SLocSpaceSize = Record[1]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2158 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2159 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
| 2160 | SLocSpaceSize); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2161 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2162 | // we invert it. Because we invert it, though, we need the other end of |
| 2163 | // the range. |
| 2164 | unsigned RangeStart = |
| 2165 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2166 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2167 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2168 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2169 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 2170 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 2171 | GlobalSLocOffsetMap.insert( |
| 2172 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 2173 | - SLocSpaceSize,&F)); |
| 2174 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2175 | // Initialize the remapping table. |
| 2176 | // Invalid stays invalid. |
| 2177 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2178 | // This module. Base was 2 when being compiled. |
| 2179 | F.SLocRemap.insert(std::make_pair(2U, |
| 2180 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2181 | |
| 2182 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2183 | break; |
| 2184 | } |
| 2185 | |
Douglas Gregor | 5d51a1d | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 2186 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2187 | // Additional remapping information. |
| 2188 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2189 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2190 | |
| 2191 | // Continuous range maps we may be updating in our module. |
| 2192 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2193 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2194 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2195 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2196 | MacroRemap(F.MacroRemap); |
| 2197 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2198 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2199 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2200 | SubmoduleRemap(F.SubmoduleRemap); |
| 2201 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2202 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2203 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2204 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 2205 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2206 | while(Data < DataEnd) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2207 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2208 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2209 | Data += Len; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2210 | ModuleFile *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2211 | if (!OM) { |
| 2212 | Error("SourceLocation remap refers to unknown module"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2213 | return true; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2214 | } |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2215 | |
| 2216 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 2217 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2218 | uint32_t MacroIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2219 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2220 | uint32_t SubmoduleIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2221 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 2222 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2223 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2224 | |
| 2225 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 2226 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 2227 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2228 | IdentifierRemap.insert( |
| 2229 | std::make_pair(IdentifierIDOffset, |
| 2230 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2231 | MacroRemap.insert(std::make_pair(MacroIDOffset, |
| 2232 | OM->BaseMacroID - MacroIDOffset)); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2233 | PreprocessedEntityRemap.insert( |
| 2234 | std::make_pair(PreprocessedEntityIDOffset, |
| 2235 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2236 | SubmoduleRemap.insert(std::make_pair(SubmoduleIDOffset, |
| 2237 | OM->BaseSubmoduleID - SubmoduleIDOffset)); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2238 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 2239 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2240 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 2241 | OM->BaseDeclID - DeclIDOffset)); |
| 2242 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2243 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2244 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2245 | |
| 2246 | // Global -> local mappings. |
| 2247 | F.GlobalToLocalDeclIDs[OM] = DeclIDOffset; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2248 | } |
| 2249 | break; |
| 2250 | } |
| 2251 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2252 | case SOURCE_MANAGER_LINE_TABLE: |
| 2253 | if (ParseLineTable(F, Record)) |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2254 | return true; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2255 | break; |
| 2256 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2257 | case SOURCE_LOCATION_PRELOADS: { |
| 2258 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2259 | // which is based off F.SLocEntryBaseID. |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2260 | if (!F.PreloadSLocEntries.empty()) { |
| 2261 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2262 | return true; |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | F.PreloadSLocEntries.swap(Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2266 | break; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2267 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2268 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2269 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2270 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2271 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2272 | break; |
| 2273 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2274 | case VTABLE_USES: |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2275 | if (Record.size() % 3 != 0) { |
| 2276 | Error("Invalid VTABLE_USES record"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2277 | return true; |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2280 | // Later tables overwrite earlier ones. |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2281 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2282 | // the right way to do this. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2283 | VTableUses.clear(); |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2284 | |
| 2285 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2286 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2287 | VTableUses.push_back( |
| 2288 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2289 | VTableUses.push_back(Record[Idx++]); |
| 2290 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2291 | break; |
| 2292 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2293 | case DYNAMIC_CLASSES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2294 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2295 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2296 | break; |
| 2297 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2298 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2299 | if (PendingInstantiations.size() % 2 != 0) { |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 2300 | Error("Invalid existing PendingInstantiations"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2301 | return true; |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | if (Record.size() % 2 != 0) { |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2305 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2306 | return true; |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2307 | } |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 2308 | |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2309 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2310 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2311 | PendingInstantiations.push_back( |
| 2312 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2313 | } |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2314 | break; |
| 2315 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2316 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2317 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2318 | // FIXME: Modules will have some trouble with this. |
| 2319 | SemaDeclRefs.clear(); |
| 2320 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2321 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2322 | break; |
| 2323 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2324 | case PPD_ENTITIES_OFFSETS: { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2325 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)BlobStart; |
| 2326 | assert(BlobLen % sizeof(PPEntityOffset) == 0); |
| 2327 | F.NumPreprocessedEntities = BlobLen / sizeof(PPEntityOffset); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2328 | |
| 2329 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2330 | |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2331 | unsigned StartingID; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2332 | if (!PP.getPreprocessingRecord()) |
Argyrios Kyrtzidis | c6c5452 | 2012-03-05 05:48:17 +0000 | [diff] [blame] | 2333 | PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2334 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2335 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2336 | StartingID |
| 2337 | = PP.getPreprocessingRecord() |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2338 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2339 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2340 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2341 | if (F.NumPreprocessedEntities > 0) { |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2342 | // Introduce the global -> local mapping for preprocessed entities in |
| 2343 | // this module. |
| 2344 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2345 | |
| 2346 | // Introduce the local -> global mapping for preprocessed entities in |
| 2347 | // this module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2348 | F.PreprocessedEntityRemap.insertOrReplace( |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2349 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2350 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2351 | } |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2352 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2353 | break; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2356 | case DECL_UPDATE_OFFSETS: { |
| 2357 | if (Record.size() % 2 != 0) { |
| 2358 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2359 | return true; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2360 | } |
| 2361 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2362 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2363 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2364 | break; |
| 2365 | } |
| 2366 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2367 | case DECL_REPLACEMENTS: { |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2368 | if (Record.size() % 3 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2369 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2370 | return true; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2371 | } |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2372 | for (unsigned I = 0, N = Record.size(); I != N; I += 3) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2373 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2374 | = ReplacedDeclInfo(&F, Record[I+1], Record[I+2]); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2375 | break; |
| 2376 | } |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2377 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2378 | case OBJC_CATEGORIES_MAP: { |
| 2379 | if (F.LocalNumObjCCategoriesInMap != 0) { |
| 2380 | Error("duplicate OBJC_CATEGORIES_MAP record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2381 | return true; |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2382 | } |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2383 | |
| 2384 | F.LocalNumObjCCategoriesInMap = Record[0]; |
| 2385 | F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)BlobStart; |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2386 | break; |
| 2387 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2388 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2389 | case OBJC_CATEGORIES: |
| 2390 | F.ObjCCategories.swap(Record); |
| 2391 | break; |
| 2392 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2393 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2394 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2395 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2396 | return true; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2400 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2401 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2402 | break; |
| 2403 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2404 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2405 | case DIAG_PRAGMA_MAPPINGS: |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2406 | if (F.PragmaDiagMappings.empty()) |
| 2407 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2408 | else |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2409 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2410 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2411 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2412 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2413 | case CUDA_SPECIAL_DECL_REFS: |
| 2414 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2415 | // FIXME: Modules will have trouble with this. |
| 2416 | CUDASpecialDeclRefs.clear(); |
| 2417 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2418 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2419 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2420 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2421 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2422 | F.HeaderFileInfoTableData = BlobStart; |
| 2423 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2424 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2425 | if (Record[0]) { |
| 2426 | F.HeaderFileInfoTable |
| 2427 | = HeaderFileInfoLookupTable::Create( |
| 2428 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2429 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2430 | HeaderFileInfoTrait(*this, F, |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2431 | &PP.getHeaderSearchInfo(), |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2432 | BlobStart + Record[2])); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2433 | |
| 2434 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 2435 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 2436 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2437 | } |
| 2438 | break; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2439 | } |
| 2440 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2441 | case FP_PRAGMA_OPTIONS: |
| 2442 | // Later tables overwrite earlier ones. |
| 2443 | FPPragmaOptions.swap(Record); |
| 2444 | break; |
| 2445 | |
| 2446 | case OPENCL_EXTENSIONS: |
| 2447 | // Later tables overwrite earlier ones. |
| 2448 | OpenCLExtensions.swap(Record); |
| 2449 | break; |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2450 | |
| 2451 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2452 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2453 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2454 | break; |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2455 | |
| 2456 | case KNOWN_NAMESPACES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2457 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2458 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2459 | break; |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2460 | |
| 2461 | case IMPORTED_MODULES: { |
| 2462 | if (F.Kind != MK_Module) { |
| 2463 | // If we aren't loading a module (which has its own exports), make |
| 2464 | // all of the imported modules visible. |
| 2465 | // FIXME: Deal with macros-only imports. |
| 2466 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 2467 | if (unsigned GlobalID = getGlobalSubmoduleID(F, Record[I])) |
| 2468 | ImportedModules.push_back(GlobalID); |
| 2469 | } |
| 2470 | } |
| 2471 | break; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2472 | } |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2473 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2474 | case LOCAL_REDECLARATIONS: { |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2475 | F.RedeclarationChains.swap(Record); |
| 2476 | break; |
| 2477 | } |
| 2478 | |
| 2479 | case LOCAL_REDECLARATIONS_MAP: { |
| 2480 | if (F.LocalNumRedeclarationsInMap != 0) { |
| 2481 | Error("duplicate LOCAL_REDECLARATIONS_MAP record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2482 | return true; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2483 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2484 | |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2485 | F.LocalNumRedeclarationsInMap = Record[0]; |
| 2486 | F.RedeclarationsMap = (const LocalRedeclarationsInfo *)BlobStart; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2487 | break; |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2488 | } |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 2489 | |
| 2490 | case MERGED_DECLARATIONS: { |
| 2491 | for (unsigned Idx = 0; Idx < Record.size(); /* increment in loop */) { |
| 2492 | GlobalDeclID CanonID = getGlobalDeclID(F, Record[Idx++]); |
| 2493 | SmallVectorImpl<GlobalDeclID> &Decls = StoredMergedDecls[CanonID]; |
| 2494 | for (unsigned N = Record[Idx++]; N > 0; --N) |
| 2495 | Decls.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2496 | } |
| 2497 | break; |
| 2498 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2499 | |
| 2500 | case MACRO_OFFSET: { |
| 2501 | if (F.LocalNumMacros != 0) { |
| 2502 | Error("duplicate MACRO_OFFSET record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2503 | return true; |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2504 | } |
| 2505 | F.MacroOffsets = (const uint32_t *)BlobStart; |
| 2506 | F.LocalNumMacros = Record[0]; |
| 2507 | unsigned LocalBaseMacroID = Record[1]; |
| 2508 | F.BaseMacroID = getTotalNumMacros(); |
| 2509 | |
| 2510 | if (F.LocalNumMacros > 0) { |
| 2511 | // Introduce the global -> local mapping for macros within this module. |
| 2512 | GlobalMacroMap.insert(std::make_pair(getTotalNumMacros() + 1, &F)); |
| 2513 | |
| 2514 | // Introduce the local -> global mapping for macros within this module. |
| 2515 | F.MacroRemap.insertOrReplace( |
| 2516 | std::make_pair(LocalBaseMacroID, |
| 2517 | F.BaseMacroID - LocalBaseMacroID)); |
| 2518 | |
| 2519 | MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros); |
| 2520 | } |
| 2521 | break; |
| 2522 | } |
| 2523 | |
| 2524 | case MACRO_UPDATES: { |
| 2525 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2526 | MacroID ID = getGlobalMacroID(F, Record[I++]); |
| 2527 | if (I == N) |
| 2528 | break; |
| 2529 | |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 2530 | SourceLocation UndefLoc = ReadSourceLocation(F, Record, I); |
| 2531 | SubmoduleID SubmoduleID = getGlobalSubmoduleID(F, Record[I++]);; |
| 2532 | MacroUpdate Update; |
| 2533 | Update.UndefLoc = UndefLoc; |
| 2534 | MacroUpdates[ID].push_back(std::make_pair(SubmoduleID, Update)); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2535 | } |
| 2536 | break; |
| 2537 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2538 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2539 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2540 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2541 | return true; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2542 | } |
| 2543 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2544 | void ASTReader::makeNamesVisible(const HiddenNames &Names) { |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2545 | for (unsigned I = 0, N = Names.size(); I != N; ++I) { |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 2546 | switch (Names[I].getKind()) { |
| 2547 | case HiddenName::Declaration: |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 2548 | Names[I].getDecl()->Hidden = false; |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | |
| 2551 | case HiddenName::MacroVisibility: { |
| 2552 | std::pair<IdentifierInfo *, MacroInfo *> Macro = Names[I].getMacro(); |
| 2553 | Macro.second->setHidden(!Macro.second->isPublic()); |
| 2554 | if (Macro.second->isDefined()) { |
| 2555 | PP.makeLoadedMacroInfoVisible(Macro.first, Macro.second); |
| 2556 | } |
| 2557 | break; |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 2558 | } |
| 2559 | |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 2560 | case HiddenName::MacroUndef: { |
| 2561 | std::pair<IdentifierInfo *, MacroInfo *> Macro = Names[I].getMacro(); |
| 2562 | if (Macro.second->isDefined()) { |
| 2563 | Macro.second->setUndefLoc(Names[I].getMacroUndefLoc()); |
| 2564 | if (PPMutationListener *Listener = PP.getPPMutationListener()) |
| 2565 | Listener->UndefinedMacro(Macro.second); |
| 2566 | PP.makeLoadedMacroInfoVisible(Macro.first, Macro.second); |
| 2567 | } |
| 2568 | break; |
| 2569 | } |
Douglas Gregor | 1d4c113 | 2011-12-20 22:06:13 +0000 | [diff] [blame] | 2570 | } |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2571 | } |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2572 | } |
| 2573 | |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2574 | void ASTReader::makeModuleVisible(Module *Mod, |
| 2575 | Module::NameVisibilityKind NameVisibility) { |
| 2576 | llvm::SmallPtrSet<Module *, 4> Visited; |
| 2577 | llvm::SmallVector<Module *, 4> Stack; |
| 2578 | Stack.push_back(Mod); |
| 2579 | while (!Stack.empty()) { |
| 2580 | Mod = Stack.back(); |
| 2581 | Stack.pop_back(); |
| 2582 | |
| 2583 | if (NameVisibility <= Mod->NameVisibility) { |
| 2584 | // This module already has this level of visibility (or greater), so |
| 2585 | // there is nothing more to do. |
| 2586 | continue; |
| 2587 | } |
| 2588 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2589 | if (!Mod->isAvailable()) { |
| 2590 | // Modules that aren't available cannot be made visible. |
| 2591 | continue; |
| 2592 | } |
| 2593 | |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2594 | // Update the module's name visibility. |
| 2595 | Mod->NameVisibility = NameVisibility; |
| 2596 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2597 | // If we've already deserialized any names from this module, |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2598 | // mark them as visible. |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2599 | HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod); |
| 2600 | if (Hidden != HiddenNamesMap.end()) { |
| 2601 | makeNamesVisible(Hidden->second); |
| 2602 | HiddenNamesMap.erase(Hidden); |
| 2603 | } |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2604 | |
| 2605 | // Push any non-explicit submodules onto the stack to be marked as |
| 2606 | // visible. |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2607 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2608 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2609 | Sub != SubEnd; ++Sub) { |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2610 | if (!(*Sub)->IsExplicit && Visited.insert(*Sub)) |
| 2611 | Stack.push_back(*Sub); |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2612 | } |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2613 | |
| 2614 | // Push any exported modules onto the stack to be marked as visible. |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2615 | bool AnyWildcard = false; |
| 2616 | bool UnrestrictedWildcard = false; |
| 2617 | llvm::SmallVector<Module *, 4> WildcardRestrictions; |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2618 | for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { |
| 2619 | Module *Exported = Mod->Exports[I].getPointer(); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2620 | if (!Mod->Exports[I].getInt()) { |
| 2621 | // Export a named module directly; no wildcards involved. |
| 2622 | if (Visited.insert(Exported)) |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2623 | Stack.push_back(Exported); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2624 | |
| 2625 | continue; |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2626 | } |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2627 | |
| 2628 | // Wildcard export: export all of the imported modules that match |
| 2629 | // the given pattern. |
| 2630 | AnyWildcard = true; |
| 2631 | if (UnrestrictedWildcard) |
| 2632 | continue; |
| 2633 | |
| 2634 | if (Module *Restriction = Mod->Exports[I].getPointer()) |
| 2635 | WildcardRestrictions.push_back(Restriction); |
| 2636 | else { |
| 2637 | WildcardRestrictions.clear(); |
| 2638 | UnrestrictedWildcard = true; |
| 2639 | } |
| 2640 | } |
| 2641 | |
| 2642 | // If there were any wildcards, push any imported modules that were |
| 2643 | // re-exported by the wildcard restriction. |
| 2644 | if (!AnyWildcard) |
| 2645 | continue; |
| 2646 | |
| 2647 | for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { |
| 2648 | Module *Imported = Mod->Imports[I]; |
Benjamin Kramer | d48bcb2 | 2012-08-22 15:37:55 +0000 | [diff] [blame] | 2649 | if (!Visited.insert(Imported)) |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2650 | continue; |
| 2651 | |
| 2652 | bool Acceptable = UnrestrictedWildcard; |
| 2653 | if (!Acceptable) { |
| 2654 | // Check whether this module meets one of the restrictions. |
| 2655 | for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) { |
| 2656 | Module *Restriction = WildcardRestrictions[R]; |
| 2657 | if (Imported == Restriction || Imported->isSubModuleOf(Restriction)) { |
| 2658 | Acceptable = true; |
| 2659 | break; |
| 2660 | } |
| 2661 | } |
| 2662 | } |
| 2663 | |
| 2664 | if (!Acceptable) |
| 2665 | continue; |
| 2666 | |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2667 | Stack.push_back(Imported); |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2668 | } |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2669 | } |
| 2670 | } |
| 2671 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2672 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2673 | ModuleKind Type, |
| 2674 | unsigned ClientLoadCapabilities) { |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2675 | // Bump the generation number. |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2676 | unsigned PreviousGeneration = CurrentGeneration++; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2677 | |
| 2678 | // Load the core of the AST files. |
| 2679 | llvm::SmallVector<ModuleFile *, 4> Loaded; |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2680 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0, Loaded, |
| 2681 | ClientLoadCapabilities)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2682 | case Failure: return Failure; |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2683 | case OutOfDate: return OutOfDate; |
| 2684 | case VersionMismatch: return VersionMismatch; |
| 2685 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 2686 | case HadErrors: return HadErrors; |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2687 | case Success: break; |
| 2688 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2689 | |
| 2690 | // 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] | 2691 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2692 | // Load the AST blocks of all of the modules that we loaded. |
| 2693 | for (llvm::SmallVectorImpl<ModuleFile *>::iterator M = Loaded.begin(), |
| 2694 | MEnd = Loaded.end(); |
| 2695 | M != MEnd; ++M) { |
| 2696 | ModuleFile &F = **M; |
| 2697 | |
| 2698 | // Read the AST block. |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2699 | if (ReadASTBlock(F)) |
| 2700 | return Failure; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2701 | |
| 2702 | // Once read, set the ModuleFile bit base offset and update the size in |
| 2703 | // bits of all files we've seen. |
| 2704 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 2705 | TotalModulesSizeInBits += F.SizeInBits; |
| 2706 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
| 2707 | |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2708 | // Preload SLocEntries. |
| 2709 | for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) { |
| 2710 | int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
Douglas Gregor | 8b53d14 | 2012-10-22 22:53:10 +0000 | [diff] [blame] | 2711 | // Load it through the SourceManager and don't call ReadSLocEntry() |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2712 | // directly because the entry may have already been loaded in which case |
Douglas Gregor | 8b53d14 | 2012-10-22 22:53:10 +0000 | [diff] [blame] | 2713 | // calling ReadSLocEntry() directly would trigger an assertion in |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2714 | // SourceManager. |
| 2715 | SourceMgr.getLoadedSLocEntryByID(Index); |
| 2716 | } |
| 2717 | } |
| 2718 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2719 | // Mark all of the identifiers in the identifier table as being out of date, |
| 2720 | // so that various accessors know to check the loaded modules when the |
| 2721 | // identifier is used. |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2722 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 2723 | IdEnd = PP.getIdentifierTable().end(); |
| 2724 | Id != IdEnd; ++Id) |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2725 | Id->second->setOutOfDate(true); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2726 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2727 | // Resolve any unresolved module exports. |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2728 | for (unsigned I = 0, N = UnresolvedModuleImportExports.size(); I != N; ++I) { |
| 2729 | UnresolvedModuleImportExport &Unresolved = UnresolvedModuleImportExports[I]; |
| 2730 | SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2731 | Module *ResolvedMod = getSubmodule(GlobalID); |
| 2732 | |
| 2733 | if (Unresolved.IsImport) { |
| 2734 | if (ResolvedMod) |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2735 | Unresolved.Mod->Imports.push_back(ResolvedMod); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2736 | continue; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2737 | } |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2738 | |
| 2739 | if (ResolvedMod || Unresolved.IsWildcard) |
| 2740 | Unresolved.Mod->Exports.push_back( |
| 2741 | Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard)); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2742 | } |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2743 | UnresolvedModuleImportExports.clear(); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2744 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2745 | InitializeContext(); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2746 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2747 | if (DeserializationListener) |
| 2748 | DeserializationListener->ReaderInitialized(this); |
| 2749 | |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 2750 | ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule(); |
| 2751 | if (!PrimaryModule.OriginalSourceFileID.isInvalid()) { |
| 2752 | PrimaryModule.OriginalSourceFileID |
| 2753 | = FileID::get(PrimaryModule.SLocEntryBaseID |
| 2754 | + PrimaryModule.OriginalSourceFileID.getOpaqueValue() - 1); |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 2755 | |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 2756 | // If this AST file is a precompiled preamble, then set the |
| 2757 | // preamble file ID of the source manager to the file source file |
| 2758 | // from which the preamble was built. |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 2759 | if (Type == MK_Preamble) { |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 2760 | SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID); |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 2761 | } else if (Type == MK_MainFile) { |
Douglas Gregor | 11407b8 | 2012-10-18 21:18:25 +0000 | [diff] [blame] | 2762 | SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2763 | } |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2764 | } |
| 2765 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2766 | // For any Objective-C class definitions we have already loaded, make sure |
| 2767 | // that we load any additional categories. |
| 2768 | for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { |
| 2769 | loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), |
| 2770 | ObjCClassesLoaded[I], |
| 2771 | PreviousGeneration); |
| 2772 | } |
| 2773 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2774 | return Success; |
| 2775 | } |
| 2776 | |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2777 | ASTReader::ASTReadResult |
| 2778 | ASTReader::ReadASTCore(StringRef FileName, |
| 2779 | ModuleKind Type, |
| 2780 | ModuleFile *ImportedBy, |
| 2781 | llvm::SmallVectorImpl<ModuleFile *> &Loaded, |
| 2782 | unsigned ClientLoadCapabilities) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2783 | ModuleFile *M; |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2784 | bool NewModule; |
| 2785 | std::string ErrorStr; |
| 2786 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2787 | CurrentGeneration, ErrorStr); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2788 | |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2789 | if (!M) { |
| 2790 | // We couldn't load the module. |
| 2791 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 2792 | + ErrorStr; |
| 2793 | Error(Msg); |
| 2794 | return Failure; |
| 2795 | } |
| 2796 | |
| 2797 | if (!NewModule) { |
| 2798 | // We've already loaded this module. |
| 2799 | return Success; |
| 2800 | } |
| 2801 | |
| 2802 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 2803 | // module? |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2804 | if (FileName != "-") { |
| 2805 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2806 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2807 | } |
| 2808 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2809 | ModuleFile &F = *M; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2810 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2811 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2812 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2813 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2814 | // Sniff for the signature. |
| 2815 | if (Stream.Read(8) != 'C' || |
| 2816 | Stream.Read(8) != 'P' || |
| 2817 | Stream.Read(8) != 'C' || |
| 2818 | Stream.Read(8) != 'H') { |
| 2819 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2820 | return Failure; |
| 2821 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2822 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2823 | while (!Stream.AtEndOfStream()) { |
| 2824 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2825 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2826 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2827 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2828 | return Failure; |
| 2829 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2830 | |
| 2831 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2832 | |
Douglas Gregor | 7ae467f | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 2833 | // We only know the control subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2834 | switch (BlockID) { |
| 2835 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2836 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2837 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2838 | return Failure; |
| 2839 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2840 | break; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2841 | case CONTROL_BLOCK_ID: |
Douglas Gregor | 38295be | 2012-10-22 23:51:00 +0000 | [diff] [blame] | 2842 | switch (ReadControlBlock(F, Loaded, ClientLoadCapabilities)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2843 | case Success: |
| 2844 | break; |
| 2845 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 2846 | case Failure: return Failure; |
| 2847 | case OutOfDate: return OutOfDate; |
| 2848 | case VersionMismatch: return VersionMismatch; |
| 2849 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 2850 | case HadErrors: return HadErrors; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2851 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2852 | break; |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 2853 | case AST_BLOCK_ID: |
| 2854 | // Record that we've loaded this module. |
| 2855 | Loaded.push_back(M); |
| 2856 | return Success; |
| 2857 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2858 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2859 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2860 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2861 | return Failure; |
| 2862 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2863 | break; |
| 2864 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2865 | } |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2866 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2867 | return Success; |
| 2868 | } |
| 2869 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2870 | void ASTReader::InitializeContext() { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2871 | // If there's a listener, notify them that we "read" the translation unit. |
| 2872 | if (DeserializationListener) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2873 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2874 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2875 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2876 | // Make sure we load the declaration update records for the translation unit, |
| 2877 | // if there are any. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2878 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2879 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2880 | |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2881 | // FIXME: Find a better way to deal with collisions between these |
| 2882 | // built-in types. Right now, we just ignore the problem. |
| 2883 | |
| 2884 | // Load the special types. |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 2885 | if (SpecialTypes.size() >= NumSpecialTypeIDs) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2886 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 2887 | if (!Context.CFConstantStringTypeDecl) |
| 2888 | Context.setCFConstantStringType(GetType(String)); |
| 2889 | } |
| 2890 | |
| 2891 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 2892 | QualType FileType = GetType(File); |
| 2893 | if (FileType.isNull()) { |
| 2894 | Error("FILE type is NULL"); |
| 2895 | return; |
| 2896 | } |
| 2897 | |
| 2898 | if (!Context.FILEDecl) { |
| 2899 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 2900 | Context.setFILEDecl(Typedef->getDecl()); |
| 2901 | else { |
| 2902 | const TagType *Tag = FileType->getAs<TagType>(); |
| 2903 | if (!Tag) { |
| 2904 | Error("Invalid FILE type in AST file"); |
| 2905 | return; |
| 2906 | } |
| 2907 | Context.setFILEDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2908 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2909 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2910 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2911 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 2912 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2913 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 2914 | if (Jmp_bufType.isNull()) { |
| 2915 | Error("jmp_buf type is NULL"); |
| 2916 | return; |
| 2917 | } |
| 2918 | |
| 2919 | if (!Context.jmp_bufDecl) { |
| 2920 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 2921 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 2922 | else { |
| 2923 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 2924 | if (!Tag) { |
| 2925 | Error("Invalid jmp_buf type in AST file"); |
| 2926 | return; |
| 2927 | } |
| 2928 | Context.setjmp_bufDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2929 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2930 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2931 | } |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2932 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 2933 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2934 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 2935 | if (Sigjmp_bufType.isNull()) { |
| 2936 | Error("sigjmp_buf type is NULL"); |
| 2937 | return; |
| 2938 | } |
| 2939 | |
| 2940 | if (!Context.sigjmp_bufDecl) { |
| 2941 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 2942 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 2943 | else { |
| 2944 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 2945 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 2946 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 2947 | } |
| 2948 | } |
| 2949 | } |
| 2950 | |
| 2951 | if (unsigned ObjCIdRedef |
| 2952 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 2953 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 2954 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 2955 | } |
| 2956 | |
| 2957 | if (unsigned ObjCClassRedef |
| 2958 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 2959 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 2960 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 2961 | } |
| 2962 | |
| 2963 | if (unsigned ObjCSelRedef |
| 2964 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 2965 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 2966 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 2967 | } |
Rafael Espindola | e2d4f4e | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 2968 | |
| 2969 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 2970 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 2971 | if (Ucontext_tType.isNull()) { |
| 2972 | Error("ucontext_t type is NULL"); |
| 2973 | return; |
| 2974 | } |
| 2975 | |
| 2976 | if (!Context.ucontext_tDecl) { |
| 2977 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| 2978 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 2979 | else { |
| 2980 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| 2981 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 2982 | Context.setucontext_tDecl(Tag->getDecl()); |
| 2983 | } |
| 2984 | } |
| 2985 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2986 | } |
| 2987 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2988 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2989 | |
| 2990 | // If there were any CUDA special declarations, deserialize them. |
| 2991 | if (!CUDASpecialDeclRefs.empty()) { |
| 2992 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2993 | Context.setcudaConfigureCallDecl( |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2994 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2995 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2996 | |
| 2997 | // Re-export any modules that were imported by a non-module AST file. |
| 2998 | for (unsigned I = 0, N = ImportedModules.size(); I != N; ++I) { |
| 2999 | if (Module *Imported = getSubmodule(ImportedModules[I])) |
| 3000 | makeModuleVisible(Imported, Module::AllVisible); |
| 3001 | } |
| 3002 | ImportedModules.clear(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 3005 | void ASTReader::finalizeForWriting() { |
| 3006 | for (HiddenNamesMapType::iterator Hidden = HiddenNamesMap.begin(), |
| 3007 | HiddenEnd = HiddenNamesMap.end(); |
| 3008 | Hidden != HiddenEnd; ++Hidden) { |
| 3009 | makeNamesVisible(Hidden->second); |
| 3010 | } |
| 3011 | HiddenNamesMap.clear(); |
| 3012 | } |
| 3013 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3014 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3015 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3016 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3017 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 3018 | FileManager &FileMgr, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 3019 | DiagnosticsEngine &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3020 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3021 | std::string ErrStr; |
Dylan Noblesmith | 6f42b62 | 2012-02-05 02:12:40 +0000 | [diff] [blame] | 3022 | OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 3023 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3024 | if (!Buffer) { |
Kaelyn Uhrain | da01f62 | 2012-06-20 00:36:03 +0000 | [diff] [blame] | 3025 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ASTFileName << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3026 | return std::string(); |
| 3027 | } |
| 3028 | |
| 3029 | // Initialize the stream |
| 3030 | llvm::BitstreamReader StreamFile; |
| 3031 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3032 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3033 | (const unsigned char *)Buffer->getBufferEnd()); |
| 3034 | Stream.init(StreamFile); |
| 3035 | |
| 3036 | // Sniff for the signature. |
| 3037 | if (Stream.Read(8) != 'C' || |
| 3038 | Stream.Read(8) != 'P' || |
| 3039 | Stream.Read(8) != 'C' || |
| 3040 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3041 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3042 | return std::string(); |
| 3043 | } |
| 3044 | |
| 3045 | RecordData Record; |
| 3046 | while (!Stream.AtEndOfStream()) { |
| 3047 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3048 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3049 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3050 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3051 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3052 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3053 | switch (BlockID) { |
Douglas Gregor | 1d9d989 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 3054 | case CONTROL_BLOCK_ID: |
| 3055 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3056 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3057 | return std::string(); |
| 3058 | } |
| 3059 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3060 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3061 | default: |
| 3062 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3063 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3064 | return std::string(); |
| 3065 | } |
| 3066 | break; |
| 3067 | } |
| 3068 | continue; |
| 3069 | } |
| 3070 | |
| 3071 | if (Code == llvm::bitc::END_BLOCK) { |
| 3072 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3073 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3074 | return std::string(); |
| 3075 | } |
| 3076 | continue; |
| 3077 | } |
| 3078 | |
| 3079 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3080 | Stream.ReadAbbrevRecord(); |
| 3081 | continue; |
| 3082 | } |
| 3083 | |
| 3084 | Record.clear(); |
| 3085 | const char *BlobStart = 0; |
| 3086 | unsigned BlobLen = 0; |
Douglas Gregor | 39c497b | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 3087 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) == ORIGINAL_FILE) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3088 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3089 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3090 | |
| 3091 | return std::string(); |
| 3092 | } |
| 3093 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3094 | namespace { |
| 3095 | class SimplePCHValidator : public ASTReaderListener { |
| 3096 | const LangOptions &ExistingLangOpts; |
| 3097 | const TargetOptions &ExistingTargetOpts; |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3098 | const PreprocessorOptions &ExistingPPOpts; |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3099 | FileManager &FileMgr; |
| 3100 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3101 | public: |
| 3102 | SimplePCHValidator(const LangOptions &ExistingLangOpts, |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3103 | const TargetOptions &ExistingTargetOpts, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3104 | const PreprocessorOptions &ExistingPPOpts, |
| 3105 | FileManager &FileMgr) |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3106 | : ExistingLangOpts(ExistingLangOpts), |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3107 | ExistingTargetOpts(ExistingTargetOpts), |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3108 | ExistingPPOpts(ExistingPPOpts), |
| 3109 | FileMgr(FileMgr) |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3110 | { |
| 3111 | } |
| 3112 | |
| 3113 | virtual bool ReadLanguageOptions(const LangOptions &LangOpts, |
| 3114 | bool Complain) { |
| 3115 | return checkLanguageOptions(ExistingLangOpts, LangOpts, 0); |
| 3116 | } |
| 3117 | virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, |
| 3118 | bool Complain) { |
| 3119 | return checkTargetOptions(ExistingTargetOpts, TargetOpts, 0); |
| 3120 | } |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3121 | virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3122 | bool Complain, |
| 3123 | std::string &SuggestedPredefines) { |
| 3124 | return checkPreprocessorOptions(ExistingPPOpts, PPOpts, 0, FileMgr, |
| 3125 | SuggestedPredefines); |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3126 | } |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3127 | }; |
| 3128 | } |
| 3129 | |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3130 | bool ASTReader::readASTFileControlBlock(StringRef Filename, |
| 3131 | FileManager &FileMgr, |
| 3132 | ASTReaderListener &Listener) { |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3133 | // Open the AST file. |
| 3134 | std::string ErrStr; |
| 3135 | OwningPtr<llvm::MemoryBuffer> Buffer; |
| 3136 | Buffer.reset(FileMgr.getBufferForFile(Filename, &ErrStr)); |
| 3137 | if (!Buffer) { |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3138 | return true; |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | // Initialize the stream |
| 3142 | llvm::BitstreamReader StreamFile; |
| 3143 | llvm::BitstreamCursor Stream; |
| 3144 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
| 3145 | (const unsigned char *)Buffer->getBufferEnd()); |
| 3146 | Stream.init(StreamFile); |
| 3147 | |
| 3148 | // Sniff for the signature. |
| 3149 | if (Stream.Read(8) != 'C' || |
| 3150 | Stream.Read(8) != 'P' || |
| 3151 | Stream.Read(8) != 'C' || |
| 3152 | Stream.Read(8) != 'H') { |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3153 | return true; |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3154 | } |
| 3155 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3156 | RecordData Record; |
| 3157 | bool InControlBlock = false; |
| 3158 | while (!Stream.AtEndOfStream()) { |
| 3159 | unsigned Code = Stream.ReadCode(); |
| 3160 | |
| 3161 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3162 | unsigned BlockID = Stream.ReadSubBlockID(); |
| 3163 | |
| 3164 | // We only know the control subblock ID. |
| 3165 | switch (BlockID) { |
| 3166 | case CONTROL_BLOCK_ID: |
| 3167 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3168 | return true; |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3169 | } else { |
| 3170 | InControlBlock = true; |
| 3171 | } |
| 3172 | break; |
| 3173 | |
| 3174 | default: |
| 3175 | if (Stream.SkipBlock()) |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3176 | return true; |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3177 | break; |
| 3178 | } |
| 3179 | continue; |
| 3180 | } |
| 3181 | |
| 3182 | if (Code == llvm::bitc::END_BLOCK) { |
| 3183 | if (Stream.ReadBlockEnd()) { |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3184 | return true; |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3185 | } |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3186 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3187 | InControlBlock = false; |
| 3188 | continue; |
| 3189 | } |
| 3190 | |
| 3191 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3192 | Stream.ReadAbbrevRecord(); |
| 3193 | continue; |
| 3194 | } |
| 3195 | |
| 3196 | Record.clear(); |
| 3197 | const char *BlobStart = 0; |
| 3198 | unsigned BlobLen = 0; |
| 3199 | unsigned RecCode = Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
| 3200 | if (InControlBlock) { |
| 3201 | switch ((ControlRecordTypes)RecCode) { |
| 3202 | case METADATA: { |
| 3203 | if (Record[0] != VERSION_MAJOR) { |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3204 | return true; |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3205 | } |
| 3206 | |
| 3207 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
| 3208 | StringRef ASTBranch(BlobStart, BlobLen); |
| 3209 | if (StringRef(CurBranch) != ASTBranch) |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3210 | return true; |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3211 | |
| 3212 | break; |
| 3213 | } |
| 3214 | case LANGUAGE_OPTIONS: |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3215 | if (ParseLanguageOptions(Record, false, Listener)) |
| 3216 | return true; |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3217 | break; |
| 3218 | |
| 3219 | case TARGET_OPTIONS: |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3220 | if (ParseTargetOptions(Record, false, Listener)) |
| 3221 | return true; |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3222 | break; |
| 3223 | |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 3224 | case DIAGNOSTIC_OPTIONS: |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3225 | if (ParseDiagnosticOptions(Record, false, Listener)) |
| 3226 | return true; |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 3227 | break; |
| 3228 | |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 3229 | case FILE_SYSTEM_OPTIONS: |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3230 | if (ParseFileSystemOptions(Record, false, Listener)) |
| 3231 | return true; |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 3232 | break; |
| 3233 | |
| 3234 | case HEADER_SEARCH_OPTIONS: |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3235 | if (ParseHeaderSearchOptions(Record, false, Listener)) |
| 3236 | return true; |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 3237 | break; |
| 3238 | |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3239 | case PREPROCESSOR_OPTIONS: { |
| 3240 | std::string IgnoredSuggestedPredefines; |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3241 | if (ParsePreprocessorOptions(Record, false, Listener, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3242 | IgnoredSuggestedPredefines)) |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3243 | return true; |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3244 | break; |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3245 | } |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3246 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3247 | default: |
| 3248 | // No other validation to perform. |
| 3249 | break; |
| 3250 | } |
| 3251 | } |
| 3252 | } |
| 3253 | |
Douglas Gregor | 9e60371 | 2012-11-06 23:40:54 +0000 | [diff] [blame] | 3254 | return false; |
| 3255 | } |
| 3256 | |
| 3257 | |
| 3258 | bool ASTReader::isAcceptableASTFile(StringRef Filename, |
| 3259 | FileManager &FileMgr, |
| 3260 | const LangOptions &LangOpts, |
| 3261 | const TargetOptions &TargetOpts, |
| 3262 | const PreprocessorOptions &PPOpts) { |
| 3263 | SimplePCHValidator validator(LangOpts, TargetOpts, PPOpts, FileMgr); |
| 3264 | return !readASTFileControlBlock(Filename, FileMgr, validator); |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3265 | } |
| 3266 | |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3267 | bool ASTReader::ReadSubmoduleBlock(ModuleFile &F) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3268 | // Enter the submodule block. |
| 3269 | if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) { |
| 3270 | Error("malformed submodule block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3271 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3272 | } |
| 3273 | |
| 3274 | ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3275 | bool First = true; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3276 | Module *CurrentModule = 0; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3277 | RecordData Record; |
| 3278 | while (true) { |
| 3279 | unsigned Code = F.Stream.ReadCode(); |
| 3280 | if (Code == llvm::bitc::END_BLOCK) { |
| 3281 | if (F.Stream.ReadBlockEnd()) { |
| 3282 | Error("error at end of submodule block in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3283 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3284 | } |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3285 | return false; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3286 | } |
| 3287 | |
| 3288 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3289 | // No known subblocks, always skip them. |
| 3290 | F.Stream.ReadSubBlockID(); |
| 3291 | if (F.Stream.SkipBlock()) { |
| 3292 | Error("malformed block record in AST file"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3293 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3294 | } |
| 3295 | continue; |
| 3296 | } |
| 3297 | |
| 3298 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3299 | F.Stream.ReadAbbrevRecord(); |
| 3300 | continue; |
| 3301 | } |
| 3302 | |
| 3303 | // Read a record. |
| 3304 | const char *BlobStart; |
| 3305 | unsigned BlobLen; |
| 3306 | Record.clear(); |
| 3307 | switch (F.Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 3308 | default: // Default behavior: ignore. |
| 3309 | break; |
| 3310 | |
| 3311 | case SUBMODULE_DEFINITION: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3312 | if (First) { |
| 3313 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3314 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3315 | } |
| 3316 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3317 | if (Record.size() < 7) { |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3318 | Error("malformed module definition"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3319 | return true; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3320 | } |
| 3321 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3322 | StringRef Name(BlobStart, BlobLen); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3323 | SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[0]); |
| 3324 | SubmoduleID Parent = getGlobalSubmoduleID(F, Record[1]); |
| 3325 | bool IsFramework = Record[2]; |
| 3326 | bool IsExplicit = Record[3]; |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 3327 | bool IsSystem = Record[4]; |
| 3328 | bool InferSubmodules = Record[5]; |
| 3329 | bool InferExplicitSubmodules = Record[6]; |
| 3330 | bool InferExportWildcard = Record[7]; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3331 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3332 | Module *ParentModule = 0; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3333 | if (Parent) |
| 3334 | ParentModule = getSubmodule(Parent); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3335 | |
| 3336 | // Retrieve this (sub)module from the module map, creating it if |
| 3337 | // necessary. |
| 3338 | CurrentModule = ModMap.findOrCreateModule(Name, ParentModule, |
| 3339 | IsFramework, |
| 3340 | IsExplicit).first; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3341 | SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS; |
| 3342 | if (GlobalIndex >= SubmodulesLoaded.size() || |
| 3343 | SubmodulesLoaded[GlobalIndex]) { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3344 | Error("too many submodules"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3345 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3346 | } |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3347 | |
Argyrios Kyrtzidis | d64c26f | 2012-10-03 01:58:42 +0000 | [diff] [blame] | 3348 | CurrentModule->setASTFile(F.File); |
Douglas Gregor | 305dc3e | 2011-12-20 00:28:52 +0000 | [diff] [blame] | 3349 | CurrentModule->IsFromModuleFile = true; |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 3350 | CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3351 | CurrentModule->InferSubmodules = InferSubmodules; |
| 3352 | CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; |
| 3353 | CurrentModule->InferExportWildcard = InferExportWildcard; |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3354 | if (DeserializationListener) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3355 | DeserializationListener->ModuleRead(GlobalID, CurrentModule); |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3356 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3357 | SubmodulesLoaded[GlobalIndex] = CurrentModule; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3358 | break; |
| 3359 | } |
| 3360 | |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3361 | case SUBMODULE_UMBRELLA_HEADER: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3362 | if (First) { |
| 3363 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3364 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3365 | } |
| 3366 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3367 | if (!CurrentModule) |
| 3368 | break; |
| 3369 | |
| 3370 | StringRef FileName(BlobStart, BlobLen); |
| 3371 | if (const FileEntry *Umbrella = PP.getFileManager().getFile(FileName)) { |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 3372 | if (!CurrentModule->getUmbrellaHeader()) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3373 | ModMap.setUmbrellaHeader(CurrentModule, Umbrella); |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 3374 | else if (CurrentModule->getUmbrellaHeader() != Umbrella) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3375 | Error("mismatched umbrella headers in submodule"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3376 | return true; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3377 | } |
| 3378 | } |
| 3379 | break; |
| 3380 | } |
| 3381 | |
| 3382 | case SUBMODULE_HEADER: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3383 | if (First) { |
| 3384 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3385 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3386 | } |
| 3387 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3388 | if (!CurrentModule) |
| 3389 | break; |
| 3390 | |
| 3391 | // FIXME: Be more lazy about this! |
| 3392 | StringRef FileName(BlobStart, BlobLen); |
| 3393 | if (const FileEntry *File = PP.getFileManager().getFile(FileName)) { |
| 3394 | if (std::find(CurrentModule->Headers.begin(), |
| 3395 | CurrentModule->Headers.end(), |
| 3396 | File) == CurrentModule->Headers.end()) |
Douglas Gregor | 2b49d1f | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 3397 | ModMap.addHeader(CurrentModule, File, false); |
| 3398 | } |
| 3399 | break; |
| 3400 | } |
| 3401 | |
| 3402 | case SUBMODULE_EXCLUDED_HEADER: { |
| 3403 | if (First) { |
| 3404 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3405 | return true; |
Douglas Gregor | 2b49d1f | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | if (!CurrentModule) |
| 3409 | break; |
| 3410 | |
| 3411 | // FIXME: Be more lazy about this! |
| 3412 | StringRef FileName(BlobStart, BlobLen); |
| 3413 | if (const FileEntry *File = PP.getFileManager().getFile(FileName)) { |
| 3414 | if (std::find(CurrentModule->Headers.begin(), |
| 3415 | CurrentModule->Headers.end(), |
| 3416 | File) == CurrentModule->Headers.end()) |
| 3417 | ModMap.addHeader(CurrentModule, File, true); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3418 | } |
| 3419 | break; |
| 3420 | } |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 3421 | |
| 3422 | case SUBMODULE_TOPHEADER: { |
| 3423 | if (First) { |
| 3424 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3425 | return true; |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 3426 | } |
| 3427 | |
| 3428 | if (!CurrentModule) |
| 3429 | break; |
| 3430 | |
| 3431 | // FIXME: Be more lazy about this! |
| 3432 | StringRef FileName(BlobStart, BlobLen); |
| 3433 | if (const FileEntry *File = PP.getFileManager().getFile(FileName)) |
| 3434 | CurrentModule->TopHeaders.insert(File); |
| 3435 | break; |
| 3436 | } |
| 3437 | |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3438 | case SUBMODULE_UMBRELLA_DIR: { |
| 3439 | if (First) { |
| 3440 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3441 | return true; |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3442 | } |
| 3443 | |
| 3444 | if (!CurrentModule) |
| 3445 | break; |
| 3446 | |
| 3447 | StringRef DirName(BlobStart, BlobLen); |
| 3448 | if (const DirectoryEntry *Umbrella |
| 3449 | = PP.getFileManager().getDirectory(DirName)) { |
| 3450 | if (!CurrentModule->getUmbrellaDir()) |
| 3451 | ModMap.setUmbrellaDir(CurrentModule, Umbrella); |
| 3452 | else if (CurrentModule->getUmbrellaDir() != Umbrella) { |
| 3453 | Error("mismatched umbrella directories in submodule"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3454 | return true; |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3455 | } |
| 3456 | } |
| 3457 | break; |
| 3458 | } |
| 3459 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3460 | case SUBMODULE_METADATA: { |
| 3461 | if (!First) { |
| 3462 | Error("submodule metadata record not at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3463 | return true; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3464 | } |
| 3465 | First = false; |
| 3466 | |
| 3467 | F.BaseSubmoduleID = getTotalNumSubmodules(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3468 | F.LocalNumSubmodules = Record[0]; |
| 3469 | unsigned LocalBaseSubmoduleID = Record[1]; |
| 3470 | if (F.LocalNumSubmodules > 0) { |
| 3471 | // Introduce the global -> local mapping for submodules within this |
| 3472 | // module. |
| 3473 | GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F)); |
| 3474 | |
| 3475 | // Introduce the local -> global mapping for submodules within this |
| 3476 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 3477 | F.SubmoduleRemap.insertOrReplace( |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3478 | std::make_pair(LocalBaseSubmoduleID, |
| 3479 | F.BaseSubmoduleID - LocalBaseSubmoduleID)); |
| 3480 | |
| 3481 | SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules); |
| 3482 | } |
| 3483 | break; |
| 3484 | } |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3485 | |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3486 | case SUBMODULE_IMPORTS: { |
| 3487 | if (First) { |
| 3488 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3489 | return true; |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | if (!CurrentModule) |
| 3493 | break; |
| 3494 | |
| 3495 | for (unsigned Idx = 0; Idx != Record.size(); ++Idx) { |
| 3496 | UnresolvedModuleImportExport Unresolved; |
| 3497 | Unresolved.File = &F; |
| 3498 | Unresolved.Mod = CurrentModule; |
| 3499 | Unresolved.ID = Record[Idx]; |
| 3500 | Unresolved.IsImport = true; |
| 3501 | Unresolved.IsWildcard = false; |
| 3502 | UnresolvedModuleImportExports.push_back(Unresolved); |
| 3503 | } |
| 3504 | break; |
| 3505 | } |
| 3506 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3507 | case SUBMODULE_EXPORTS: { |
| 3508 | if (First) { |
| 3509 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3510 | return true; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | if (!CurrentModule) |
| 3514 | break; |
| 3515 | |
| 3516 | for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3517 | UnresolvedModuleImportExport Unresolved; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3518 | Unresolved.File = &F; |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3519 | Unresolved.Mod = CurrentModule; |
| 3520 | Unresolved.ID = Record[Idx]; |
| 3521 | Unresolved.IsImport = false; |
| 3522 | Unresolved.IsWildcard = Record[Idx + 1]; |
| 3523 | UnresolvedModuleImportExports.push_back(Unresolved); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | // Once we've loaded the set of exports, there's no reason to keep |
| 3527 | // the parsed, unresolved exports around. |
| 3528 | CurrentModule->UnresolvedExports.clear(); |
| 3529 | break; |
| 3530 | } |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3531 | case SUBMODULE_REQUIRES: { |
| 3532 | if (First) { |
| 3533 | Error("missing submodule metadata record at beginning of block"); |
Douglas Gregor | 4825fd7 | 2012-10-22 22:50:17 +0000 | [diff] [blame] | 3534 | return true; |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3535 | } |
| 3536 | |
| 3537 | if (!CurrentModule) |
| 3538 | break; |
| 3539 | |
| 3540 | CurrentModule->addRequirement(StringRef(BlobStart, BlobLen), |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3541 | Context.getLangOpts(), |
Douglas Gregor | dc58aa7 | 2012-01-30 06:01:29 +0000 | [diff] [blame] | 3542 | Context.getTargetInfo()); |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3543 | break; |
| 3544 | } |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3545 | } |
| 3546 | } |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3547 | } |
| 3548 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3549 | /// \brief Parse the record that corresponds to a LangOptions data |
| 3550 | /// structure. |
| 3551 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3552 | /// This routine parses the language options from the AST file and then gives |
| 3553 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3554 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3555 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3556 | bool ASTReader::ParseLanguageOptions(const RecordData &Record, |
| 3557 | bool Complain, |
| 3558 | ASTReaderListener &Listener) { |
| 3559 | LangOptions LangOpts; |
| 3560 | unsigned Idx = 0; |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 3561 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 3562 | LangOpts.Name = Record[Idx++]; |
| 3563 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 3564 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 3565 | #include "clang/Basic/LangOptions.def" |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3566 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3567 | ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++]; |
| 3568 | VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx); |
| 3569 | LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion); |
| 3570 | |
| 3571 | unsigned Length = Record[Idx++]; |
| 3572 | LangOpts.CurrentModule.assign(Record.begin() + Idx, |
| 3573 | Record.begin() + Idx + Length); |
| 3574 | return Listener.ReadLanguageOptions(LangOpts, Complain); |
| 3575 | } |
| 3576 | |
| 3577 | bool ASTReader::ParseTargetOptions(const RecordData &Record, |
| 3578 | bool Complain, |
| 3579 | ASTReaderListener &Listener) { |
| 3580 | unsigned Idx = 0; |
| 3581 | TargetOptions TargetOpts; |
| 3582 | TargetOpts.Triple = ReadString(Record, Idx); |
| 3583 | TargetOpts.CPU = ReadString(Record, Idx); |
| 3584 | TargetOpts.ABI = ReadString(Record, Idx); |
| 3585 | TargetOpts.CXXABI = ReadString(Record, Idx); |
| 3586 | TargetOpts.LinkerVersion = ReadString(Record, Idx); |
| 3587 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3588 | TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx)); |
| 3589 | } |
| 3590 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3591 | TargetOpts.Features.push_back(ReadString(Record, Idx)); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3592 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3593 | |
Douglas Gregor | 27ffa6c | 2012-10-23 06:18:24 +0000 | [diff] [blame] | 3594 | return Listener.ReadTargetOptions(TargetOpts, Complain); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3595 | } |
| 3596 | |
Douglas Gregor | 5f3d822 | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 3597 | bool ASTReader::ParseDiagnosticOptions(const RecordData &Record, bool Complain, |
| 3598 | ASTReaderListener &Listener) { |
| 3599 | DiagnosticOptions DiagOpts; |
| 3600 | unsigned Idx = 0; |
| 3601 | #define DIAGOPT(Name, Bits, Default) DiagOpts.Name = Record[Idx++]; |
| 3602 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 3603 | DiagOpts.set##Name(static_cast<Type>(Record[Idx++])); |
| 3604 | #include "clang/Basic/DiagnosticOptions.def" |
| 3605 | |
| 3606 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3607 | DiagOpts.Warnings.push_back(ReadString(Record, Idx)); |
| 3608 | } |
| 3609 | |
| 3610 | return Listener.ReadDiagnosticOptions(DiagOpts, Complain); |
| 3611 | } |
| 3612 | |
Douglas Gregor | 1b2c3c0 | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 3613 | bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain, |
| 3614 | ASTReaderListener &Listener) { |
| 3615 | FileSystemOptions FSOpts; |
| 3616 | unsigned Idx = 0; |
| 3617 | FSOpts.WorkingDir = ReadString(Record, Idx); |
| 3618 | return Listener.ReadFileSystemOptions(FSOpts, Complain); |
| 3619 | } |
| 3620 | |
Douglas Gregor | bbf3831 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 3621 | bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record, |
| 3622 | bool Complain, |
| 3623 | ASTReaderListener &Listener) { |
| 3624 | HeaderSearchOptions HSOpts; |
| 3625 | unsigned Idx = 0; |
| 3626 | HSOpts.Sysroot = ReadString(Record, Idx); |
| 3627 | |
| 3628 | // Include entries. |
| 3629 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3630 | std::string Path = ReadString(Record, Idx); |
| 3631 | frontend::IncludeDirGroup Group |
| 3632 | = static_cast<frontend::IncludeDirGroup>(Record[Idx++]); |
| 3633 | bool IsUserSupplied = Record[Idx++]; |
| 3634 | bool IsFramework = Record[Idx++]; |
| 3635 | bool IgnoreSysRoot = Record[Idx++]; |
| 3636 | bool IsInternal = Record[Idx++]; |
| 3637 | bool ImplicitExternC = Record[Idx++]; |
| 3638 | HSOpts.UserEntries.push_back( |
| 3639 | HeaderSearchOptions::Entry(Path, Group, IsUserSupplied, IsFramework, |
| 3640 | IgnoreSysRoot, IsInternal, ImplicitExternC)); |
| 3641 | } |
| 3642 | |
| 3643 | // System header prefixes. |
| 3644 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3645 | std::string Prefix = ReadString(Record, Idx); |
| 3646 | bool IsSystemHeader = Record[Idx++]; |
| 3647 | HSOpts.SystemHeaderPrefixes.push_back( |
| 3648 | HeaderSearchOptions::SystemHeaderPrefix(Prefix, IsSystemHeader)); |
| 3649 | } |
| 3650 | |
| 3651 | HSOpts.ResourceDir = ReadString(Record, Idx); |
| 3652 | HSOpts.ModuleCachePath = ReadString(Record, Idx); |
| 3653 | HSOpts.DisableModuleHash = Record[Idx++]; |
| 3654 | HSOpts.UseBuiltinIncludes = Record[Idx++]; |
| 3655 | HSOpts.UseStandardSystemIncludes = Record[Idx++]; |
| 3656 | HSOpts.UseStandardCXXIncludes = Record[Idx++]; |
| 3657 | HSOpts.UseLibcxx = Record[Idx++]; |
| 3658 | |
| 3659 | return Listener.ReadHeaderSearchOptions(HSOpts, Complain); |
| 3660 | } |
| 3661 | |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3662 | bool ASTReader::ParsePreprocessorOptions(const RecordData &Record, |
| 3663 | bool Complain, |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3664 | ASTReaderListener &Listener, |
| 3665 | std::string &SuggestedPredefines) { |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3666 | PreprocessorOptions PPOpts; |
| 3667 | unsigned Idx = 0; |
| 3668 | |
| 3669 | // Macro definitions/undefs |
| 3670 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3671 | std::string Macro = ReadString(Record, Idx); |
| 3672 | bool IsUndef = Record[Idx++]; |
| 3673 | PPOpts.Macros.push_back(std::make_pair(Macro, IsUndef)); |
| 3674 | } |
| 3675 | |
| 3676 | // Includes |
| 3677 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3678 | PPOpts.Includes.push_back(ReadString(Record, Idx)); |
| 3679 | } |
| 3680 | |
| 3681 | // Macro Includes |
| 3682 | for (unsigned N = Record[Idx++]; N; --N) { |
| 3683 | PPOpts.MacroIncludes.push_back(ReadString(Record, Idx)); |
| 3684 | } |
| 3685 | |
Douglas Gregor | 4c0c7e8 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 3686 | PPOpts.UsePredefines = Record[Idx++]; |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3687 | PPOpts.ImplicitPCHInclude = ReadString(Record, Idx); |
| 3688 | PPOpts.ImplicitPTHInclude = ReadString(Record, Idx); |
| 3689 | PPOpts.ObjCXXARCStandardLibrary = |
| 3690 | static_cast<ObjCXXARCStandardLibraryKind>(Record[Idx++]); |
Douglas Gregor | 8769924 | 2012-10-25 00:07:54 +0000 | [diff] [blame] | 3691 | SuggestedPredefines.clear(); |
| 3692 | return Listener.ReadPreprocessorOptions(PPOpts, Complain, |
| 3693 | SuggestedPredefines); |
Douglas Gregor | a71a7d8 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 3694 | } |
| 3695 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3696 | std::pair<ModuleFile *, unsigned> |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3697 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3698 | GlobalPreprocessedEntityMapType::iterator |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3699 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3700 | assert(I != GlobalPreprocessedEntityMap.end() && |
| 3701 | "Corrupted global preprocessed entity map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3702 | ModuleFile *M = I->second; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3703 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 3704 | return std::make_pair(M, LocalIndex); |
| 3705 | } |
| 3706 | |
Argyrios Kyrtzidis | 632dcc9 | 2012-10-02 16:10:51 +0000 | [diff] [blame] | 3707 | std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator> |
| 3708 | ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const { |
| 3709 | if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord()) |
| 3710 | return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID, |
| 3711 | Mod.NumPreprocessedEntities); |
| 3712 | |
| 3713 | return std::make_pair(PreprocessingRecord::iterator(), |
| 3714 | PreprocessingRecord::iterator()); |
| 3715 | } |
| 3716 | |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 3717 | std::pair<ASTReader::ModuleDeclIterator, ASTReader::ModuleDeclIterator> |
| 3718 | ASTReader::getModuleFileLevelDecls(ModuleFile &Mod) { |
| 3719 | return std::make_pair(ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls), |
| 3720 | ModuleDeclIterator(this, &Mod, |
| 3721 | Mod.FileSortedDecls + Mod.NumFileSortedDecls)); |
| 3722 | } |
| 3723 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3724 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 3725 | PreprocessedEntityID PPID = Index+1; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3726 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 3727 | ModuleFile &M = *PPInfo.first; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3728 | unsigned LocalIndex = PPInfo.second; |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3729 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3730 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3731 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3732 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3733 | |
| 3734 | unsigned Code = M.PreprocessorDetailCursor.ReadCode(); |
| 3735 | switch (Code) { |
| 3736 | case llvm::bitc::END_BLOCK: |
| 3737 | return 0; |
| 3738 | |
| 3739 | case llvm::bitc::ENTER_SUBBLOCK: |
| 3740 | Error("unexpected subblock record in preprocessor detail block"); |
| 3741 | return 0; |
| 3742 | |
| 3743 | case llvm::bitc::DEFINE_ABBREV: |
| 3744 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 3745 | return 0; |
| 3746 | |
| 3747 | default: |
| 3748 | break; |
| 3749 | } |
| 3750 | |
| 3751 | if (!PP.getPreprocessingRecord()) { |
| 3752 | Error("no preprocessing record"); |
| 3753 | return 0; |
| 3754 | } |
| 3755 | |
| 3756 | // Read the record. |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3757 | SourceRange Range(ReadSourceLocation(M, PPOffs.Begin), |
| 3758 | ReadSourceLocation(M, PPOffs.End)); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3759 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 3760 | const char *BlobStart = 0; |
| 3761 | unsigned BlobLen = 0; |
| 3762 | RecordData Record; |
| 3763 | PreprocessorDetailRecordTypes RecType = |
| 3764 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.ReadRecord( |
| 3765 | Code, Record, BlobStart, BlobLen); |
| 3766 | switch (RecType) { |
| 3767 | case PPD_MACRO_EXPANSION: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3768 | bool isBuiltin = Record[0]; |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3769 | IdentifierInfo *Name = 0; |
| 3770 | MacroDefinition *Def = 0; |
| 3771 | if (isBuiltin) |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3772 | Name = getLocalIdentifier(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3773 | else { |
| 3774 | PreprocessedEntityID |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3775 | GlobalID = getGlobalPreprocessedEntityID(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3776 | Def =cast<MacroDefinition>(PPRec.getLoadedPreprocessedEntity(GlobalID-1)); |
| 3777 | } |
| 3778 | |
| 3779 | MacroExpansion *ME; |
| 3780 | if (isBuiltin) |
| 3781 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 3782 | else |
| 3783 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 3784 | |
| 3785 | return ME; |
| 3786 | } |
| 3787 | |
| 3788 | case PPD_MACRO_DEFINITION: { |
| 3789 | // Decode the identifier info and then check again; if the macro is |
| 3790 | // still defined and associated with the identifier, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3791 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3792 | MacroDefinition *MD |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3793 | = new (PPRec) MacroDefinition(II, Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3794 | |
| 3795 | if (DeserializationListener) |
| 3796 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 3797 | |
| 3798 | return MD; |
| 3799 | } |
| 3800 | |
| 3801 | case PPD_INCLUSION_DIRECTIVE: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3802 | const char *FullFileNameStart = BlobStart + Record[0]; |
Argyrios Kyrtzidis | 29f98b4 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 3803 | StringRef FullFileName(FullFileNameStart, BlobLen - Record[0]); |
| 3804 | const FileEntry *File = 0; |
| 3805 | if (!FullFileName.empty()) |
| 3806 | File = PP.getFileManager().getFile(FullFileName); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3807 | |
| 3808 | // FIXME: Stable encoding |
| 3809 | InclusionDirective::InclusionKind Kind |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3810 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3811 | InclusionDirective *ID |
| 3812 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3813 | StringRef(BlobStart, Record[0]), |
Argyrios Kyrtzidis | 8dd927c | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 3814 | Record[1], Record[3], |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3815 | File, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3816 | Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3817 | return ID; |
| 3818 | } |
| 3819 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 3820 | |
| 3821 | llvm_unreachable("Invalid PreprocessorDetailRecordTypes"); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3822 | } |
| 3823 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3824 | /// \brief \arg SLocMapI points at a chunk of a module that contains no |
| 3825 | /// preprocessed entities or the entities it contains are not the ones we are |
| 3826 | /// looking for. Find the next module that contains entities and return the ID |
| 3827 | /// of the first entry. |
| 3828 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 3829 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 3830 | ++SLocMapI; |
| 3831 | for (GlobalSLocOffsetMapType::const_iterator |
| 3832 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3833 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3834 | if (M.NumPreprocessedEntities) |
Argyrios Kyrtzidis | ce25492 | 2012-11-02 02:31:22 +0000 | [diff] [blame] | 3835 | return M.BasePreprocessedEntityID; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | return getTotalNumPreprocessedEntities(); |
| 3839 | } |
| 3840 | |
| 3841 | namespace { |
| 3842 | |
| 3843 | template <unsigned PPEntityOffset::*PPLoc> |
| 3844 | struct PPEntityComp { |
| 3845 | const ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3846 | ModuleFile &M; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3847 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3848 | PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) { } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3849 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 3850 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 3851 | SourceLocation LHS = getLoc(L); |
| 3852 | SourceLocation RHS = getLoc(R); |
| 3853 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3854 | } |
| 3855 | |
| 3856 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3857 | SourceLocation LHS = getLoc(L); |
| 3858 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3859 | } |
| 3860 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 3861 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3862 | SourceLocation RHS = getLoc(R); |
| 3863 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3864 | } |
| 3865 | |
| 3866 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
| 3867 | return Reader.ReadSourceLocation(M, PPE.*PPLoc); |
| 3868 | } |
| 3869 | }; |
| 3870 | |
| 3871 | } |
| 3872 | |
| 3873 | /// \brief Returns the first preprocessed entity ID that ends after \arg BLoc. |
| 3874 | PreprocessedEntityID |
| 3875 | ASTReader::findBeginPreprocessedEntity(SourceLocation BLoc) const { |
| 3876 | if (SourceMgr.isLocalSourceLocation(BLoc)) |
| 3877 | return getTotalNumPreprocessedEntities(); |
| 3878 | |
| 3879 | GlobalSLocOffsetMapType::const_iterator |
| 3880 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 3881 | BLoc.getOffset()); |
| 3882 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 3883 | "Corrupted global sloc offset map"); |
| 3884 | |
| 3885 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 3886 | return findNextPreprocessedEntity(SLocMapI); |
| 3887 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3888 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3889 | typedef const PPEntityOffset *pp_iterator; |
| 3890 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 3891 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
Argyrios Kyrtzidis | 4cd0634 | 2011-09-22 21:17:02 +0000 | [diff] [blame] | 3892 | |
| 3893 | size_t Count = M.NumPreprocessedEntities; |
| 3894 | size_t Half; |
| 3895 | pp_iterator First = pp_begin; |
| 3896 | pp_iterator PPI; |
| 3897 | |
| 3898 | // Do a binary search manually instead of using std::lower_bound because |
| 3899 | // The end locations of entities may be unordered (when a macro expansion |
| 3900 | // is inside another macro argument), but for this case it is not important |
| 3901 | // whether we get the first macro expansion or its containing macro. |
| 3902 | while (Count > 0) { |
| 3903 | Half = Count/2; |
| 3904 | PPI = First; |
| 3905 | std::advance(PPI, Half); |
| 3906 | if (SourceMgr.isBeforeInTranslationUnit(ReadSourceLocation(M, PPI->End), |
| 3907 | BLoc)){ |
| 3908 | First = PPI; |
| 3909 | ++First; |
| 3910 | Count = Count - Half - 1; |
| 3911 | } else |
| 3912 | Count = Half; |
| 3913 | } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3914 | |
| 3915 | if (PPI == pp_end) |
| 3916 | return findNextPreprocessedEntity(SLocMapI); |
| 3917 | |
Argyrios Kyrtzidis | ce25492 | 2012-11-02 02:31:22 +0000 | [diff] [blame] | 3918 | return M.BasePreprocessedEntityID + (PPI - pp_begin); |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3919 | } |
| 3920 | |
| 3921 | /// \brief Returns the first preprocessed entity ID that begins after \arg ELoc. |
| 3922 | PreprocessedEntityID |
| 3923 | ASTReader::findEndPreprocessedEntity(SourceLocation ELoc) const { |
| 3924 | if (SourceMgr.isLocalSourceLocation(ELoc)) |
| 3925 | return getTotalNumPreprocessedEntities(); |
| 3926 | |
| 3927 | GlobalSLocOffsetMapType::const_iterator |
| 3928 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 3929 | ELoc.getOffset()); |
| 3930 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 3931 | "Corrupted global sloc offset map"); |
| 3932 | |
| 3933 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 3934 | return findNextPreprocessedEntity(SLocMapI); |
| 3935 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3936 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3937 | typedef const PPEntityOffset *pp_iterator; |
| 3938 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 3939 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 3940 | pp_iterator PPI = |
| 3941 | std::upper_bound(pp_begin, pp_end, ELoc, |
| 3942 | PPEntityComp<&PPEntityOffset::Begin>(*this, M)); |
| 3943 | |
| 3944 | if (PPI == pp_end) |
| 3945 | return findNextPreprocessedEntity(SLocMapI); |
| 3946 | |
Argyrios Kyrtzidis | ce25492 | 2012-11-02 02:31:22 +0000 | [diff] [blame] | 3947 | return M.BasePreprocessedEntityID + (PPI - pp_begin); |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | /// \brief Returns a pair of [Begin, End) indices of preallocated |
| 3951 | /// preprocessed entities that \arg Range encompasses. |
| 3952 | std::pair<unsigned, unsigned> |
| 3953 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 3954 | if (Range.isInvalid()) |
| 3955 | return std::make_pair(0,0); |
| 3956 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 3957 | |
| 3958 | PreprocessedEntityID BeginID = findBeginPreprocessedEntity(Range.getBegin()); |
| 3959 | PreprocessedEntityID EndID = findEndPreprocessedEntity(Range.getEnd()); |
| 3960 | return std::make_pair(BeginID, EndID); |
| 3961 | } |
| 3962 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3963 | /// \brief Optionally returns true or false if the preallocated preprocessed |
| 3964 | /// entity with index \arg Index came from file \arg FID. |
| 3965 | llvm::Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
| 3966 | FileID FID) { |
| 3967 | if (FID.isInvalid()) |
| 3968 | return false; |
| 3969 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3970 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 3971 | ModuleFile &M = *PPInfo.first; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3972 | unsigned LocalIndex = PPInfo.second; |
| 3973 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 3974 | |
| 3975 | SourceLocation Loc = ReadSourceLocation(M, PPOffs.Begin); |
| 3976 | if (Loc.isInvalid()) |
| 3977 | return false; |
| 3978 | |
| 3979 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 3980 | return true; |
| 3981 | else |
| 3982 | return false; |
| 3983 | } |
| 3984 | |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3985 | namespace { |
| 3986 | /// \brief Visitor used to search for information about a header file. |
| 3987 | class HeaderFileInfoVisitor { |
| 3988 | ASTReader &Reader; |
| 3989 | const FileEntry *FE; |
| 3990 | |
| 3991 | llvm::Optional<HeaderFileInfo> HFI; |
| 3992 | |
| 3993 | public: |
| 3994 | HeaderFileInfoVisitor(ASTReader &Reader, const FileEntry *FE) |
| 3995 | : Reader(Reader), FE(FE) { } |
| 3996 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3997 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3998 | HeaderFileInfoVisitor *This |
| 3999 | = static_cast<HeaderFileInfoVisitor *>(UserData); |
| 4000 | |
| 4001 | HeaderFileInfoTrait Trait(This->Reader, M, |
| 4002 | &This->Reader.getPreprocessor().getHeaderSearchInfo(), |
| 4003 | M.HeaderFileFrameworkStrings, |
| 4004 | This->FE->getName()); |
| 4005 | |
| 4006 | HeaderFileInfoLookupTable *Table |
| 4007 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 4008 | if (!Table) |
| 4009 | return false; |
| 4010 | |
| 4011 | // Look in the on-disk hash table for an entry for this file name. |
| 4012 | HeaderFileInfoLookupTable::iterator Pos = Table->find(This->FE->getName(), |
| 4013 | &Trait); |
| 4014 | if (Pos == Table->end()) |
| 4015 | return false; |
| 4016 | |
| 4017 | This->HFI = *Pos; |
| 4018 | return true; |
| 4019 | } |
| 4020 | |
| 4021 | llvm::Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| 4022 | }; |
| 4023 | } |
| 4024 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4025 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 4026 | HeaderFileInfoVisitor Visitor(*this, FE); |
| 4027 | ModuleMgr.visit(&HeaderFileInfoVisitor::visit, &Visitor); |
| 4028 | if (llvm::Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4029 | if (Listener) |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 4030 | Listener->ReadHeaderFileInfo(*HFI, FE->getUID()); |
| 4031 | return *HFI; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | return HeaderFileInfo(); |
| 4035 | } |
| 4036 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 4037 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
Argyrios Kyrtzidis | 33e1576 | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 4038 | // FIXME: Make it work properly with modules. |
| 4039 | llvm::SmallVector<DiagnosticsEngine::DiagState *, 32> DiagStates; |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4040 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4041 | ModuleFile &F = *(*I); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4042 | unsigned Idx = 0; |
Argyrios Kyrtzidis | 33e1576 | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 4043 | DiagStates.clear(); |
| 4044 | assert(!Diag.DiagStates.empty()); |
| 4045 | DiagStates.push_back(&Diag.DiagStates.front()); // the command-line one. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4046 | while (Idx < F.PragmaDiagMappings.size()) { |
| 4047 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
Argyrios Kyrtzidis | 33e1576 | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 4048 | unsigned DiagStateID = F.PragmaDiagMappings[Idx++]; |
| 4049 | if (DiagStateID != 0) { |
| 4050 | Diag.DiagStatePoints.push_back( |
| 4051 | DiagnosticsEngine::DiagStatePoint(DiagStates[DiagStateID-1], |
| 4052 | FullSourceLoc(Loc, SourceMgr))); |
| 4053 | continue; |
| 4054 | } |
| 4055 | |
| 4056 | assert(DiagStateID == 0); |
| 4057 | // A new DiagState was created here. |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 4058 | Diag.DiagStates.push_back(*Diag.GetCurDiagState()); |
Argyrios Kyrtzidis | 33e1576 | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 4059 | DiagnosticsEngine::DiagState *NewState = &Diag.DiagStates.back(); |
| 4060 | DiagStates.push_back(NewState); |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 4061 | Diag.DiagStatePoints.push_back( |
Argyrios Kyrtzidis | 33e1576 | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 4062 | DiagnosticsEngine::DiagStatePoint(NewState, |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 4063 | FullSourceLoc(Loc, SourceMgr))); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4064 | while (1) { |
| 4065 | assert(Idx < F.PragmaDiagMappings.size() && |
| 4066 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 4067 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 4068 | break; // Something is messed up but at least avoid infinite loop in |
| 4069 | // release build. |
| 4070 | } |
| 4071 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 4072 | if (DiagID == (unsigned)-1) { |
| 4073 | break; // no more diag/map pairs for this location. |
| 4074 | } |
| 4075 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 4076 | DiagnosticMappingInfo MappingInfo = Diag.makeMappingInfo(Map, Loc); |
| 4077 | Diag.GetCurDiagState()->setMappingInfo(DiagID, MappingInfo); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4078 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 4079 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 4080 | } |
| 4081 | } |
| 4082 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4083 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4084 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4085 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | e9b76c1 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 4086 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4087 | ModuleFile *M = I->second; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 4088 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4089 | } |
| 4090 | |
| 4091 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4092 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4093 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 4094 | /// routine actually reads the record corresponding to the type at the given |
| 4095 | /// location. It is a helper routine for GetType, which deals with reading type |
| 4096 | /// IDs. |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4097 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4098 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4099 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 4100 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 4101 | // Keep track of where we are in the stream, then jump back there |
| 4102 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4103 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 4104 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4105 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 4106 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4107 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4108 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4109 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4110 | unsigned Idx = 0; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4111 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4112 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4113 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4114 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 4115 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4116 | if (Record.size() != 2) { |
| 4117 | Error("Incorrect encoding of extended qualifier type"); |
| 4118 | return QualType(); |
| 4119 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4120 | QualType Base = readType(*Loc.F, Record, Idx); |
| 4121 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4122 | return Context.getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 4123 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4124 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4125 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4126 | if (Record.size() != 1) { |
| 4127 | Error("Incorrect encoding of complex type"); |
| 4128 | return QualType(); |
| 4129 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4130 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4131 | return Context.getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4132 | } |
| 4133 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4134 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4135 | if (Record.size() != 1) { |
| 4136 | Error("Incorrect encoding of pointer type"); |
| 4137 | return QualType(); |
| 4138 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4139 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4140 | return Context.getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4141 | } |
| 4142 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4143 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4144 | if (Record.size() != 1) { |
| 4145 | Error("Incorrect encoding of block pointer type"); |
| 4146 | return QualType(); |
| 4147 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4148 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4149 | return Context.getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4150 | } |
| 4151 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4152 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 4153 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4154 | Error("Incorrect encoding of lvalue reference type"); |
| 4155 | return QualType(); |
| 4156 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4157 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4158 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4159 | } |
| 4160 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4161 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4162 | if (Record.size() != 1) { |
| 4163 | Error("Incorrect encoding of rvalue reference type"); |
| 4164 | return QualType(); |
| 4165 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4166 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4167 | return Context.getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4168 | } |
| 4169 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4170 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 4171 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4172 | Error("Incorrect encoding of member pointer type"); |
| 4173 | return QualType(); |
| 4174 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4175 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 4176 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 4177 | if (PointeeType.isNull() || ClassType.isNull()) |
| 4178 | return QualType(); |
| 4179 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4180 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4181 | } |
| 4182 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4183 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4184 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4185 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 4186 | unsigned IndexTypeQuals = Record[2]; |
| 4187 | unsigned Idx = 3; |
| 4188 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4189 | return Context.getConstantArrayType(ElementType, Size, |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 4190 | ASM, IndexTypeQuals); |
| 4191 | } |
| 4192 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4193 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4194 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4195 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 4196 | unsigned IndexTypeQuals = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4197 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4198 | } |
| 4199 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4200 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4201 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 4202 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 4203 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4204 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 4205 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4206 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 4207 | ASM, IndexTypeQuals, |
| 4208 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4209 | } |
| 4210 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4211 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 4212 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4213 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4214 | return QualType(); |
| 4215 | } |
| 4216 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4217 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4218 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4219 | unsigned VecKind = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4220 | return Context.getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4221 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4222 | } |
| 4223 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4224 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 4225 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4226 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4227 | return QualType(); |
| 4228 | } |
| 4229 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4230 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4231 | unsigned NumElements = Record[1]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4232 | return Context.getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4233 | } |
| 4234 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4235 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4236 | if (Record.size() != 6) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4237 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4238 | return QualType(); |
| 4239 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4240 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4241 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 4242 | (CallingConv)Record[4], Record[5]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4243 | return Context.getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4244 | } |
| 4245 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4246 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4247 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4248 | |
| 4249 | FunctionProtoType::ExtProtoInfo EPI; |
| 4250 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 4251 | /*hasregparm*/ Record[2], |
| 4252 | /*regparm*/ Record[3], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4253 | static_cast<CallingConv>(Record[4]), |
| 4254 | /*produces*/ Record[5]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4255 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4256 | unsigned Idx = 6; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4257 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4258 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4259 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4260 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4261 | |
| 4262 | EPI.Variadic = Record[Idx++]; |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 4263 | EPI.HasTrailingReturn = Record[Idx++]; |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4264 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 4265 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4266 | ExceptionSpecificationType EST = |
| 4267 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 4268 | EPI.ExceptionSpecType = EST; |
Douglas Gregor | b0d06e2 | 2012-04-04 00:34:49 +0000 | [diff] [blame] | 4269 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4270 | if (EST == EST_Dynamic) { |
| 4271 | EPI.NumExceptions = Record[Idx++]; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4272 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4273 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4274 | EPI.Exceptions = Exceptions.data(); |
| 4275 | } else if (EST == EST_ComputedNoexcept) { |
| 4276 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
Richard Smith | 7bb698a | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 4277 | } else if (EST == EST_Uninstantiated) { |
| 4278 | EPI.ExceptionSpecDecl = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
| 4279 | EPI.ExceptionSpecTemplate = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
Richard Smith | b9d0b76 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 4280 | } else if (EST == EST_Unevaluated) { |
| 4281 | EPI.ExceptionSpecDecl = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 4282 | } |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4283 | return Context.getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 4284 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4285 | } |
| 4286 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4287 | case TYPE_UNRESOLVED_USING: { |
| 4288 | unsigned Idx = 0; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4289 | return Context.getTypeDeclType( |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4290 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 4291 | } |
| 4292 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4293 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 4294 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4295 | Error("incorrect encoding of typedef type"); |
| 4296 | return QualType(); |
| 4297 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4298 | unsigned Idx = 0; |
| 4299 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4300 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 4301 | if (!Canonical.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4302 | Canonical = Context.getCanonicalType(Canonical); |
| 4303 | return Context.getTypedefType(Decl, Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 4304 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4305 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4306 | case TYPE_TYPEOF_EXPR: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4307 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4308 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4309 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4310 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4311 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4312 | return QualType(); |
| 4313 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4314 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4315 | return Context.getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4316 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4317 | |
Douglas Gregor | f8af982 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 4318 | case TYPE_DECLTYPE: { |
| 4319 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 4320 | return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType); |
| 4321 | } |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 4322 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4323 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4324 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 4325 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4326 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4327 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4328 | } |
| 4329 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4330 | case TYPE_AUTO: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4331 | return Context.getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4332 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4333 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4334 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4335 | Error("incorrect encoding of record type"); |
| 4336 | return QualType(); |
| 4337 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4338 | unsigned Idx = 0; |
| 4339 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 4340 | RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx); |
| 4341 | RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl()); |
| 4342 | QualType T = Context.getRecordType(RD); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4343 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4344 | return T; |
| 4345 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4346 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4347 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4348 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4349 | Error("incorrect encoding of enum type"); |
| 4350 | return QualType(); |
| 4351 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4352 | unsigned Idx = 0; |
| 4353 | bool IsDependent = Record[Idx++]; |
| 4354 | QualType T |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4355 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4356 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4357 | return T; |
| 4358 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4359 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4360 | case TYPE_ATTRIBUTED: { |
| 4361 | if (Record.size() != 3) { |
| 4362 | Error("incorrect encoding of attributed type"); |
| 4363 | return QualType(); |
| 4364 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4365 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 4366 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4367 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4368 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4371 | case TYPE_PAREN: { |
| 4372 | if (Record.size() != 1) { |
| 4373 | Error("incorrect encoding of paren type"); |
| 4374 | return QualType(); |
| 4375 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4376 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4377 | return Context.getParenType(InnerType); |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4378 | } |
| 4379 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4380 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 4381 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4382 | Error("incorrect encoding of pack expansion type"); |
| 4383 | return QualType(); |
| 4384 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4385 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4386 | if (Pattern.isNull()) |
| 4387 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4388 | llvm::Optional<unsigned> NumExpansions; |
| 4389 | if (Record[1]) |
| 4390 | NumExpansions = Record[1] - 1; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4391 | return Context.getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4392 | } |
| 4393 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4394 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4395 | unsigned Idx = 0; |
| 4396 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4397 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4398 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4399 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4400 | } |
| 4401 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4402 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4403 | unsigned Idx = 0; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4404 | ObjCInterfaceDecl *ItfD |
| 4405 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 4406 | return Context.getObjCInterfaceType(ItfD->getCanonicalDecl()); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4407 | } |
| 4408 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4409 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4410 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4411 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4412 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4413 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4414 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4415 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4416 | return Context.getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4417 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4418 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4419 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 4420 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4421 | QualType Pointee = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4422 | return Context.getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 4423 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4424 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4425 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4426 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4427 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 4428 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4429 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4430 | Context.getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4431 | Replacement); |
| 4432 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4433 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4434 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 4435 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4436 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4437 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4438 | return Context.getSubstTemplateTypeParmPackType( |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4439 | cast<TemplateTypeParmType>(Parm), |
| 4440 | ArgPack); |
| 4441 | } |
| 4442 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4443 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4444 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4445 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 4446 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4447 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 4448 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4449 | QualType(new (Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4450 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4451 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4452 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4453 | unsigned Idx = 0; |
| 4454 | unsigned Depth = Record[Idx++]; |
| 4455 | unsigned Index = Record[Idx++]; |
| 4456 | bool Pack = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4457 | TemplateTypeParmDecl *D |
| 4458 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4459 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4460 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4461 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4462 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 4463 | unsigned Idx = 0; |
| 4464 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4465 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4466 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4467 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 4468 | if (!Canon.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4469 | Canon = Context.getCanonicalType(Canon); |
| 4470 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 4471 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4472 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4473 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4474 | unsigned Idx = 0; |
| 4475 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4476 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4477 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4478 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4479 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4480 | Args.reserve(NumArgs); |
| 4481 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4482 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4483 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4484 | Args.size(), Args.data()); |
| 4485 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4486 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4487 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4488 | unsigned Idx = 0; |
| 4489 | |
| 4490 | // ArrayType |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4491 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4492 | ArrayType::ArraySizeModifier ASM |
| 4493 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 4494 | unsigned IndexTypeQuals = Record[Idx++]; |
| 4495 | |
| 4496 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4497 | Expr *NumElts = ReadExpr(*Loc.F); |
| 4498 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4499 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4500 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4501 | IndexTypeQuals, Brackets); |
| 4502 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4503 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4504 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4505 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4506 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4507 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4508 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4509 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4510 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4511 | QualType T; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4512 | if (Underlying.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4513 | T = Context.getCanonicalTemplateSpecializationType(Name, Args.data(), |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4514 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 4515 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4516 | T = Context.getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4517 | Args.size(), Underlying); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4518 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4519 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4520 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4521 | |
| 4522 | case TYPE_ATOMIC: { |
| 4523 | if (Record.size() != 1) { |
| 4524 | Error("Incorrect encoding of atomic type"); |
| 4525 | return QualType(); |
| 4526 | } |
| 4527 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 4528 | return Context.getAtomicType(ValueType); |
| 4529 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4530 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 4531 | llvm_unreachable("Invalid TypeCode!"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4532 | } |
| 4533 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4534 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4535 | ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4536 | ModuleFile &F; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4537 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4538 | unsigned &Idx; |
| 4539 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4540 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 4541 | unsigned &I) { |
| 4542 | return Reader.ReadSourceLocation(F, R, I); |
| 4543 | } |
| 4544 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4545 | template<typename T> |
| 4546 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 4547 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 4548 | } |
| 4549 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4550 | public: |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4551 | TypeLocReader(ASTReader &Reader, ModuleFile &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4552 | const ASTReader::RecordData &Record, unsigned &Idx) |
Benjamin Kramer | facde17 | 2012-06-06 17:32:50 +0000 | [diff] [blame] | 4553 | : Reader(Reader), F(F), Record(Record), Idx(Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4554 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4555 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4556 | // We want compile-time assurance that we've enumerated all of |
| 4557 | // these, so unfortunately we have to declare them first, then |
| 4558 | // define them out-of-line. |
| 4559 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4560 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4561 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4562 | #include "clang/AST/TypeLocNodes.def" |
| 4563 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4564 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 4565 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4566 | }; |
| 4567 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4568 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4569 | // nothing to do |
| 4570 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4571 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4572 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 4573 | if (TL.needsExtraLocalData()) { |
| 4574 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 4575 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 4576 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 4577 | TL.setModeAttr(Record[Idx++]); |
| 4578 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4579 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4580 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4581 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4582 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4583 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4584 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4585 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4586 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4587 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4588 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4589 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4590 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4591 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4592 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4593 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4594 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4595 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4596 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4597 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4598 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4599 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4600 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 4601 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4602 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4603 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4604 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4605 | TL.setSizeExpr(0); |
| 4606 | } |
| 4607 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 4608 | VisitArrayTypeLoc(TL); |
| 4609 | } |
| 4610 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 4611 | VisitArrayTypeLoc(TL); |
| 4612 | } |
| 4613 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 4614 | VisitArrayTypeLoc(TL); |
| 4615 | } |
| 4616 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 4617 | DependentSizedArrayTypeLoc TL) { |
| 4618 | VisitArrayTypeLoc(TL); |
| 4619 | } |
| 4620 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 4621 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4622 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4623 | } |
| 4624 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4625 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4626 | } |
| 4627 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4628 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4629 | } |
| 4630 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4631 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4632 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4633 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4634 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4635 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4636 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 4640 | VisitFunctionTypeLoc(TL); |
| 4641 | } |
| 4642 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 4643 | VisitFunctionTypeLoc(TL); |
| 4644 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4645 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4646 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4647 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4648 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4649 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4650 | } |
| 4651 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4652 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 4653 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4654 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4655 | } |
| 4656 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4657 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 4658 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4659 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4660 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4661 | } |
| 4662 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4663 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4664 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4665 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 4666 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 4667 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4668 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4669 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 4670 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4671 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 4672 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 4673 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4674 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4675 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4676 | } |
| 4677 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4678 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4679 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4680 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 4681 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 4682 | if (TL.hasAttrOperand()) { |
| 4683 | SourceRange range; |
| 4684 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 4685 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 4686 | TL.setAttrOperandParensRange(range); |
| 4687 | } |
| 4688 | if (TL.hasAttrExprOperand()) { |
| 4689 | if (Record[Idx++]) |
| 4690 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 4691 | else |
| 4692 | TL.setAttrExprOperand(0); |
| 4693 | } else if (TL.hasAttrEnumOperand()) |
| 4694 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 4695 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4696 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4697 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4698 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4699 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 4700 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4701 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4702 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4703 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 4704 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4705 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 4706 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4707 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 4708 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4709 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4710 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 4711 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4712 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4713 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 4714 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4715 | Reader.GetTemplateArgumentLocInfo(F, |
| 4716 | TL.getTypePtr()->getArg(i).getKind(), |
| 4717 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4718 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4719 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 4720 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4721 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4722 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4723 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4724 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4725 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4726 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4727 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4728 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4729 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4730 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4731 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4732 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4733 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4734 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4735 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 4736 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4737 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4738 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4739 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4740 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4741 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4742 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4743 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 4744 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4745 | Reader.GetTemplateArgumentLocInfo(F, |
| 4746 | TL.getTypePtr()->getArg(I).getKind(), |
| 4747 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4748 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4749 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 4750 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 4751 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4752 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4753 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4754 | } |
| 4755 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 4756 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4757 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4758 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4759 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4760 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4761 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 4762 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4763 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 4764 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4765 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 4766 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 4767 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4768 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4769 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4770 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4771 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4772 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4773 | unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4774 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4775 | if (InfoTy.isNull()) |
| 4776 | return 0; |
| 4777 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4778 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4779 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4780 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4781 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4782 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4783 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4784 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4785 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4786 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 4787 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4788 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4789 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4790 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4791 | switch ((PredefinedTypeIDs)Index) { |
| 4792 | case PREDEF_TYPE_NULL_ID: return QualType(); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4793 | case PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; |
| 4794 | case PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4795 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4796 | case PREDEF_TYPE_CHAR_U_ID: |
| 4797 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4798 | // FIXME: Check that the signedness of CharTy is correct! |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4799 | T = Context.CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4800 | break; |
| 4801 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4802 | case PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; |
| 4803 | case PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; |
| 4804 | case PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; |
| 4805 | case PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; |
| 4806 | case PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; |
| 4807 | case PREDEF_TYPE_UINT128_ID: T = Context.UnsignedInt128Ty; break; |
| 4808 | case PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; |
| 4809 | case PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; |
| 4810 | case PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; |
| 4811 | case PREDEF_TYPE_INT_ID: T = Context.IntTy; break; |
| 4812 | case PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; |
| 4813 | case PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; |
| 4814 | case PREDEF_TYPE_INT128_ID: T = Context.Int128Ty; break; |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 4815 | case PREDEF_TYPE_HALF_ID: T = Context.HalfTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4816 | case PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; |
| 4817 | case PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; |
| 4818 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; |
| 4819 | case PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; |
| 4820 | case PREDEF_TYPE_BOUND_MEMBER: T = Context.BoundMemberTy; break; |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 4821 | case PREDEF_TYPE_PSEUDO_OBJECT: T = Context.PseudoObjectTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4822 | case PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; |
| 4823 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context.UnknownAnyTy; break; |
| 4824 | case PREDEF_TYPE_NULLPTR_ID: T = Context.NullPtrTy; break; |
| 4825 | case PREDEF_TYPE_CHAR16_ID: T = Context.Char16Ty; break; |
| 4826 | case PREDEF_TYPE_CHAR32_ID: T = Context.Char32Ty; break; |
| 4827 | case PREDEF_TYPE_OBJC_ID: T = Context.ObjCBuiltinIdTy; break; |
| 4828 | case PREDEF_TYPE_OBJC_CLASS: T = Context.ObjCBuiltinClassTy; break; |
| 4829 | case PREDEF_TYPE_OBJC_SEL: T = Context.ObjCBuiltinSelTy; break; |
| 4830 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4831 | |
| 4832 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4833 | T = Context.getAutoRRefDeductType(); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4834 | break; |
John McCall | 0ddaeb9 | 2011-10-17 18:09:15 +0000 | [diff] [blame] | 4835 | |
| 4836 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 4837 | T = Context.ARCUnbridgedCastTy; |
| 4838 | break; |
| 4839 | |
Meador Inge | fb40e3f | 2012-07-01 15:57:25 +0000 | [diff] [blame] | 4840 | case PREDEF_TYPE_VA_LIST_TAG: |
| 4841 | T = Context.getVaListTagType(); |
| 4842 | break; |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 4843 | |
| 4844 | case PREDEF_TYPE_BUILTIN_FN: |
| 4845 | T = Context.BuiltinFnTy; |
| 4846 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4850 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4851 | } |
| 4852 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4853 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4854 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4855 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4856 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4857 | if (TypesLoaded[Index].isNull()) |
| 4858 | return QualType(); |
| 4859 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4860 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4861 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4862 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 4863 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4864 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4865 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4866 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4867 | } |
| 4868 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4869 | QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4870 | return GetType(getGlobalTypeID(F, LocalID)); |
| 4871 | } |
| 4872 | |
| 4873 | serialization::TypeID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4874 | ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4875 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 4876 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 4877 | |
| 4878 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 4879 | return LocalID; |
| 4880 | |
| 4881 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4882 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 4883 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 4884 | |
| 4885 | unsigned GlobalIndex = LocalIndex + I->second; |
| 4886 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 4887 | } |
| 4888 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4889 | TemplateArgumentLocInfo |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4890 | ASTReader::GetTemplateArgumentLocInfo(ModuleFile &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4891 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4892 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4893 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4894 | switch (Kind) { |
| 4895 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4896 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4897 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4898 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4899 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4900 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4901 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4902 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4903 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4904 | SourceLocation()); |
| 4905 | } |
| 4906 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4907 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4908 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4909 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4910 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4911 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4912 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4913 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4914 | case TemplateArgument::Null: |
| 4915 | case TemplateArgument::Integral: |
| 4916 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4917 | case TemplateArgument::NullPtr: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4918 | case TemplateArgument::Pack: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4919 | // FIXME: Is this right? |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4920 | return TemplateArgumentLocInfo(); |
| 4921 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 4922 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4923 | } |
| 4924 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4925 | TemplateArgumentLoc |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4926 | ASTReader::ReadTemplateArgumentLoc(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4927 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4928 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4929 | |
| 4930 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 4931 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 4932 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 4933 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4934 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4935 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4936 | } |
| 4937 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4938 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4939 | return GetDecl(ID); |
| 4940 | } |
| 4941 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4942 | uint64_t ASTReader::readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4943 | unsigned &Idx){ |
| 4944 | if (Idx >= Record.size()) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4945 | return 0; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4946 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4947 | unsigned LocalID = Record[Idx++]; |
| 4948 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4949 | } |
| 4950 | |
| 4951 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4952 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4953 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4954 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4955 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4956 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 4957 | RecordData Record; |
| 4958 | unsigned Code = Cursor.ReadCode(); |
| 4959 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 4960 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 4961 | Error("Malformed AST file: missing C++ base specifiers"); |
| 4962 | return 0; |
| 4963 | } |
| 4964 | |
| 4965 | unsigned Idx = 0; |
| 4966 | unsigned NumBases = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4967 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4968 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 4969 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4970 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4971 | return Bases; |
| 4972 | } |
| 4973 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4974 | serialization::DeclID |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 4975 | ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4976 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4977 | return LocalID; |
| 4978 | |
| 4979 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4980 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4981 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 4982 | |
| 4983 | return LocalID + I->second; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4984 | } |
| 4985 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4986 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4987 | ModuleFile &M) const { |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4988 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(ID); |
| 4989 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4990 | return &M == I->second; |
| 4991 | } |
| 4992 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4993 | ModuleFile *ASTReader::getOwningModuleFile(Decl *D) { |
| 4994 | if (!D->isFromASTFile()) |
| 4995 | return 0; |
| 4996 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID()); |
| 4997 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4998 | return I->second; |
| 4999 | } |
| 5000 | |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5001 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 5002 | if (ID < NUM_PREDEF_DECL_IDS) |
| 5003 | return SourceLocation(); |
| 5004 | |
| 5005 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 5006 | |
| 5007 | if (Index > DeclsLoaded.size()) { |
| 5008 | Error("declaration ID out-of-range for AST file"); |
| 5009 | return SourceLocation(); |
| 5010 | } |
| 5011 | |
| 5012 | if (Decl *D = DeclsLoaded[Index]) |
| 5013 | return D->getLocation(); |
| 5014 | |
| 5015 | unsigned RawLocation = 0; |
| 5016 | RecordLocation Rec = DeclCursorForID(ID, RawLocation); |
| 5017 | return ReadSourceLocation(*Rec.F, RawLocation); |
| 5018 | } |
| 5019 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5020 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5021 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 5022 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5023 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5024 | return 0; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5025 | |
| 5026 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5027 | return Context.getTranslationUnitDecl(); |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 5028 | |
| 5029 | case PREDEF_DECL_OBJC_ID_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5030 | return Context.getObjCIdDecl(); |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 5031 | |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 5032 | case PREDEF_DECL_OBJC_SEL_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5033 | return Context.getObjCSelDecl(); |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 5034 | |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 5035 | case PREDEF_DECL_OBJC_CLASS_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5036 | return Context.getObjCClassDecl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 5037 | |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 5038 | case PREDEF_DECL_OBJC_PROTOCOL_ID: |
| 5039 | return Context.getObjCProtocolDecl(); |
| 5040 | |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 5041 | case PREDEF_DECL_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5042 | return Context.getInt128Decl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 5043 | |
| 5044 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5045 | return Context.getUInt128Decl(); |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 5046 | |
| 5047 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5048 | return Context.getObjCInstanceTypeDecl(); |
Meador Inge | c5613b2 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 5049 | |
| 5050 | case PREDEF_DECL_BUILTIN_VA_LIST_ID: |
| 5051 | return Context.getBuiltinVaListDecl(); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5052 | } |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 5053 | } |
| 5054 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5055 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 5056 | |
Richard Smith | 2fbf373 | 2011-12-20 04:39:57 +0000 | [diff] [blame] | 5057 | if (Index >= DeclsLoaded.size()) { |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5058 | assert(0 && "declaration ID out-of-range for AST file"); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5059 | Error("declaration ID out-of-range for AST file"); |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5060 | return 0; |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5061 | } |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5062 | |
Douglas Gregor | fd002a7 | 2011-12-16 22:37:11 +0000 | [diff] [blame] | 5063 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5064 | ReadDeclRecord(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5065 | if (DeserializationListener) |
| 5066 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 5067 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5068 | |
| 5069 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5070 | } |
| 5071 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 5072 | DeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
| 5073 | DeclID GlobalID) { |
| 5074 | if (GlobalID < NUM_PREDEF_DECL_IDS) |
| 5075 | return GlobalID; |
| 5076 | |
| 5077 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID); |
| 5078 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 5079 | ModuleFile *Owner = I->second; |
| 5080 | |
| 5081 | llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos |
| 5082 | = M.GlobalToLocalDeclIDs.find(Owner); |
| 5083 | if (Pos == M.GlobalToLocalDeclIDs.end()) |
| 5084 | return 0; |
| 5085 | |
| 5086 | return GlobalID - Owner->BaseDeclID + Pos->second; |
| 5087 | } |
| 5088 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5089 | serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5090 | const RecordData &Record, |
| 5091 | unsigned &Idx) { |
| 5092 | if (Idx >= Record.size()) { |
| 5093 | Error("Corrupted AST file"); |
| 5094 | return 0; |
| 5095 | } |
| 5096 | |
| 5097 | return getGlobalDeclID(F, Record[Idx++]); |
| 5098 | } |
| 5099 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 5100 | /// \brief Resolve the offset of a statement into a statement. |
| 5101 | /// |
| 5102 | /// This operation will read a new statement from the external |
| 5103 | /// source each time it is called, and is meant to be used via a |
| 5104 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5105 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 5106 | // Switch case IDs are per Decl. |
| 5107 | ClearSwitchCaseIDs(); |
| 5108 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 5109 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5110 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 5111 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 5112 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 5113 | } |
| 5114 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5115 | namespace { |
| 5116 | class FindExternalLexicalDeclsVisitor { |
| 5117 | ASTReader &Reader; |
| 5118 | const DeclContext *DC; |
| 5119 | bool (*isKindWeWant)(Decl::Kind); |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 5120 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5121 | SmallVectorImpl<Decl*> &Decls; |
| 5122 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 5123 | |
| 5124 | public: |
| 5125 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 5126 | bool (*isKindWeWant)(Decl::Kind), |
| 5127 | SmallVectorImpl<Decl*> &Decls) |
| 5128 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 5129 | { |
| 5130 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 5131 | PredefsVisited[I] = false; |
| 5132 | } |
| 5133 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5134 | static bool visit(ModuleFile &M, bool Preorder, void *UserData) { |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5135 | if (Preorder) |
| 5136 | return false; |
| 5137 | |
| 5138 | FindExternalLexicalDeclsVisitor *This |
| 5139 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 5140 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5141 | ModuleFile::DeclContextInfosMap::iterator Info |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5142 | = M.DeclContextInfos.find(This->DC); |
| 5143 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 5144 | return false; |
| 5145 | |
| 5146 | // Load all of the declaration IDs |
| 5147 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 5148 | *IDE = ID + Info->second.NumLexicalDecls; |
| 5149 | ID != IDE; ++ID) { |
| 5150 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 5151 | continue; |
| 5152 | |
| 5153 | // Don't add predefined declarations to the lexical context more |
| 5154 | // than once. |
| 5155 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 5156 | if (This->PredefsVisited[ID->second]) |
| 5157 | continue; |
| 5158 | |
| 5159 | This->PredefsVisited[ID->second] = true; |
| 5160 | } |
| 5161 | |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 5162 | if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) { |
| 5163 | if (!This->DC->isDeclInLexicalTraversal(D)) |
| 5164 | This->Decls.push_back(D); |
| 5165 | } |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | return false; |
| 5169 | } |
| 5170 | }; |
| 5171 | } |
| 5172 | |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 5173 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 5174 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5175 | SmallVectorImpl<Decl*> &Decls) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5176 | // There might be lexical decls in multiple modules, for the TU at |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5177 | // least. Walk all of the modules in the order they were loaded. |
| 5178 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 5179 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 5180 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 5181 | return ELR_Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5182 | } |
| 5183 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5184 | namespace { |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5185 | |
| 5186 | class DeclIDComp { |
| 5187 | ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5188 | ModuleFile &Mod; |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5189 | |
| 5190 | public: |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5191 | DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {} |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5192 | |
| 5193 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 5194 | SourceLocation LHS = getLocation(L); |
| 5195 | SourceLocation RHS = getLocation(R); |
| 5196 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5197 | } |
| 5198 | |
| 5199 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 5200 | SourceLocation RHS = getLocation(R); |
| 5201 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5202 | } |
| 5203 | |
| 5204 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 5205 | SourceLocation LHS = getLocation(L); |
| 5206 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5207 | } |
| 5208 | |
| 5209 | SourceLocation getLocation(LocalDeclID ID) const { |
| 5210 | return Reader.getSourceManager().getFileLoc( |
| 5211 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 5212 | } |
| 5213 | }; |
| 5214 | |
| 5215 | } |
| 5216 | |
| 5217 | void ASTReader::FindFileRegionDecls(FileID File, |
| 5218 | unsigned Offset, unsigned Length, |
| 5219 | SmallVectorImpl<Decl *> &Decls) { |
| 5220 | SourceManager &SM = getSourceManager(); |
| 5221 | |
| 5222 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 5223 | if (I == FileDeclIDs.end()) |
| 5224 | return; |
| 5225 | |
| 5226 | FileDeclsInfo &DInfo = I->second; |
| 5227 | if (DInfo.Decls.empty()) |
| 5228 | return; |
| 5229 | |
| 5230 | SourceLocation |
| 5231 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 5232 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 5233 | |
| 5234 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 5235 | ArrayRef<serialization::LocalDeclID>::iterator |
| 5236 | BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 5237 | BeginLoc, DIDComp); |
| 5238 | if (BeginIt != DInfo.Decls.begin()) |
| 5239 | --BeginIt; |
| 5240 | |
Argyrios Kyrtzidis | c14a03d | 2011-11-23 20:27:36 +0000 | [diff] [blame] | 5241 | // If we are pointing at a top-level decl inside an objc container, we need |
| 5242 | // to backtrack until we find it otherwise we will fail to report that the |
| 5243 | // region overlaps with an objc container. |
| 5244 | while (BeginIt != DInfo.Decls.begin() && |
| 5245 | GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt)) |
| 5246 | ->isTopLevelDeclInObjCContainer()) |
| 5247 | --BeginIt; |
| 5248 | |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 5249 | ArrayRef<serialization::LocalDeclID>::iterator |
| 5250 | EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 5251 | EndLoc, DIDComp); |
| 5252 | if (EndIt != DInfo.Decls.end()) |
| 5253 | ++EndIt; |
| 5254 | |
| 5255 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 5256 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 5257 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 5258 | } |
| 5259 | |
| 5260 | namespace { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5261 | /// \brief ModuleFile visitor used to perform name lookup into a |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5262 | /// declaration context. |
| 5263 | class DeclContextNameLookupVisitor { |
| 5264 | ASTReader &Reader; |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5265 | llvm::SmallVectorImpl<const DeclContext *> &Contexts; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5266 | DeclarationName Name; |
| 5267 | SmallVectorImpl<NamedDecl *> &Decls; |
| 5268 | |
| 5269 | public: |
| 5270 | DeclContextNameLookupVisitor(ASTReader &Reader, |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5271 | SmallVectorImpl<const DeclContext *> &Contexts, |
| 5272 | DeclarationName Name, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5273 | SmallVectorImpl<NamedDecl *> &Decls) |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5274 | : Reader(Reader), Contexts(Contexts), Name(Name), Decls(Decls) { } |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5275 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5276 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5277 | DeclContextNameLookupVisitor *This |
| 5278 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 5279 | |
| 5280 | // Check whether we have any visible declaration information for |
| 5281 | // this context in this module. |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5282 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 5283 | bool FoundInfo = false; |
| 5284 | for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) { |
| 5285 | Info = M.DeclContextInfos.find(This->Contexts[I]); |
| 5286 | if (Info != M.DeclContextInfos.end() && |
| 5287 | Info->second.NameLookupTableData) { |
| 5288 | FoundInfo = true; |
| 5289 | break; |
| 5290 | } |
| 5291 | } |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5292 | |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5293 | if (!FoundInfo) |
| 5294 | return false; |
| 5295 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5296 | // Look for this name within this module. |
| 5297 | ASTDeclContextNameLookupTable *LookupTable = |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 5298 | Info->second.NameLookupTableData; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5299 | ASTDeclContextNameLookupTable::iterator Pos |
| 5300 | = LookupTable->find(This->Name); |
| 5301 | if (Pos == LookupTable->end()) |
| 5302 | return false; |
| 5303 | |
| 5304 | bool FoundAnything = false; |
| 5305 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 5306 | for (; Data.first != Data.second; ++Data.first) { |
| 5307 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 5308 | if (!ND) |
| 5309 | continue; |
| 5310 | |
| 5311 | if (ND->getDeclName() != This->Name) { |
Axel Naumann | 3dd82f7 | 2012-10-01 09:51:27 +0000 | [diff] [blame] | 5312 | // A name might be null because the decl's redeclarable part is |
| 5313 | // currently read before reading its name. The lookup is triggered by |
| 5314 | // building that decl (likely indirectly), and so it is later in the |
| 5315 | // sense of "already existing" and can be ignored here. |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5316 | continue; |
| 5317 | } |
| 5318 | |
| 5319 | // Record this declaration. |
| 5320 | FoundAnything = true; |
| 5321 | This->Decls.push_back(ND); |
| 5322 | } |
| 5323 | |
| 5324 | return FoundAnything; |
| 5325 | } |
| 5326 | }; |
| 5327 | } |
| 5328 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5329 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5330 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5331 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5332 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5333 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 5334 | if (!Name) |
| 5335 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 5336 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 5337 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5338 | SmallVector<NamedDecl *, 64> Decls; |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5339 | |
| 5340 | // Compute the declaration contexts we need to look into. Multiple such |
| 5341 | // declaration contexts occur when two declaration contexts from disjoint |
| 5342 | // modules get merged, e.g., when two namespaces with the same name are |
| 5343 | // independently defined in separate modules. |
| 5344 | SmallVector<const DeclContext *, 2> Contexts; |
| 5345 | Contexts.push_back(DC); |
| 5346 | |
| 5347 | if (DC->isNamespace()) { |
| 5348 | MergedDeclsMap::iterator Merged |
| 5349 | = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
| 5350 | if (Merged != MergedDecls.end()) { |
| 5351 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 5352 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 5353 | } |
| 5354 | } |
| 5355 | |
| 5356 | DeclContextNameLookupVisitor Visitor(*this, Contexts, Name, Decls); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5357 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 5358 | ++NumVisibleDeclContextsRead; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 5359 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5360 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5361 | } |
| 5362 | |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5363 | namespace { |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5364 | /// \brief ModuleFile visitor used to retrieve all visible names in a |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5365 | /// declaration context. |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5366 | class DeclContextAllNamesVisitor { |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5367 | ASTReader &Reader; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5368 | llvm::SmallVectorImpl<const DeclContext *> &Contexts; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5369 | llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8> > &Decls; |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5370 | |
| 5371 | public: |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5372 | DeclContextAllNamesVisitor(ASTReader &Reader, |
| 5373 | SmallVectorImpl<const DeclContext *> &Contexts, |
| 5374 | llvm::DenseMap<DeclarationName, |
| 5375 | SmallVector<NamedDecl *, 8> > &Decls) |
| 5376 | : Reader(Reader), Contexts(Contexts), Decls(Decls) { } |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5377 | |
| 5378 | static bool visit(ModuleFile &M, void *UserData) { |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5379 | DeclContextAllNamesVisitor *This |
| 5380 | = static_cast<DeclContextAllNamesVisitor *>(UserData); |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5381 | |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5382 | // Check whether we have any visible declaration information for |
| 5383 | // this context in this module. |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5384 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 5385 | bool FoundInfo = false; |
| 5386 | for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) { |
| 5387 | Info = M.DeclContextInfos.find(This->Contexts[I]); |
| 5388 | if (Info != M.DeclContextInfos.end() && |
| 5389 | Info->second.NameLookupTableData) { |
| 5390 | FoundInfo = true; |
| 5391 | break; |
| 5392 | } |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5393 | } |
| 5394 | |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5395 | if (!FoundInfo) |
| 5396 | return false; |
| 5397 | |
| 5398 | ASTDeclContextNameLookupTable *LookupTable = |
| 5399 | Info->second.NameLookupTableData; |
| 5400 | bool FoundAnything = false; |
| 5401 | for (ASTDeclContextNameLookupTable::data_iterator |
| 5402 | I = LookupTable->data_begin(), E = LookupTable->data_end(); |
| 5403 | I != E; ++I) { |
| 5404 | ASTDeclContextNameLookupTrait::data_type Data = *I; |
| 5405 | for (; Data.first != Data.second; ++Data.first) { |
| 5406 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, |
| 5407 | *Data.first); |
| 5408 | if (!ND) |
| 5409 | continue; |
| 5410 | |
| 5411 | // Record this declaration. |
| 5412 | FoundAnything = true; |
| 5413 | This->Decls[ND->getDeclName()].push_back(ND); |
| 5414 | } |
| 5415 | } |
| 5416 | |
| 5417 | return FoundAnything; |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5418 | } |
| 5419 | }; |
| 5420 | } |
| 5421 | |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5422 | void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5423 | if (!DC->hasExternalVisibleStorage()) |
| 5424 | return; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5425 | llvm::DenseMap<DeclarationName, llvm::SmallVector<NamedDecl*, 8> > Decls; |
| 5426 | |
| 5427 | // Compute the declaration contexts we need to look into. Multiple such |
| 5428 | // declaration contexts occur when two declaration contexts from disjoint |
| 5429 | // modules get merged, e.g., when two namespaces with the same name are |
| 5430 | // independently defined in separate modules. |
| 5431 | SmallVector<const DeclContext *, 2> Contexts; |
| 5432 | Contexts.push_back(DC); |
| 5433 | |
| 5434 | if (DC->isNamespace()) { |
| 5435 | MergedDeclsMap::iterator Merged |
| 5436 | = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
| 5437 | if (Merged != MergedDecls.end()) { |
| 5438 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 5439 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 5440 | } |
| 5441 | } |
| 5442 | |
| 5443 | DeclContextAllNamesVisitor Visitor(*this, Contexts, Decls); |
| 5444 | ModuleMgr.visit(&DeclContextAllNamesVisitor::visit, &Visitor); |
| 5445 | ++NumVisibleDeclContextsRead; |
| 5446 | |
| 5447 | for (llvm::DenseMap<DeclarationName, |
| 5448 | llvm::SmallVector<NamedDecl*, 8> >::iterator |
| 5449 | I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
| 5450 | SetExternalVisibleDeclsForName(DC, I->first, I->second); |
| 5451 | } |
Argyrios Kyrtzidis | 394e539 | 2012-04-26 18:34:14 +0000 | [diff] [blame] | 5452 | const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false); |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5453 | } |
| 5454 | |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5455 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 5456 | /// before receiving the implementation, and codegen depends on this. |
| 5457 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 5458 | /// implementation before passing the deserialized implementation decl. |
| 5459 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 5460 | ASTConsumer *Consumer) { |
| 5461 | assert(ImplD && Consumer); |
| 5462 | |
| 5463 | for (ObjCImplDecl::method_iterator |
| 5464 | I = ImplD->meth_begin(), E = ImplD->meth_end(); I != E; ++I) |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 5465 | Consumer->HandleInterestingDecl(DeclGroupRef(*I)); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5466 | |
| 5467 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 5468 | } |
| 5469 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5470 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5471 | assert(Consumer); |
| 5472 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5473 | Decl *D = InterestingDecls.front(); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5474 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5475 | |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 5476 | PassInterestingDeclToConsumer(D); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5477 | } |
| 5478 | } |
| 5479 | |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 5480 | void ASTReader::PassInterestingDeclToConsumer(Decl *D) { |
| 5481 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 5482 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 5483 | else |
| 5484 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
| 5485 | } |
| 5486 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5487 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 5488 | this->Consumer = Consumer; |
| 5489 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5490 | if (!Consumer) |
| 5491 | return; |
| 5492 | |
| 5493 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5494 | // Force deserialization of this decl, which will cause it to be queued for |
| 5495 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 5496 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5497 | } |
Douglas Gregor | 1a995dd | 2011-09-15 18:47:32 +0000 | [diff] [blame] | 5498 | ExternalDefinitions.clear(); |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 5499 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5500 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5501 | } |
| 5502 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5503 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5504 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5505 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5506 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5507 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5508 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5509 | unsigned NumDeclsLoaded |
| 5510 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 5511 | (Decl *)0); |
| 5512 | unsigned NumIdentifiersLoaded |
| 5513 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 5514 | IdentifiersLoaded.end(), |
| 5515 | (IdentifierInfo *)0); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5516 | unsigned NumMacrosLoaded |
| 5517 | = MacrosLoaded.size() - std::count(MacrosLoaded.begin(), |
| 5518 | MacrosLoaded.end(), |
| 5519 | (MacroInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5520 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5521 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 5522 | SelectorsLoaded.end(), |
| 5523 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 5524 | |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 5525 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 5526 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 5527 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 5528 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5529 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5530 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5531 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 5532 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 5533 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5534 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5535 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 5536 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5537 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5538 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5539 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 5540 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5541 | if (!MacrosLoaded.empty()) |
| 5542 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 5543 | NumMacrosLoaded, (unsigned)MacrosLoaded.size(), |
| 5544 | ((float)NumMacrosLoaded/MacrosLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5545 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5546 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5547 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 5548 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5549 | if (TotalNumStatements) |
| 5550 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 5551 | NumStatementsRead, TotalNumStatements, |
| 5552 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 5553 | if (TotalNumMacros) |
| 5554 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 5555 | NumMacrosRead, TotalNumMacros, |
| 5556 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 5557 | if (TotalLexicalDeclContexts) |
| 5558 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 5559 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 5560 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 5561 | * 100)); |
| 5562 | if (TotalVisibleDeclContexts) |
| 5563 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 5564 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 5565 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 5566 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5567 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5568 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5569 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 5570 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5571 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5572 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5573 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5574 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5575 | dump(); |
| 5576 | std::fprintf(stderr, "\n"); |
| 5577 | } |
| 5578 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5579 | template<typename Key, typename ModuleFile, unsigned InitialCapacity> |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5580 | static void |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5581 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5582 | const ContinuousRangeMap<Key, ModuleFile *, |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5583 | InitialCapacity> &Map) { |
| 5584 | if (Map.begin() == Map.end()) |
| 5585 | return; |
| 5586 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5587 | typedef ContinuousRangeMap<Key, ModuleFile *, InitialCapacity> MapType; |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5588 | llvm::errs() << Name << ":\n"; |
| 5589 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 5590 | I != IEnd; ++I) { |
| 5591 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 5592 | << "\n"; |
| 5593 | } |
| 5594 | } |
| 5595 | |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5596 | void ASTReader::dump() { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5597 | llvm::errs() << "*** PCH/ModuleFile Remappings:\n"; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5598 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5599 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 5600 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5601 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5602 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5603 | dumpModuleIDMap("Global macro map", GlobalMacroMap); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5604 | dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5605 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5606 | dumpModuleIDMap("Global preprocessed entity map", |
| 5607 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 8df5c9b | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 5608 | |
| 5609 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 5610 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 5611 | MEnd = ModuleMgr.end(); |
| 5612 | M != MEnd; ++M) |
| 5613 | (*M)->dump(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5614 | } |
| 5615 | |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5616 | /// Return the amount of memory used by memory buffers, breaking down |
| 5617 | /// by heap-backed versus mmap'ed memory. |
| 5618 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5619 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 5620 | E = ModuleMgr.end(); I != E; ++I) { |
| 5621 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5622 | size_t bytes = buf->getBufferSize(); |
| 5623 | switch (buf->getBufferKind()) { |
| 5624 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 5625 | sizes.malloc_bytes += bytes; |
| 5626 | break; |
| 5627 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 5628 | sizes.mmap_bytes += bytes; |
| 5629 | break; |
| 5630 | } |
| 5631 | } |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5632 | } |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5633 | } |
| 5634 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5635 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5636 | SemaObj = &S; |
Axel Naumann | 0ec56b7 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 5637 | S.addExternalSource(this); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5638 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 5639 | // Makes sure any declarations that were deserialized "too early" |
| 5640 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 5641 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5642 | SemaObj->pushExternalDeclIntoScope(PreloadedDecls[I], |
| 5643 | PreloadedDecls[I]->getDeclName()); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5644 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 5645 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 5646 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5647 | // Load the offsets of the declarations that Sema references. |
| 5648 | // They will be lazily deserialized when needed. |
| 5649 | if (!SemaDeclRefs.empty()) { |
| 5650 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | 1e5b6f6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 5651 | if (!SemaObj->StdNamespace) |
| 5652 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 5653 | if (!SemaObj->StdBadAlloc) |
| 5654 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5655 | } |
| 5656 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 5657 | if (!FPPragmaOptions.empty()) { |
| 5658 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 5659 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 5660 | } |
| 5661 | |
| 5662 | if (!OpenCLExtensions.empty()) { |
| 5663 | unsigned I = 0; |
| 5664 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 5665 | #include "clang/Basic/OpenCLExtensions.def" |
| 5666 | |
| 5667 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 5668 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5669 | } |
| 5670 | |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5671 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 5672 | // Note that we are loading an identifier. |
| 5673 | Deserializing AnIdentifier(this); |
| 5674 | |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 5675 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart), |
| 5676 | /*PriorGeneration=*/0); |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5677 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5678 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 5679 | markIdentifierUpToDate(II); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5680 | return II; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5681 | } |
| 5682 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5683 | namespace clang { |
| 5684 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 5685 | /// identifiers stored within a set of AST files. |
| 5686 | class ASTIdentifierIterator : public IdentifierIterator { |
| 5687 | /// \brief The AST reader whose identifiers are being enumerated. |
| 5688 | const ASTReader &Reader; |
| 5689 | |
| 5690 | /// \brief The current index into the chain of AST files stored in |
| 5691 | /// the AST reader. |
| 5692 | unsigned Index; |
| 5693 | |
| 5694 | /// \brief The current position within the identifier lookup table |
| 5695 | /// of the current AST file. |
| 5696 | ASTIdentifierLookupTable::key_iterator Current; |
| 5697 | |
| 5698 | /// \brief The end position within the identifier lookup table of |
| 5699 | /// the current AST file. |
| 5700 | ASTIdentifierLookupTable::key_iterator End; |
| 5701 | |
| 5702 | public: |
| 5703 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 5704 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5705 | virtual StringRef Next(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5706 | }; |
| 5707 | } |
| 5708 | |
| 5709 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5710 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5711 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5712 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5713 | Current = IdTable->key_begin(); |
| 5714 | End = IdTable->key_end(); |
| 5715 | } |
| 5716 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5717 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5718 | while (Current == End) { |
| 5719 | // If we have exhausted all of our AST files, we're done. |
| 5720 | if (Index == 0) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5721 | return StringRef(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5722 | |
| 5723 | --Index; |
| 5724 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5725 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 5726 | IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5727 | Current = IdTable->key_begin(); |
| 5728 | End = IdTable->key_end(); |
| 5729 | } |
| 5730 | |
| 5731 | // We have any identifiers remaining in the current AST file; return |
| 5732 | // the next one. |
| 5733 | std::pair<const char*, unsigned> Key = *Current; |
| 5734 | ++Current; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5735 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5736 | } |
| 5737 | |
| 5738 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 5739 | return new ASTIdentifierIterator(*this); |
| 5740 | } |
| 5741 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5742 | namespace clang { namespace serialization { |
| 5743 | class ReadMethodPoolVisitor { |
| 5744 | ASTReader &Reader; |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5745 | Selector Sel; |
| 5746 | unsigned PriorGeneration; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5747 | llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 5748 | llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5749 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5750 | public: |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5751 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, |
| 5752 | unsigned PriorGeneration) |
| 5753 | : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration) { } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5754 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5755 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5756 | ReadMethodPoolVisitor *This |
| 5757 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 5758 | |
| 5759 | if (!M.SelectorLookupTable) |
| 5760 | return false; |
| 5761 | |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5762 | // If we've already searched this module file, skip it now. |
| 5763 | if (M.Generation <= This->PriorGeneration) |
| 5764 | return true; |
| 5765 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5766 | ASTSelectorLookupTable *PoolTable |
| 5767 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 5768 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 5769 | if (Pos == PoolTable->end()) |
| 5770 | return false; |
| 5771 | |
| 5772 | ++This->Reader.NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5773 | // FIXME: Not quite happy with the statistics here. We probably should |
| 5774 | // disable this tracking when called via LoadSelector. |
| 5775 | // Also, should entries without methods count as misses? |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5776 | ++This->Reader.NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5777 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5778 | if (This->Reader.DeserializationListener) |
| 5779 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 5780 | This->Sel); |
| 5781 | |
| 5782 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 5783 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 5784 | return true; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5785 | } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5786 | |
| 5787 | /// \brief Retrieve the instance methods found by this visitor. |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5788 | ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { |
| 5789 | return InstanceMethods; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5790 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5791 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5792 | /// \brief Retrieve the instance methods found by this visitor. |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5793 | ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { |
| 5794 | return FactoryMethods; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5795 | } |
| 5796 | }; |
| 5797 | } } // end namespace clang::serialization |
| 5798 | |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5799 | /// \brief Add the given set of methods to the method list. |
| 5800 | static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, |
| 5801 | ObjCMethodList &List) { |
| 5802 | for (unsigned I = 0, N = Methods.size(); I != N; ++I) { |
| 5803 | S.addMethodToGlobalList(&List, Methods[I]); |
| 5804 | } |
| 5805 | } |
| 5806 | |
| 5807 | void ASTReader::ReadMethodPool(Selector Sel) { |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5808 | // Get the selector generation and update it to the current generation. |
| 5809 | unsigned &Generation = SelectorGeneration[Sel]; |
| 5810 | unsigned PriorGeneration = Generation; |
| 5811 | Generation = CurrentGeneration; |
| 5812 | |
| 5813 | // Search for methods defined with this selector. |
| 5814 | ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration); |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5815 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5816 | |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5817 | if (Visitor.getInstanceMethods().empty() && |
| 5818 | Visitor.getFactoryMethods().empty()) { |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5819 | ++NumMethodPoolMisses; |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5820 | return; |
| 5821 | } |
| 5822 | |
| 5823 | if (!getSema()) |
| 5824 | return; |
| 5825 | |
| 5826 | Sema &S = *getSema(); |
| 5827 | Sema::GlobalMethodPool::iterator Pos |
| 5828 | = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; |
| 5829 | |
| 5830 | addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); |
| 5831 | addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5832 | } |
| 5833 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 5834 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5835 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 5836 | Namespaces.clear(); |
| 5837 | |
| 5838 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 5839 | if (NamespaceDecl *Namespace |
| 5840 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 5841 | Namespaces.push_back(Namespace); |
| 5842 | } |
| 5843 | } |
| 5844 | |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 5845 | void ASTReader::ReadTentativeDefinitions( |
| 5846 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 5847 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 5848 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 5849 | if (Var) |
| 5850 | TentativeDefs.push_back(Var); |
| 5851 | } |
| 5852 | TentativeDefinitions.clear(); |
| 5853 | } |
| 5854 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 5855 | void ASTReader::ReadUnusedFileScopedDecls( |
| 5856 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 5857 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 5858 | DeclaratorDecl *D |
| 5859 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 5860 | if (D) |
| 5861 | Decls.push_back(D); |
| 5862 | } |
| 5863 | UnusedFileScopedDecls.clear(); |
| 5864 | } |
| 5865 | |
Douglas Gregor | 0129b56 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 5866 | void ASTReader::ReadDelegatingConstructors( |
| 5867 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 5868 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 5869 | CXXConstructorDecl *D |
| 5870 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 5871 | if (D) |
| 5872 | Decls.push_back(D); |
| 5873 | } |
| 5874 | DelegatingCtorDecls.clear(); |
| 5875 | } |
| 5876 | |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 5877 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 5878 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 5879 | TypedefNameDecl *D |
| 5880 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 5881 | if (D) |
| 5882 | Decls.push_back(D); |
| 5883 | } |
| 5884 | ExtVectorDecls.clear(); |
| 5885 | } |
| 5886 | |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 5887 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 5888 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 5889 | CXXRecordDecl *D |
| 5890 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 5891 | if (D) |
| 5892 | Decls.push_back(D); |
| 5893 | } |
| 5894 | DynamicClasses.clear(); |
| 5895 | } |
| 5896 | |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 5897 | void |
| 5898 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 5899 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 5900 | NamedDecl *D |
| 5901 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 5902 | if (D) |
| 5903 | Decls.push_back(D); |
| 5904 | } |
| 5905 | LocallyScopedExternalDecls.clear(); |
| 5906 | } |
| 5907 | |
Douglas Gregor | 5b9dc7c | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 5908 | void ASTReader::ReadReferencedSelectors( |
| 5909 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 5910 | if (ReferencedSelectorsData.empty()) |
| 5911 | return; |
| 5912 | |
| 5913 | // If there are @selector references added them to its pool. This is for |
| 5914 | // implementation of -Wselector. |
| 5915 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 5916 | unsigned I = 0; |
| 5917 | while (I < DataSize) { |
| 5918 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 5919 | SourceLocation SelLoc |
| 5920 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 5921 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 5922 | } |
| 5923 | ReferencedSelectorsData.clear(); |
| 5924 | } |
| 5925 | |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 5926 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 5927 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 5928 | if (WeakUndeclaredIdentifiers.empty()) |
| 5929 | return; |
| 5930 | |
| 5931 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 5932 | IdentifierInfo *WeakId |
| 5933 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 5934 | IdentifierInfo *AliasId |
| 5935 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 5936 | SourceLocation Loc |
| 5937 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 5938 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 5939 | WeakInfo WI(AliasId, Loc); |
| 5940 | WI.setUsed(Used); |
| 5941 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 5942 | } |
| 5943 | WeakUndeclaredIdentifiers.clear(); |
| 5944 | } |
| 5945 | |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 5946 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 5947 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 5948 | ExternalVTableUse VT; |
| 5949 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 5950 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 5951 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 5952 | VTables.push_back(VT); |
| 5953 | } |
| 5954 | |
| 5955 | VTableUses.clear(); |
| 5956 | } |
| 5957 | |
Douglas Gregor | 6e4a3f5 | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 5958 | void ASTReader::ReadPendingInstantiations( |
| 5959 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 5960 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 5961 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 5962 | SourceLocation Loc |
| 5963 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 5964 | |
Douglas Gregor | e5fa3c2 | 2012-10-03 18:34:48 +0000 | [diff] [blame] | 5965 | Pending.push_back(std::make_pair(D, Loc)); |
Douglas Gregor | 6e4a3f5 | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 5966 | } |
| 5967 | PendingInstantiations.clear(); |
| 5968 | } |
| 5969 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5970 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5971 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 5972 | ReadMethodPool(Sel); |
| 5973 | } |
| 5974 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5975 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5976 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 5977 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5978 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5979 | if (DeserializationListener) |
| 5980 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5981 | } |
| 5982 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5983 | /// \brief Set the globally-visible declarations associated with the given |
| 5984 | /// identifier. |
| 5985 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5986 | /// 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] | 5987 | /// 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] | 5988 | /// them. |
| 5989 | /// |
| 5990 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 5991 | /// declarations. |
| 5992 | /// |
| 5993 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 5994 | /// visible at global scope. |
| 5995 | /// |
| 5996 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 5997 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 5998 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5999 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6000 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6001 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6002 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 6003 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6004 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 6005 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 6006 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 6007 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6008 | return; |
| 6009 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6010 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6011 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 6012 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 6013 | if (SemaObj) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 6014 | // Introduce this declaration into the translation-unit scope |
| 6015 | // and add it to the declaration chain for this identifier, so |
| 6016 | // that (unqualified) name lookup will find it. |
| 6017 | SemaObj->pushExternalDeclIntoScope(D, II); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6018 | } else { |
| 6019 | // Queue this declaration so that it will be added to the |
| 6020 | // translation unit scope and identifier's declaration chain |
| 6021 | // once a Sema object is known. |
| 6022 | PreloadedDecls.push_back(D); |
| 6023 | } |
| 6024 | } |
| 6025 | } |
| 6026 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6027 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 6028 | if (ID == 0) |
| 6029 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6030 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 6031 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 6032 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 6033 | return 0; |
| 6034 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6035 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 6036 | ID -= 1; |
| 6037 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 6038 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 6039 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6040 | ModuleFile *M = I->second; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 6041 | unsigned Index = ID - M->BaseIdentifierID; |
| 6042 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 6043 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 6044 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 6045 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 6046 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 6047 | // unsigned integers. This is important to avoid integer overflow when |
| 6048 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 6049 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 6050 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 6051 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 6052 | IdentifiersLoaded[ID] |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 6053 | = &PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 6054 | if (DeserializationListener) |
| 6055 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 6056 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6057 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 6058 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6059 | } |
| 6060 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6061 | IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6062 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 6063 | } |
| 6064 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6065 | IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 6066 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 6067 | return LocalID; |
| 6068 | |
| 6069 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6070 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 6071 | assert(I != M.IdentifierRemap.end() |
| 6072 | && "Invalid index into identifier index remap"); |
| 6073 | |
| 6074 | return LocalID + I->second; |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6075 | } |
| 6076 | |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 6077 | MacroInfo *ASTReader::getMacro(MacroID ID, MacroInfo *Hint) { |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6078 | if (ID == 0) |
| 6079 | return 0; |
| 6080 | |
| 6081 | if (MacrosLoaded.empty()) { |
| 6082 | Error("no macro table in AST file"); |
| 6083 | return 0; |
| 6084 | } |
| 6085 | |
| 6086 | ID -= NUM_PREDEF_MACRO_IDS; |
| 6087 | if (!MacrosLoaded[ID]) { |
| 6088 | GlobalMacroMapType::iterator I |
| 6089 | = GlobalMacroMap.find(ID + NUM_PREDEF_MACRO_IDS); |
| 6090 | assert(I != GlobalMacroMap.end() && "Corrupted global macro map"); |
| 6091 | ModuleFile *M = I->second; |
| 6092 | unsigned Index = ID - M->BaseMacroID; |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 6093 | ReadMacroRecord(*M, M->MacroOffsets[Index], Hint); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6094 | } |
| 6095 | |
| 6096 | return MacrosLoaded[ID]; |
| 6097 | } |
| 6098 | |
| 6099 | MacroID ASTReader::getGlobalMacroID(ModuleFile &M, unsigned LocalID) { |
| 6100 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 6101 | return LocalID; |
| 6102 | |
| 6103 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6104 | = M.MacroRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 6105 | assert(I != M.MacroRemap.end() && "Invalid index into macro index remap"); |
| 6106 | |
| 6107 | return LocalID + I->second; |
| 6108 | } |
| 6109 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 6110 | serialization::SubmoduleID |
| 6111 | ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) { |
| 6112 | if (LocalID < NUM_PREDEF_SUBMODULE_IDS) |
| 6113 | return LocalID; |
| 6114 | |
| 6115 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6116 | = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS); |
| 6117 | assert(I != M.SubmoduleRemap.end() |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6118 | && "Invalid index into submodule index remap"); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 6119 | |
| 6120 | return LocalID + I->second; |
| 6121 | } |
| 6122 | |
| 6123 | Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { |
| 6124 | if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) { |
| 6125 | assert(GlobalID == 0 && "Unhandled global submodule ID"); |
| 6126 | return 0; |
| 6127 | } |
| 6128 | |
| 6129 | if (GlobalID > SubmodulesLoaded.size()) { |
| 6130 | Error("submodule ID out of range in AST file"); |
| 6131 | return 0; |
| 6132 | } |
| 6133 | |
| 6134 | return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; |
| 6135 | } |
| 6136 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6137 | Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 6138 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 6139 | } |
| 6140 | |
| 6141 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 6142 | if (ID == 0) |
| 6143 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6144 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 6145 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 6146 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 6147 | return Selector(); |
| 6148 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 6149 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 6150 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 6151 | // Load this selector from the selector table. |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 6152 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 6153 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6154 | ModuleFile &M = *I->second; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 6155 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 6156 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 6157 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 6158 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 6159 | if (DeserializationListener) |
| 6160 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 6161 | } |
| 6162 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 6163 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 6164 | } |
| 6165 | |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 6166 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 6167 | return DecodeSelector(ID); |
| 6168 | } |
| 6169 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6170 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 6171 | // ID 0 (the null selector) is considered an external selector. |
| 6172 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 6173 | } |
| 6174 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 6175 | serialization::SelectorID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6176 | ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 6177 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 6178 | return LocalID; |
| 6179 | |
| 6180 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6181 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 6182 | assert(I != M.SelectorRemap.end() |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6183 | && "Invalid index into selector index remap"); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 6184 | |
| 6185 | return LocalID + I->second; |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 6186 | } |
| 6187 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6188 | DeclarationName |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6189 | ASTReader::ReadDeclarationName(ModuleFile &F, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6190 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6191 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 6192 | switch (Kind) { |
| 6193 | case DeclarationName::Identifier: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6194 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6195 | |
| 6196 | case DeclarationName::ObjCZeroArgSelector: |
| 6197 | case DeclarationName::ObjCOneArgSelector: |
| 6198 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 6199 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6200 | |
| 6201 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6202 | return Context.DeclarationNames.getCXXConstructorName( |
| 6203 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6204 | |
| 6205 | case DeclarationName::CXXDestructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6206 | return Context.DeclarationNames.getCXXDestructorName( |
| 6207 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6208 | |
| 6209 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6210 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 6211 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6212 | |
| 6213 | case DeclarationName::CXXOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6214 | return Context.DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6215 | (OverloadedOperatorKind)Record[Idx++]); |
| 6216 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 6217 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6218 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6219 | GetIdentifierInfo(F, Record, Idx)); |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 6220 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6221 | case DeclarationName::CXXUsingDirective: |
| 6222 | return DeclarationName::getUsingDirectiveName(); |
| 6223 | } |
| 6224 | |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 6225 | llvm_unreachable("Invalid NameKind!"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6226 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 6227 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6228 | void ASTReader::ReadDeclarationNameLoc(ModuleFile &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6229 | DeclarationNameLoc &DNLoc, |
| 6230 | DeclarationName Name, |
| 6231 | const RecordData &Record, unsigned &Idx) { |
| 6232 | switch (Name.getNameKind()) { |
| 6233 | case DeclarationName::CXXConstructorName: |
| 6234 | case DeclarationName::CXXDestructorName: |
| 6235 | case DeclarationName::CXXConversionFunctionName: |
| 6236 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 6237 | break; |
| 6238 | |
| 6239 | case DeclarationName::CXXOperatorName: |
| 6240 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 6241 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 6242 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 6243 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 6244 | break; |
| 6245 | |
| 6246 | case DeclarationName::CXXLiteralOperatorName: |
| 6247 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 6248 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 6249 | break; |
| 6250 | |
| 6251 | case DeclarationName::Identifier: |
| 6252 | case DeclarationName::ObjCZeroArgSelector: |
| 6253 | case DeclarationName::ObjCOneArgSelector: |
| 6254 | case DeclarationName::ObjCMultiArgSelector: |
| 6255 | case DeclarationName::CXXUsingDirective: |
| 6256 | break; |
| 6257 | } |
| 6258 | } |
| 6259 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6260 | void ASTReader::ReadDeclarationNameInfo(ModuleFile &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6261 | DeclarationNameInfo &NameInfo, |
| 6262 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6263 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6264 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 6265 | DeclarationNameLoc DNLoc; |
| 6266 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 6267 | NameInfo.setInfo(DNLoc); |
| 6268 | } |
| 6269 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6270 | void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6271 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 6272 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6273 | unsigned NumTPLists = Record[Idx++]; |
| 6274 | Info.NumTemplParamLists = NumTPLists; |
| 6275 | if (NumTPLists) { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6276 | Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 6277 | for (unsigned i=0; i != NumTPLists; ++i) |
| 6278 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 6279 | } |
| 6280 | } |
| 6281 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6282 | TemplateName |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6283 | ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6284 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6285 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6286 | switch (Kind) { |
| 6287 | case TemplateName::Template: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6288 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6289 | |
| 6290 | case TemplateName::OverloadedTemplate: { |
| 6291 | unsigned size = Record[Idx++]; |
| 6292 | UnresolvedSet<8> Decls; |
| 6293 | while (size--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6294 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6295 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6296 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6297 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6298 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6299 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6300 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6301 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6302 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6303 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6304 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6305 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6306 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6307 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6308 | if (Record[Idx++]) // isIdentifier |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6309 | return Context.getDependentTemplateName(NNS, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6310 | GetIdentifierInfo(F, Record, |
| 6311 | Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6312 | return Context.getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 6313 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6314 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6315 | |
| 6316 | case TemplateName::SubstTemplateTemplateParm: { |
| 6317 | TemplateTemplateParmDecl *param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6318 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6319 | if (!param) return TemplateName(); |
| 6320 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6321 | return Context.getSubstTemplateTemplateParm(param, replacement); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6322 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6323 | |
| 6324 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 6325 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6326 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6327 | if (!Param) |
| 6328 | return TemplateName(); |
| 6329 | |
| 6330 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 6331 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 6332 | return TemplateName(); |
| 6333 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6334 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6335 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6336 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6337 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 6338 | llvm_unreachable("Unhandled template name kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6339 | } |
| 6340 | |
| 6341 | TemplateArgument |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6342 | ASTReader::ReadTemplateArgument(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 6343 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 6344 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 6345 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6346 | case TemplateArgument::Null: |
| 6347 | return TemplateArgument(); |
| 6348 | case TemplateArgument::Type: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6349 | return TemplateArgument(readType(F, Record, Idx)); |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 6350 | case TemplateArgument::Declaration: { |
| 6351 | ValueDecl *D = ReadDeclAs<ValueDecl>(F, Record, Idx); |
| 6352 | bool ForReferenceParam = Record[Idx++]; |
| 6353 | return TemplateArgument(D, ForReferenceParam); |
| 6354 | } |
| 6355 | case TemplateArgument::NullPtr: |
| 6356 | return TemplateArgument(readType(F, Record, Idx), /*isNullPtr*/true); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 6357 | case TemplateArgument::Integral: { |
| 6358 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6359 | QualType T = readType(F, Record, Idx); |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 6360 | return TemplateArgument(Context, Value, T); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 6361 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 6362 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6363 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 6364 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6365 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 6366 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 6367 | if (unsigned NumExpansions = Record[Idx++]) |
| 6368 | NumTemplateExpansions = NumExpansions - 1; |
| 6369 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 6370 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6371 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6372 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6373 | case TemplateArgument::Pack: { |
| 6374 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6375 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 6376 | for (unsigned I = 0; I != NumArgs; ++I) |
| 6377 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 6378 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6379 | } |
| 6380 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6381 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 6382 | llvm_unreachable("Unhandled template argument kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6383 | } |
| 6384 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6385 | TemplateParameterList * |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6386 | ASTReader::ReadTemplateParameterList(ModuleFile &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6387 | const RecordData &Record, unsigned &Idx) { |
| 6388 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 6389 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 6390 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6391 | |
| 6392 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6393 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6394 | Params.reserve(NumParams); |
| 6395 | while (NumParams--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6396 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6397 | |
| 6398 | TemplateParameterList* TemplateParams = |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6399 | TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6400 | Params.data(), Params.size(), RAngleLoc); |
| 6401 | return TemplateParams; |
| 6402 | } |
| 6403 | |
| 6404 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6405 | ASTReader:: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6406 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6407 | ModuleFile &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6408 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6409 | unsigned NumTemplateArgs = Record[Idx++]; |
| 6410 | TemplArgs.reserve(NumTemplateArgs); |
| 6411 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6412 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6413 | } |
| 6414 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6415 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6416 | void ASTReader::ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6417 | const RecordData &Record, unsigned &Idx) { |
| 6418 | unsigned NumDecls = Record[Idx++]; |
| 6419 | while (NumDecls--) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6420 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6421 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 6422 | Set.addDecl(D, AS); |
| 6423 | } |
| 6424 | } |
| 6425 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6426 | CXXBaseSpecifier |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6427 | ASTReader::ReadCXXBaseSpecifier(ModuleFile &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 6428 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6429 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 6430 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 6431 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6432 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6433 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 6434 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 6435 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6436 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 6437 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6438 | Result.setInheritConstructors(inheritConstructors); |
| 6439 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6440 | } |
| 6441 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6442 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6443 | ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6444 | unsigned &Idx) { |
| 6445 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6446 | unsigned NumInitializers = Record[Idx++]; |
| 6447 | if (NumInitializers) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6448 | CtorInitializers |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6449 | = new (Context) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6450 | for (unsigned i=0; i != NumInitializers; ++i) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6451 | TypeSourceInfo *TInfo = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6452 | bool IsBaseVirtual = false; |
| 6453 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6454 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6455 | |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6456 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 6457 | switch (Type) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6458 | case CTOR_INITIALIZER_BASE: |
| 6459 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6460 | IsBaseVirtual = Record[Idx++]; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6461 | break; |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6462 | |
| 6463 | case CTOR_INITIALIZER_DELEGATING: |
| 6464 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6465 | break; |
| 6466 | |
| 6467 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6468 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6469 | break; |
| 6470 | |
| 6471 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6472 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6473 | break; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6474 | } |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6475 | |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 6476 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6477 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6478 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 6479 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6480 | bool IsWritten = Record[Idx++]; |
| 6481 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6482 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6483 | if (IsWritten) { |
| 6484 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 6485 | } else { |
| 6486 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 6487 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 6488 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6489 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6490 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6491 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6492 | CXXCtorInitializer *BOMInit; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6493 | if (Type == CTOR_INITIALIZER_BASE) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6494 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, IsBaseVirtual, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6495 | LParenLoc, Init, RParenLoc, |
| 6496 | MemberOrEllipsisLoc); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6497 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6498 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, LParenLoc, |
| 6499 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6500 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6501 | if (Member) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6502 | BOMInit = new (Context) CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6503 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6504 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6505 | BOMInit = new (Context) CXXCtorInitializer(Context, IndirectMember, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6506 | MemberOrEllipsisLoc, LParenLoc, |
| 6507 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6508 | } else { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6509 | BOMInit = CXXCtorInitializer::Create(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6510 | LParenLoc, Init, RParenLoc, |
| 6511 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6512 | } |
| 6513 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 6514 | if (IsWritten) |
| 6515 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6516 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6517 | } |
| 6518 | } |
| 6519 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6520 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6521 | } |
| 6522 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6523 | NestedNameSpecifier * |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6524 | ASTReader::ReadNestedNameSpecifier(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6525 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6526 | unsigned N = Record[Idx++]; |
| 6527 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 6528 | for (unsigned I = 0; I != N; ++I) { |
| 6529 | NestedNameSpecifier::SpecifierKind Kind |
| 6530 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 6531 | switch (Kind) { |
| 6532 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6533 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6534 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6535 | break; |
| 6536 | } |
| 6537 | |
| 6538 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6539 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6540 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6541 | break; |
| 6542 | } |
| 6543 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 6544 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6545 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6546 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 6547 | break; |
| 6548 | } |
| 6549 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6550 | case NestedNameSpecifier::TypeSpec: |
| 6551 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6552 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 6553 | if (!T) |
| 6554 | return 0; |
| 6555 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6556 | bool Template = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6557 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6558 | break; |
| 6559 | } |
| 6560 | |
| 6561 | case NestedNameSpecifier::Global: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6562 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6563 | // No associated value, and there can't be a prefix. |
| 6564 | break; |
| 6565 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6566 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 6567 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6568 | } |
| 6569 | return NNS; |
| 6570 | } |
| 6571 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6572 | NestedNameSpecifierLoc |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6573 | ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6574 | unsigned &Idx) { |
| 6575 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6576 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6577 | for (unsigned I = 0; I != N; ++I) { |
| 6578 | NestedNameSpecifier::SpecifierKind Kind |
| 6579 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 6580 | switch (Kind) { |
| 6581 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6582 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6583 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6584 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6585 | break; |
| 6586 | } |
| 6587 | |
| 6588 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6589 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6590 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6591 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6592 | break; |
| 6593 | } |
| 6594 | |
| 6595 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6596 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6597 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6598 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6599 | break; |
| 6600 | } |
| 6601 | |
| 6602 | case NestedNameSpecifier::TypeSpec: |
| 6603 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6604 | bool Template = Record[Idx++]; |
| 6605 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 6606 | if (!T) |
| 6607 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6608 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6609 | |
| 6610 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6611 | Builder.Extend(Context, |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6612 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 6613 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6614 | break; |
| 6615 | } |
| 6616 | |
| 6617 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6618 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6619 | Builder.MakeGlobal(Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6620 | break; |
| 6621 | } |
| 6622 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6623 | } |
| 6624 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6625 | return Builder.getWithLocInContext(Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6626 | } |
| 6627 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6628 | SourceRange |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6629 | ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6630 | unsigned &Idx) { |
| 6631 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 6632 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 6633 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6634 | } |
| 6635 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6636 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6637 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6638 | unsigned BitWidth = Record[Idx++]; |
| 6639 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 6640 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 6641 | Idx += NumWords; |
| 6642 | return Result; |
| 6643 | } |
| 6644 | |
| 6645 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6646 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6647 | bool isUnsigned = Record[Idx++]; |
| 6648 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 6649 | } |
| 6650 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 6651 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6652 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 6653 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 6654 | } |
| 6655 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6656 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6657 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6658 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 6659 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6660 | Idx += Len; |
| 6661 | return Result; |
| 6662 | } |
| 6663 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 6664 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 6665 | unsigned &Idx) { |
| 6666 | unsigned Major = Record[Idx++]; |
| 6667 | unsigned Minor = Record[Idx++]; |
| 6668 | unsigned Subminor = Record[Idx++]; |
| 6669 | if (Minor == 0) |
| 6670 | return VersionTuple(Major); |
| 6671 | if (Subminor == 0) |
| 6672 | return VersionTuple(Major, Minor - 1); |
| 6673 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 6674 | } |
| 6675 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6676 | CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6677 | const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 6678 | unsigned &Idx) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6679 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6680 | return CXXTemporary::Create(Context, Decl); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 6681 | } |
| 6682 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6683 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 6684 | return Diag(SourceLocation(), DiagID); |
| 6685 | } |
| 6686 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6687 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6688 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 6689 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6690 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6691 | /// \brief Retrieve the identifier table associated with the |
| 6692 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6693 | IdentifierTable &ASTReader::getIdentifierTable() { |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 6694 | return PP.getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6695 | } |
| 6696 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6697 | /// \brief Record that the given ID maps to the given switch-case |
| 6698 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6699 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6700 | assert((*CurrSwitchCaseStmts)[ID] == 0 && |
| 6701 | "Already have a SwitchCase with this ID"); |
| 6702 | (*CurrSwitchCaseStmts)[ID] = SC; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6703 | } |
| 6704 | |
| 6705 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6706 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6707 | assert((*CurrSwitchCaseStmts)[ID] != 0 && "No SwitchCase with this ID"); |
| 6708 | return (*CurrSwitchCaseStmts)[ID]; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6709 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 6710 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 6711 | void ASTReader::ClearSwitchCaseIDs() { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6712 | CurrSwitchCaseStmts->clear(); |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 6713 | } |
| 6714 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6715 | void ASTReader::ReadComments() { |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 6716 | std::vector<RawComment *> Comments; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6717 | for (SmallVectorImpl<std::pair<llvm::BitstreamCursor, |
| 6718 | serialization::ModuleFile *> >::iterator |
| 6719 | I = CommentsCursors.begin(), |
| 6720 | E = CommentsCursors.end(); |
| 6721 | I != E; ++I) { |
| 6722 | llvm::BitstreamCursor &Cursor = I->first; |
| 6723 | serialization::ModuleFile &F = *I->second; |
| 6724 | SavedStreamPosition SavedPosition(Cursor); |
| 6725 | |
| 6726 | RecordData Record; |
| 6727 | while (true) { |
| 6728 | unsigned Code = Cursor.ReadCode(); |
| 6729 | if (Code == llvm::bitc::END_BLOCK) |
| 6730 | break; |
| 6731 | |
| 6732 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 6733 | // No known subblocks, always skip them. |
| 6734 | Cursor.ReadSubBlockID(); |
| 6735 | if (Cursor.SkipBlock()) { |
| 6736 | Error("malformed block record in AST file"); |
| 6737 | return; |
| 6738 | } |
| 6739 | continue; |
| 6740 | } |
| 6741 | |
| 6742 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 6743 | Cursor.ReadAbbrevRecord(); |
| 6744 | continue; |
| 6745 | } |
| 6746 | |
| 6747 | // Read a record. |
| 6748 | Record.clear(); |
| 6749 | switch ((CommentRecordTypes) Cursor.ReadRecord(Code, Record)) { |
Chandler Carruth | 13691bb | 2012-06-20 06:47:54 +0000 | [diff] [blame] | 6750 | case COMMENTS_RAW_COMMENT: { |
| 6751 | unsigned Idx = 0; |
| 6752 | SourceRange SR = ReadSourceRange(F, Record, Idx); |
| 6753 | RawComment::CommentKind Kind = |
| 6754 | (RawComment::CommentKind) Record[Idx++]; |
| 6755 | bool IsTrailingComment = Record[Idx++]; |
| 6756 | bool IsAlmostTrailingComment = Record[Idx++]; |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 6757 | Comments.push_back(new (Context) RawComment(SR, Kind, |
| 6758 | IsTrailingComment, |
| 6759 | IsAlmostTrailingComment)); |
Chandler Carruth | 13691bb | 2012-06-20 06:47:54 +0000 | [diff] [blame] | 6760 | break; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6761 | } |
| 6762 | } |
| 6763 | } |
| 6764 | } |
| 6765 | Context.Comments.addCommentsToFront(Comments); |
| 6766 | } |
| 6767 | |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6768 | void ASTReader::finishPendingActions() { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 6769 | while (!PendingIdentifierInfos.empty() || !PendingDeclChains.empty() || |
| 6770 | !PendingMacroIDs.empty()) { |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6771 | // If any identifiers with corresponding top-level declarations have |
| 6772 | // been loaded, load those declarations now. |
| 6773 | while (!PendingIdentifierInfos.empty()) { |
| 6774 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 6775 | PendingIdentifierInfos.front().DeclIDs, true); |
| 6776 | PendingIdentifierInfos.pop_front(); |
| 6777 | } |
| 6778 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 6779 | // Load pending declaration chains. |
| 6780 | for (unsigned I = 0; I != PendingDeclChains.size(); ++I) { |
| 6781 | loadPendingDeclChain(PendingDeclChains[I]); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6782 | PendingDeclChainsKnown.erase(PendingDeclChains[I]); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 6783 | } |
| 6784 | PendingDeclChains.clear(); |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 6785 | |
| 6786 | // Load any pending macro definitions. |
Douglas Gregor | e9652bf | 2012-10-11 17:31:34 +0000 | [diff] [blame] | 6787 | for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) { |
| 6788 | // FIXME: std::move here |
| 6789 | SmallVector<MacroID, 2> GlobalIDs = PendingMacroIDs.begin()[I].second; |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 6790 | MacroInfo *Hint = 0; |
Douglas Gregor | e9652bf | 2012-10-11 17:31:34 +0000 | [diff] [blame] | 6791 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
| 6792 | ++IDIdx) { |
Douglas Gregor | 3ab50fe | 2012-10-11 17:41:54 +0000 | [diff] [blame] | 6793 | Hint = getMacro(GlobalIDs[IDIdx], Hint); |
Douglas Gregor | e9652bf | 2012-10-11 17:31:34 +0000 | [diff] [blame] | 6794 | } |
| 6795 | } |
| 6796 | PendingMacroIDs.clear(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6797 | } |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6798 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 6799 | // If we deserialized any C++ or Objective-C class definitions, any |
| 6800 | // Objective-C protocol definitions, or any redeclarable templates, make sure |
| 6801 | // that all redeclarations point to the definitions. Note that this can only |
| 6802 | // happen now, after the redeclaration chains have been fully wired. |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6803 | for (llvm::SmallPtrSet<Decl *, 4>::iterator D = PendingDefinitions.begin(), |
| 6804 | DEnd = PendingDefinitions.end(); |
| 6805 | D != DEnd; ++D) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6806 | if (TagDecl *TD = dyn_cast<TagDecl>(*D)) { |
| 6807 | if (const TagType *TagT = dyn_cast<TagType>(TD->TypeForDecl)) { |
| 6808 | // Make sure that the TagType points at the definition. |
| 6809 | const_cast<TagType*>(TagT)->decl = TD; |
| 6810 | } |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6811 | |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6812 | if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(*D)) { |
| 6813 | for (CXXRecordDecl::redecl_iterator R = RD->redecls_begin(), |
| 6814 | REnd = RD->redecls_end(); |
| 6815 | R != REnd; ++R) |
| 6816 | cast<CXXRecordDecl>(*R)->DefinitionData = RD->DefinitionData; |
| 6817 | |
| 6818 | } |
| 6819 | |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6820 | continue; |
| 6821 | } |
| 6822 | |
Douglas Gregor | 1d784b2 | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 6823 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(*D)) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6824 | // Make sure that the ObjCInterfaceType points at the definition. |
| 6825 | const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl)) |
| 6826 | ->Decl = ID; |
| 6827 | |
Douglas Gregor | 1d784b2 | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 6828 | for (ObjCInterfaceDecl::redecl_iterator R = ID->redecls_begin(), |
| 6829 | REnd = ID->redecls_end(); |
| 6830 | R != REnd; ++R) |
| 6831 | R->Data = ID->Data; |
| 6832 | |
| 6833 | continue; |
| 6834 | } |
| 6835 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 6836 | if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(*D)) { |
| 6837 | for (ObjCProtocolDecl::redecl_iterator R = PD->redecls_begin(), |
| 6838 | REnd = PD->redecls_end(); |
| 6839 | R != REnd; ++R) |
| 6840 | R->Data = PD->Data; |
| 6841 | |
| 6842 | continue; |
| 6843 | } |
| 6844 | |
| 6845 | RedeclarableTemplateDecl *RTD |
| 6846 | = cast<RedeclarableTemplateDecl>(*D)->getCanonicalDecl(); |
| 6847 | for (RedeclarableTemplateDecl::redecl_iterator R = RTD->redecls_begin(), |
| 6848 | REnd = RTD->redecls_end(); |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6849 | R != REnd; ++R) |
Douglas Gregor | 5456b0fe | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 6850 | R->Common = RTD->Common; |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6851 | } |
| 6852 | PendingDefinitions.clear(); |
Douglas Gregor | 5456b0fe | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 6853 | |
| 6854 | // Load the bodies of any functions or methods we've encountered. We do |
| 6855 | // this now (delayed) so that we can be sure that the declaration chains |
| 6856 | // have been fully wired up. |
Douglas Gregor | ce12d2f | 2012-10-09 17:50:23 +0000 | [diff] [blame] | 6857 | for (PendingBodiesMap::iterator PB = PendingBodies.begin(), |
| 6858 | PBEnd = PendingBodies.end(); |
Douglas Gregor | 5456b0fe | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 6859 | PB != PBEnd; ++PB) { |
| 6860 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) { |
| 6861 | // FIXME: Check for =delete/=default? |
| 6862 | // FIXME: Complain about ODR violations here? |
| 6863 | if (!getContext().getLangOpts().Modules || !FD->hasBody()) |
| 6864 | FD->setLazyBody(PB->second); |
| 6865 | continue; |
| 6866 | } |
| 6867 | |
| 6868 | ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first); |
| 6869 | if (!getContext().getLangOpts().Modules || !MD->hasBody()) |
| 6870 | MD->setLazyBody(PB->second); |
| 6871 | } |
| 6872 | PendingBodies.clear(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6873 | } |
| 6874 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6875 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 6876 | assert(NumCurrentElementsDeserializing && |
| 6877 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 6878 | if (NumCurrentElementsDeserializing == 1) { |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6879 | // We decrease NumCurrentElementsDeserializing only after pending actions |
| 6880 | // are finished, to avoid recursively re-calling finishPendingActions(). |
| 6881 | finishPendingActions(); |
| 6882 | } |
| 6883 | --NumCurrentElementsDeserializing; |
Argyrios Kyrtzidis | 7116833 | 2011-12-17 04:13:28 +0000 | [diff] [blame] | 6884 | |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6885 | if (NumCurrentElementsDeserializing == 0 && |
| 6886 | Consumer && !PassingDeclsToConsumer) { |
| 6887 | // Guard variable to avoid recursively redoing the process of passing |
| 6888 | // decls to consumer. |
| 6889 | SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer, |
| 6890 | true); |
Argyrios Kyrtzidis | 7116833 | 2011-12-17 04:13:28 +0000 | [diff] [blame] | 6891 | |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6892 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 6893 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 6894 | // decls to the consumer. |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6895 | Decl *D = InterestingDecls.front(); |
| 6896 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6897 | PassInterestingDeclToConsumer(D); |
| 6898 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6899 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6900 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 6901 | |
Douglas Gregor | f8a1e51 | 2011-09-02 00:26:20 +0000 | [diff] [blame] | 6902 | ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 6903 | StringRef isysroot, bool DisableValidation, |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 6904 | bool AllowASTWithCompilerErrors) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6905 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 6906 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 6907 | Diags(PP.getDiagnostics()), SemaObj(0), PP(PP), Context(Context), |
Argyrios Kyrtzidis | d64c26f | 2012-10-03 01:58:42 +0000 | [diff] [blame] | 6908 | Consumer(0), ModuleMgr(PP.getFileManager()), |
Douglas Gregor | caed060 | 2012-10-18 21:31:35 +0000 | [diff] [blame] | 6909 | isysroot(isysroot), DisableValidation(DisableValidation), |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 6910 | AllowASTWithCompilerErrors(AllowASTWithCompilerErrors), |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6911 | CurrentGeneration(0), CurrSwitchCaseStmts(&SwitchCaseStmts), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 6912 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 6913 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 6914 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 6915 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 6916 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 6917 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 6918 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6919 | PassingDeclsToConsumer(false), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 6920 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 6921 | { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 6922 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6923 | } |
| 6924 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6925 | ASTReader::~ASTReader() { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6926 | for (DeclContextVisibleUpdatesPending::iterator |
| 6927 | I = PendingVisibleUpdates.begin(), |
| 6928 | E = PendingVisibleUpdates.end(); |
| 6929 | I != E; ++I) { |
| 6930 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 6931 | F = I->second.end(); |
| 6932 | J != F; ++J) |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 6933 | delete J->first; |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6934 | } |
| 6935 | } |