Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 1 | //===-- ASTReader.cpp - AST File Reader ----------------------------------===// |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +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 | // |
| 10 | // This file defines the ASTReader class, which reads AST files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Serialization/ASTReader.h" |
| 15 | #include "ASTCommon.h" |
| 16 | #include "ASTReaderInternals.h" |
| 17 | #include "clang/AST/ASTConsumer.h" |
| 18 | #include "clang/AST/ASTContext.h" |
| 19 | #include "clang/AST/DeclTemplate.h" |
| 20 | #include "clang/AST/Expr.h" |
| 21 | #include "clang/AST/ExprCXX.h" |
| 22 | #include "clang/AST/NestedNameSpecifier.h" |
| 23 | #include "clang/AST/Type.h" |
| 24 | #include "clang/AST/TypeLocVisitor.h" |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 25 | #include "clang/Basic/DiagnosticOptions.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 26 | #include "clang/Basic/FileManager.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 27 | #include "clang/Basic/SourceManager.h" |
| 28 | #include "clang/Basic/SourceManagerInternals.h" |
| 29 | #include "clang/Basic/TargetInfo.h" |
| 30 | #include "clang/Basic/TargetOptions.h" |
| 31 | #include "clang/Basic/Version.h" |
| 32 | #include "clang/Basic/VersionTuple.h" |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 33 | #include "clang/Frontend/Utils.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 34 | #include "clang/Lex/HeaderSearch.h" |
| 35 | #include "clang/Lex/HeaderSearchOptions.h" |
| 36 | #include "clang/Lex/MacroInfo.h" |
| 37 | #include "clang/Lex/PreprocessingRecord.h" |
| 38 | #include "clang/Lex/Preprocessor.h" |
| 39 | #include "clang/Lex/PreprocessorOptions.h" |
| 40 | #include "clang/Sema/Scope.h" |
| 41 | #include "clang/Sema/Sema.h" |
| 42 | #include "clang/Serialization/ASTDeserializationListener.h" |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 43 | #include "clang/Serialization/GlobalModuleIndex.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 44 | #include "clang/Serialization/ModuleManager.h" |
| 45 | #include "clang/Serialization/SerializationDiagnostic.h" |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 46 | #include "llvm/ADT/Hashing.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 47 | #include "llvm/ADT/StringExtras.h" |
| 48 | #include "llvm/Bitcode/BitstreamReader.h" |
| 49 | #include "llvm/Support/ErrorHandling.h" |
| 50 | #include "llvm/Support/FileSystem.h" |
| 51 | #include "llvm/Support/MemoryBuffer.h" |
| 52 | #include "llvm/Support/Path.h" |
| 53 | #include "llvm/Support/SaveAndRestore.h" |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 54 | #include "llvm/Support/raw_ostream.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 55 | #include <algorithm> |
Chris Lattner | 91f373e | 2013-01-20 00:57:52 +0000 | [diff] [blame] | 56 | #include <cstdio> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 57 | #include <iterator> |
Rafael Espindola | 8a8e554 | 2014-06-12 17:19:42 +0000 | [diff] [blame] | 58 | #include <system_error> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 59 | |
| 60 | using namespace clang; |
| 61 | using namespace clang::serialization; |
| 62 | using namespace clang::serialization::reader; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 63 | using llvm::BitstreamCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 64 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 65 | |
| 66 | //===----------------------------------------------------------------------===// |
| 67 | // ChainedASTReaderListener implementation |
| 68 | //===----------------------------------------------------------------------===// |
| 69 | |
| 70 | bool |
| 71 | ChainedASTReaderListener::ReadFullVersionInformation(StringRef FullVersion) { |
| 72 | return First->ReadFullVersionInformation(FullVersion) || |
| 73 | Second->ReadFullVersionInformation(FullVersion); |
| 74 | } |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 75 | void ChainedASTReaderListener::ReadModuleName(StringRef ModuleName) { |
| 76 | First->ReadModuleName(ModuleName); |
| 77 | Second->ReadModuleName(ModuleName); |
| 78 | } |
| 79 | void ChainedASTReaderListener::ReadModuleMapFile(StringRef ModuleMapPath) { |
| 80 | First->ReadModuleMapFile(ModuleMapPath); |
| 81 | Second->ReadModuleMapFile(ModuleMapPath); |
| 82 | } |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 83 | bool |
| 84 | ChainedASTReaderListener::ReadLanguageOptions(const LangOptions &LangOpts, |
| 85 | bool Complain, |
| 86 | bool AllowCompatibleDifferences) { |
| 87 | return First->ReadLanguageOptions(LangOpts, Complain, |
| 88 | AllowCompatibleDifferences) || |
| 89 | Second->ReadLanguageOptions(LangOpts, Complain, |
| 90 | AllowCompatibleDifferences); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 91 | } |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 92 | bool ChainedASTReaderListener::ReadTargetOptions( |
| 93 | const TargetOptions &TargetOpts, bool Complain, |
| 94 | bool AllowCompatibleDifferences) { |
| 95 | return First->ReadTargetOptions(TargetOpts, Complain, |
| 96 | AllowCompatibleDifferences) || |
| 97 | Second->ReadTargetOptions(TargetOpts, Complain, |
| 98 | AllowCompatibleDifferences); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 99 | } |
| 100 | bool ChainedASTReaderListener::ReadDiagnosticOptions( |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 101 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 102 | return First->ReadDiagnosticOptions(DiagOpts, Complain) || |
| 103 | Second->ReadDiagnosticOptions(DiagOpts, Complain); |
| 104 | } |
| 105 | bool |
| 106 | ChainedASTReaderListener::ReadFileSystemOptions(const FileSystemOptions &FSOpts, |
| 107 | bool Complain) { |
| 108 | return First->ReadFileSystemOptions(FSOpts, Complain) || |
| 109 | Second->ReadFileSystemOptions(FSOpts, Complain); |
| 110 | } |
| 111 | |
| 112 | bool ChainedASTReaderListener::ReadHeaderSearchOptions( |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 113 | const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, |
| 114 | bool Complain) { |
| 115 | return First->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 116 | Complain) || |
| 117 | Second->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 118 | Complain); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 119 | } |
| 120 | bool ChainedASTReaderListener::ReadPreprocessorOptions( |
| 121 | const PreprocessorOptions &PPOpts, bool Complain, |
| 122 | std::string &SuggestedPredefines) { |
| 123 | return First->ReadPreprocessorOptions(PPOpts, Complain, |
| 124 | SuggestedPredefines) || |
| 125 | Second->ReadPreprocessorOptions(PPOpts, Complain, SuggestedPredefines); |
| 126 | } |
| 127 | void ChainedASTReaderListener::ReadCounter(const serialization::ModuleFile &M, |
| 128 | unsigned Value) { |
| 129 | First->ReadCounter(M, Value); |
| 130 | Second->ReadCounter(M, Value); |
| 131 | } |
| 132 | bool ChainedASTReaderListener::needsInputFileVisitation() { |
| 133 | return First->needsInputFileVisitation() || |
| 134 | Second->needsInputFileVisitation(); |
| 135 | } |
| 136 | bool ChainedASTReaderListener::needsSystemInputFileVisitation() { |
| 137 | return First->needsSystemInputFileVisitation() || |
| 138 | Second->needsSystemInputFileVisitation(); |
| 139 | } |
Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 140 | void ChainedASTReaderListener::visitModuleFile(StringRef Filename) { |
| 141 | First->visitModuleFile(Filename); |
| 142 | Second->visitModuleFile(Filename); |
| 143 | } |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 144 | bool ChainedASTReaderListener::visitInputFile(StringRef Filename, |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 145 | bool isSystem, |
| 146 | bool isOverridden) { |
Justin Bogner | c65a66d | 2014-05-22 06:04:59 +0000 | [diff] [blame] | 147 | bool Continue = false; |
| 148 | if (First->needsInputFileVisitation() && |
| 149 | (!isSystem || First->needsSystemInputFileVisitation())) |
| 150 | Continue |= First->visitInputFile(Filename, isSystem, isOverridden); |
| 151 | if (Second->needsInputFileVisitation() && |
| 152 | (!isSystem || Second->needsSystemInputFileVisitation())) |
| 153 | Continue |= Second->visitInputFile(Filename, isSystem, isOverridden); |
| 154 | return Continue; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 157 | //===----------------------------------------------------------------------===// |
| 158 | // PCH validator implementation |
| 159 | //===----------------------------------------------------------------------===// |
| 160 | |
| 161 | ASTReaderListener::~ASTReaderListener() {} |
| 162 | |
| 163 | /// \brief Compare the given set of language options against an existing set of |
| 164 | /// language options. |
| 165 | /// |
| 166 | /// \param Diags If non-NULL, diagnostics will be emitted via this engine. |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 167 | /// \param AllowCompatibleDifferences If true, differences between compatible |
| 168 | /// language options will be permitted. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 169 | /// |
| 170 | /// \returns true if the languagae options mis-match, false otherwise. |
| 171 | static bool checkLanguageOptions(const LangOptions &LangOpts, |
| 172 | const LangOptions &ExistingLangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 173 | DiagnosticsEngine *Diags, |
| 174 | bool AllowCompatibleDifferences = true) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 175 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 176 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 177 | if (Diags) \ |
| 178 | Diags->Report(diag::err_pch_langopt_mismatch) \ |
| 179 | << Description << LangOpts.Name << ExistingLangOpts.Name; \ |
| 180 | return true; \ |
| 181 | } |
| 182 | |
| 183 | #define VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 184 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 185 | if (Diags) \ |
| 186 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 187 | << Description; \ |
| 188 | return true; \ |
| 189 | } |
| 190 | |
| 191 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 192 | if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \ |
| 193 | if (Diags) \ |
| 194 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 195 | << Description; \ |
| 196 | return true; \ |
| 197 | } |
| 198 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 199 | #define COMPATIBLE_LANGOPT(Name, Bits, Default, Description) \ |
| 200 | if (!AllowCompatibleDifferences) \ |
| 201 | LANGOPT(Name, Bits, Default, Description) |
| 202 | |
| 203 | #define COMPATIBLE_ENUM_LANGOPT(Name, Bits, Default, Description) \ |
| 204 | if (!AllowCompatibleDifferences) \ |
| 205 | ENUM_LANGOPT(Name, Bits, Default, Description) |
| 206 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 207 | #define BENIGN_LANGOPT(Name, Bits, Default, Description) |
| 208 | #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
| 209 | #include "clang/Basic/LangOptions.def" |
| 210 | |
| 211 | if (ExistingLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) { |
| 212 | if (Diags) |
| 213 | Diags->Report(diag::err_pch_langopt_value_mismatch) |
| 214 | << "target Objective-C runtime"; |
| 215 | return true; |
| 216 | } |
| 217 | |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 218 | if (ExistingLangOpts.CommentOpts.BlockCommandNames != |
| 219 | LangOpts.CommentOpts.BlockCommandNames) { |
| 220 | if (Diags) |
| 221 | Diags->Report(diag::err_pch_langopt_value_mismatch) |
| 222 | << "block command names"; |
| 223 | return true; |
| 224 | } |
| 225 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 226 | return false; |
| 227 | } |
| 228 | |
| 229 | /// \brief Compare the given set of target options against an existing set of |
| 230 | /// target options. |
| 231 | /// |
| 232 | /// \param Diags If non-NULL, diagnostics will be emitted via this engine. |
| 233 | /// |
| 234 | /// \returns true if the target options mis-match, false otherwise. |
| 235 | static bool checkTargetOptions(const TargetOptions &TargetOpts, |
| 236 | const TargetOptions &ExistingTargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 237 | DiagnosticsEngine *Diags, |
| 238 | bool AllowCompatibleDifferences = true) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 239 | #define CHECK_TARGET_OPT(Field, Name) \ |
| 240 | if (TargetOpts.Field != ExistingTargetOpts.Field) { \ |
| 241 | if (Diags) \ |
| 242 | Diags->Report(diag::err_pch_targetopt_mismatch) \ |
| 243 | << Name << TargetOpts.Field << ExistingTargetOpts.Field; \ |
| 244 | return true; \ |
| 245 | } |
| 246 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 247 | // The triple and ABI must match exactly. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 248 | CHECK_TARGET_OPT(Triple, "target"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 249 | CHECK_TARGET_OPT(ABI, "target ABI"); |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 250 | |
| 251 | // We can tolerate different CPUs in many cases, notably when one CPU |
| 252 | // supports a strict superset of another. When allowing compatible |
| 253 | // differences skip this check. |
| 254 | if (!AllowCompatibleDifferences) |
| 255 | CHECK_TARGET_OPT(CPU, "target CPU"); |
| 256 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 257 | #undef CHECK_TARGET_OPT |
| 258 | |
| 259 | // Compare feature sets. |
| 260 | SmallVector<StringRef, 4> ExistingFeatures( |
| 261 | ExistingTargetOpts.FeaturesAsWritten.begin(), |
| 262 | ExistingTargetOpts.FeaturesAsWritten.end()); |
| 263 | SmallVector<StringRef, 4> ReadFeatures(TargetOpts.FeaturesAsWritten.begin(), |
| 264 | TargetOpts.FeaturesAsWritten.end()); |
| 265 | std::sort(ExistingFeatures.begin(), ExistingFeatures.end()); |
| 266 | std::sort(ReadFeatures.begin(), ReadFeatures.end()); |
| 267 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 268 | // We compute the set difference in both directions explicitly so that we can |
| 269 | // diagnose the differences differently. |
| 270 | SmallVector<StringRef, 4> UnmatchedExistingFeatures, UnmatchedReadFeatures; |
| 271 | std::set_difference( |
| 272 | ExistingFeatures.begin(), ExistingFeatures.end(), ReadFeatures.begin(), |
| 273 | ReadFeatures.end(), std::back_inserter(UnmatchedExistingFeatures)); |
| 274 | std::set_difference(ReadFeatures.begin(), ReadFeatures.end(), |
| 275 | ExistingFeatures.begin(), ExistingFeatures.end(), |
| 276 | std::back_inserter(UnmatchedReadFeatures)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 277 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 278 | // If we are allowing compatible differences and the read feature set is |
| 279 | // a strict subset of the existing feature set, there is nothing to diagnose. |
| 280 | if (AllowCompatibleDifferences && UnmatchedReadFeatures.empty()) |
| 281 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 282 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 283 | if (Diags) { |
| 284 | for (StringRef Feature : UnmatchedReadFeatures) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 285 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 286 | << /* is-existing-feature */ false << Feature; |
| 287 | for (StringRef Feature : UnmatchedExistingFeatures) |
| 288 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
| 289 | << /* is-existing-feature */ true << Feature; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 292 | return !UnmatchedReadFeatures.empty() || !UnmatchedExistingFeatures.empty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | bool |
| 296 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 297 | bool Complain, |
| 298 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 299 | const LangOptions &ExistingLangOpts = PP.getLangOpts(); |
| 300 | return checkLanguageOptions(LangOpts, ExistingLangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 301 | Complain ? &Reader.Diags : nullptr, |
| 302 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | bool PCHValidator::ReadTargetOptions(const TargetOptions &TargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 306 | bool Complain, |
| 307 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 308 | const TargetOptions &ExistingTargetOpts = PP.getTargetInfo().getTargetOpts(); |
| 309 | return checkTargetOptions(TargetOpts, ExistingTargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 310 | Complain ? &Reader.Diags : nullptr, |
| 311 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | namespace { |
| 315 | typedef llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> > |
| 316 | MacroDefinitionsMap; |
Craig Topper | 3598eb7 | 2013-07-05 04:43:31 +0000 | [diff] [blame] | 317 | typedef llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8> > |
| 318 | DeclsMap; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 321 | static bool checkDiagnosticGroupMappings(DiagnosticsEngine &StoredDiags, |
| 322 | DiagnosticsEngine &Diags, |
| 323 | bool Complain) { |
| 324 | typedef DiagnosticsEngine::Level Level; |
| 325 | |
| 326 | // Check current mappings for new -Werror mappings, and the stored mappings |
| 327 | // for cases that were explicitly mapped to *not* be errors that are now |
| 328 | // errors because of options like -Werror. |
| 329 | DiagnosticsEngine *MappingSources[] = { &Diags, &StoredDiags }; |
| 330 | |
| 331 | for (DiagnosticsEngine *MappingSource : MappingSources) { |
| 332 | for (auto DiagIDMappingPair : MappingSource->getDiagnosticMappings()) { |
| 333 | diag::kind DiagID = DiagIDMappingPair.first; |
| 334 | Level CurLevel = Diags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 335 | if (CurLevel < DiagnosticsEngine::Error) |
| 336 | continue; // not significant |
| 337 | Level StoredLevel = |
| 338 | StoredDiags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 339 | if (StoredLevel < DiagnosticsEngine::Error) { |
| 340 | if (Complain) |
| 341 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror=" + |
| 342 | Diags.getDiagnosticIDs()->getWarningOptionForDiag(DiagID).str(); |
| 343 | return true; |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | return false; |
| 349 | } |
| 350 | |
Alp Toker | ac4e8e5 | 2014-06-22 21:58:33 +0000 | [diff] [blame] | 351 | static bool isExtHandlingFromDiagsError(DiagnosticsEngine &Diags) { |
| 352 | diag::Severity Ext = Diags.getExtensionHandlingBehavior(); |
| 353 | if (Ext == diag::Severity::Warning && Diags.getWarningsAsErrors()) |
| 354 | return true; |
| 355 | return Ext >= diag::Severity::Error; |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static bool checkDiagnosticMappings(DiagnosticsEngine &StoredDiags, |
| 359 | DiagnosticsEngine &Diags, |
| 360 | bool IsSystem, bool Complain) { |
| 361 | // Top-level options |
| 362 | if (IsSystem) { |
| 363 | if (Diags.getSuppressSystemWarnings()) |
| 364 | return false; |
| 365 | // If -Wsystem-headers was not enabled before, be conservative |
| 366 | if (StoredDiags.getSuppressSystemWarnings()) { |
| 367 | if (Complain) |
| 368 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Wsystem-headers"; |
| 369 | return true; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | if (Diags.getWarningsAsErrors() && !StoredDiags.getWarningsAsErrors()) { |
| 374 | if (Complain) |
| 375 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror"; |
| 376 | return true; |
| 377 | } |
| 378 | |
| 379 | if (Diags.getWarningsAsErrors() && Diags.getEnableAllWarnings() && |
| 380 | !StoredDiags.getEnableAllWarnings()) { |
| 381 | if (Complain) |
| 382 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Weverything -Werror"; |
| 383 | return true; |
| 384 | } |
| 385 | |
| 386 | if (isExtHandlingFromDiagsError(Diags) && |
| 387 | !isExtHandlingFromDiagsError(StoredDiags)) { |
| 388 | if (Complain) |
| 389 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-pedantic-errors"; |
| 390 | return true; |
| 391 | } |
| 392 | |
| 393 | return checkDiagnosticGroupMappings(StoredDiags, Diags, Complain); |
| 394 | } |
| 395 | |
| 396 | bool PCHValidator::ReadDiagnosticOptions( |
| 397 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { |
| 398 | DiagnosticsEngine &ExistingDiags = PP.getDiagnostics(); |
| 399 | IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(ExistingDiags.getDiagnosticIDs()); |
| 400 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags( |
Alp Toker | f994cef | 2014-07-05 03:08:06 +0000 | [diff] [blame] | 401 | new DiagnosticsEngine(DiagIDs, DiagOpts.get())); |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 402 | // This should never fail, because we would have processed these options |
| 403 | // before writing them to an ASTFile. |
| 404 | ProcessWarningOptions(*Diags, *DiagOpts, /*Report*/false); |
| 405 | |
| 406 | ModuleManager &ModuleMgr = Reader.getModuleManager(); |
| 407 | assert(ModuleMgr.size() >= 1 && "what ASTFile is this then"); |
| 408 | |
| 409 | // If the original import came from a file explicitly generated by the user, |
| 410 | // don't check the diagnostic mappings. |
| 411 | // FIXME: currently this is approximated by checking whether this is not a |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 412 | // module import of an implicitly-loaded module file. |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 413 | // Note: ModuleMgr.rbegin() may not be the current module, but it must be in |
| 414 | // the transitive closure of its imports, since unrelated modules cannot be |
| 415 | // imported until after this module finishes validation. |
| 416 | ModuleFile *TopImport = *ModuleMgr.rbegin(); |
| 417 | while (!TopImport->ImportedBy.empty()) |
| 418 | TopImport = TopImport->ImportedBy[0]; |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 419 | if (TopImport->Kind != MK_ImplicitModule) |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 420 | return false; |
| 421 | |
| 422 | StringRef ModuleName = TopImport->ModuleName; |
| 423 | assert(!ModuleName.empty() && "diagnostic options read before module name"); |
| 424 | |
| 425 | Module *M = PP.getHeaderSearchInfo().lookupModule(ModuleName); |
| 426 | assert(M && "missing module"); |
| 427 | |
| 428 | // FIXME: if the diagnostics are incompatible, save a DiagnosticOptions that |
| 429 | // contains the union of their flags. |
| 430 | return checkDiagnosticMappings(*Diags, ExistingDiags, M->IsSystem, Complain); |
| 431 | } |
| 432 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 433 | /// \brief Collect the macro definitions provided by the given preprocessor |
| 434 | /// options. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 435 | static void |
| 436 | collectMacroDefinitions(const PreprocessorOptions &PPOpts, |
| 437 | MacroDefinitionsMap &Macros, |
| 438 | SmallVectorImpl<StringRef> *MacroNames = nullptr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 439 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 440 | StringRef Macro = PPOpts.Macros[I].first; |
| 441 | bool IsUndef = PPOpts.Macros[I].second; |
| 442 | |
| 443 | std::pair<StringRef, StringRef> MacroPair = Macro.split('='); |
| 444 | StringRef MacroName = MacroPair.first; |
| 445 | StringRef MacroBody = MacroPair.second; |
| 446 | |
| 447 | // For an #undef'd macro, we only care about the name. |
| 448 | if (IsUndef) { |
| 449 | if (MacroNames && !Macros.count(MacroName)) |
| 450 | MacroNames->push_back(MacroName); |
| 451 | |
| 452 | Macros[MacroName] = std::make_pair("", true); |
| 453 | continue; |
| 454 | } |
| 455 | |
| 456 | // For a #define'd macro, figure out the actual definition. |
| 457 | if (MacroName.size() == Macro.size()) |
| 458 | MacroBody = "1"; |
| 459 | else { |
| 460 | // Note: GCC drops anything following an end-of-line character. |
| 461 | StringRef::size_type End = MacroBody.find_first_of("\n\r"); |
| 462 | MacroBody = MacroBody.substr(0, End); |
| 463 | } |
| 464 | |
| 465 | if (MacroNames && !Macros.count(MacroName)) |
| 466 | MacroNames->push_back(MacroName); |
| 467 | Macros[MacroName] = std::make_pair(MacroBody, false); |
| 468 | } |
| 469 | } |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 470 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 471 | /// \brief Check the preprocessor options deserialized from the control block |
| 472 | /// against the preprocessor options in an existing preprocessor. |
| 473 | /// |
| 474 | /// \param Diags If non-null, produce diagnostics for any mismatches incurred. |
| 475 | static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 476 | const PreprocessorOptions &ExistingPPOpts, |
| 477 | DiagnosticsEngine *Diags, |
| 478 | FileManager &FileMgr, |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 479 | std::string &SuggestedPredefines, |
| 480 | const LangOptions &LangOpts) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 481 | // Check macro definitions. |
| 482 | MacroDefinitionsMap ASTFileMacros; |
| 483 | collectMacroDefinitions(PPOpts, ASTFileMacros); |
| 484 | MacroDefinitionsMap ExistingMacros; |
| 485 | SmallVector<StringRef, 4> ExistingMacroNames; |
| 486 | collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames); |
| 487 | |
| 488 | for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) { |
| 489 | // Dig out the macro definition in the existing preprocessor options. |
| 490 | StringRef MacroName = ExistingMacroNames[I]; |
| 491 | std::pair<StringRef, bool> Existing = ExistingMacros[MacroName]; |
| 492 | |
| 493 | // Check whether we know anything about this macro name or not. |
| 494 | llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> >::iterator Known |
| 495 | = ASTFileMacros.find(MacroName); |
| 496 | if (Known == ASTFileMacros.end()) { |
| 497 | // FIXME: Check whether this identifier was referenced anywhere in the |
| 498 | // AST file. If so, we should reject the AST file. Unfortunately, this |
| 499 | // information isn't in the control block. What shall we do about it? |
| 500 | |
| 501 | if (Existing.second) { |
| 502 | SuggestedPredefines += "#undef "; |
| 503 | SuggestedPredefines += MacroName.str(); |
| 504 | SuggestedPredefines += '\n'; |
| 505 | } else { |
| 506 | SuggestedPredefines += "#define "; |
| 507 | SuggestedPredefines += MacroName.str(); |
| 508 | SuggestedPredefines += ' '; |
| 509 | SuggestedPredefines += Existing.first.str(); |
| 510 | SuggestedPredefines += '\n'; |
| 511 | } |
| 512 | continue; |
| 513 | } |
| 514 | |
| 515 | // If the macro was defined in one but undef'd in the other, we have a |
| 516 | // conflict. |
| 517 | if (Existing.second != Known->second.second) { |
| 518 | if (Diags) { |
| 519 | Diags->Report(diag::err_pch_macro_def_undef) |
| 520 | << MacroName << Known->second.second; |
| 521 | } |
| 522 | return true; |
| 523 | } |
| 524 | |
| 525 | // If the macro was #undef'd in both, or if the macro bodies are identical, |
| 526 | // it's fine. |
| 527 | if (Existing.second || Existing.first == Known->second.first) |
| 528 | continue; |
| 529 | |
| 530 | // The macro bodies differ; complain. |
| 531 | if (Diags) { |
| 532 | Diags->Report(diag::err_pch_macro_def_conflict) |
| 533 | << MacroName << Known->second.first << Existing.first; |
| 534 | } |
| 535 | return true; |
| 536 | } |
| 537 | |
| 538 | // Check whether we're using predefines. |
| 539 | if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines) { |
| 540 | if (Diags) { |
| 541 | Diags->Report(diag::err_pch_undef) << ExistingPPOpts.UsePredefines; |
| 542 | } |
| 543 | return true; |
| 544 | } |
| 545 | |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 546 | // Detailed record is important since it is used for the module cache hash. |
| 547 | if (LangOpts.Modules && |
| 548 | PPOpts.DetailedRecord != ExistingPPOpts.DetailedRecord) { |
| 549 | if (Diags) { |
| 550 | Diags->Report(diag::err_pch_pp_detailed_record) << PPOpts.DetailedRecord; |
| 551 | } |
| 552 | return true; |
| 553 | } |
| 554 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 555 | // Compute the #include and #include_macros lines we need. |
| 556 | for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) { |
| 557 | StringRef File = ExistingPPOpts.Includes[I]; |
| 558 | if (File == ExistingPPOpts.ImplicitPCHInclude) |
| 559 | continue; |
| 560 | |
| 561 | if (std::find(PPOpts.Includes.begin(), PPOpts.Includes.end(), File) |
| 562 | != PPOpts.Includes.end()) |
| 563 | continue; |
| 564 | |
| 565 | SuggestedPredefines += "#include \""; |
Manuel Klimek | 9af34ae | 2014-08-12 08:25:57 +0000 | [diff] [blame] | 566 | SuggestedPredefines += File; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 567 | SuggestedPredefines += "\"\n"; |
| 568 | } |
| 569 | |
| 570 | for (unsigned I = 0, N = ExistingPPOpts.MacroIncludes.size(); I != N; ++I) { |
| 571 | StringRef File = ExistingPPOpts.MacroIncludes[I]; |
| 572 | if (std::find(PPOpts.MacroIncludes.begin(), PPOpts.MacroIncludes.end(), |
| 573 | File) |
| 574 | != PPOpts.MacroIncludes.end()) |
| 575 | continue; |
| 576 | |
| 577 | SuggestedPredefines += "#__include_macros \""; |
Manuel Klimek | 9af34ae | 2014-08-12 08:25:57 +0000 | [diff] [blame] | 578 | SuggestedPredefines += File; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 579 | SuggestedPredefines += "\"\n##\n"; |
| 580 | } |
| 581 | |
| 582 | return false; |
| 583 | } |
| 584 | |
| 585 | bool PCHValidator::ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 586 | bool Complain, |
| 587 | std::string &SuggestedPredefines) { |
| 588 | const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts(); |
| 589 | |
| 590 | return checkPreprocessorOptions(PPOpts, ExistingPPOpts, |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 591 | Complain? &Reader.Diags : nullptr, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 592 | PP.getFileManager(), |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 593 | SuggestedPredefines, |
| 594 | PP.getLangOpts()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 595 | } |
| 596 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 597 | /// Check the header search options deserialized from the control block |
| 598 | /// against the header search options in an existing preprocessor. |
| 599 | /// |
| 600 | /// \param Diags If non-null, produce diagnostics for any mismatches incurred. |
| 601 | static bool checkHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 602 | StringRef SpecificModuleCachePath, |
| 603 | StringRef ExistingModuleCachePath, |
| 604 | DiagnosticsEngine *Diags, |
| 605 | const LangOptions &LangOpts) { |
| 606 | if (LangOpts.Modules) { |
| 607 | if (SpecificModuleCachePath != ExistingModuleCachePath) { |
| 608 | if (Diags) |
| 609 | Diags->Report(diag::err_pch_modulecache_mismatch) |
| 610 | << SpecificModuleCachePath << ExistingModuleCachePath; |
| 611 | return true; |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | return false; |
| 616 | } |
| 617 | |
| 618 | bool PCHValidator::ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 619 | StringRef SpecificModuleCachePath, |
| 620 | bool Complain) { |
| 621 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 622 | PP.getHeaderSearchInfo().getModuleCachePath(), |
| 623 | Complain ? &Reader.Diags : nullptr, |
| 624 | PP.getLangOpts()); |
| 625 | } |
| 626 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 627 | void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) { |
| 628 | PP.setCounterValue(Value); |
| 629 | } |
| 630 | |
| 631 | //===----------------------------------------------------------------------===// |
| 632 | // AST reader implementation |
| 633 | //===----------------------------------------------------------------------===// |
| 634 | |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 635 | void ASTReader::setDeserializationListener(ASTDeserializationListener *Listener, |
| 636 | bool TakeOwnership) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 637 | DeserializationListener = Listener; |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 638 | OwnsDeserializationListener = TakeOwnership; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | |
| 642 | |
| 643 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 644 | return serialization::ComputeHash(Sel); |
| 645 | } |
| 646 | |
| 647 | |
| 648 | std::pair<unsigned, unsigned> |
| 649 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 650 | using namespace llvm::support; |
| 651 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 652 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 653 | return std::make_pair(KeyLen, DataLen); |
| 654 | } |
| 655 | |
| 656 | ASTSelectorLookupTrait::internal_key_type |
| 657 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 658 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 659 | SelectorTable &SelTable = Reader.getContext().Selectors; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 660 | unsigned N = endian::readNext<uint16_t, little, unaligned>(d); |
| 661 | IdentifierInfo *FirstII = Reader.getLocalIdentifier( |
| 662 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 663 | if (N == 0) |
| 664 | return SelTable.getNullarySelector(FirstII); |
| 665 | else if (N == 1) |
| 666 | return SelTable.getUnarySelector(FirstII); |
| 667 | |
| 668 | SmallVector<IdentifierInfo *, 16> Args; |
| 669 | Args.push_back(FirstII); |
| 670 | for (unsigned I = 1; I != N; ++I) |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 671 | Args.push_back(Reader.getLocalIdentifier( |
| 672 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 673 | |
| 674 | return SelTable.getSelector(N, Args.data()); |
| 675 | } |
| 676 | |
| 677 | ASTSelectorLookupTrait::data_type |
| 678 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
| 679 | unsigned DataLen) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 680 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 681 | |
| 682 | data_type Result; |
| 683 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 684 | Result.ID = Reader.getGlobalSelectorID( |
| 685 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 686 | unsigned FullInstanceBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 687 | unsigned FullFactoryBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 688 | Result.InstanceBits = FullInstanceBits & 0x3; |
| 689 | Result.InstanceHasMoreThanOneDecl = (FullInstanceBits >> 2) & 0x1; |
| 690 | Result.FactoryBits = FullFactoryBits & 0x3; |
| 691 | Result.FactoryHasMoreThanOneDecl = (FullFactoryBits >> 2) & 0x1; |
| 692 | unsigned NumInstanceMethods = FullInstanceBits >> 3; |
| 693 | unsigned NumFactoryMethods = FullFactoryBits >> 3; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 694 | |
| 695 | // Load instance methods |
| 696 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 697 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| 698 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 699 | Result.Instance.push_back(Method); |
| 700 | } |
| 701 | |
| 702 | // Load factory methods |
| 703 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 704 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| 705 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 706 | Result.Factory.push_back(Method); |
| 707 | } |
| 708 | |
| 709 | return Result; |
| 710 | } |
| 711 | |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 712 | unsigned ASTIdentifierLookupTraitBase::ComputeHash(const internal_key_type& a) { |
| 713 | return llvm::HashString(a); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | std::pair<unsigned, unsigned> |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 717 | ASTIdentifierLookupTraitBase::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 718 | using namespace llvm::support; |
| 719 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 720 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 721 | return std::make_pair(KeyLen, DataLen); |
| 722 | } |
| 723 | |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 724 | ASTIdentifierLookupTraitBase::internal_key_type |
| 725 | ASTIdentifierLookupTraitBase::ReadKey(const unsigned char* d, unsigned n) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 726 | assert(n >= 2 && d[n-1] == '\0'); |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 727 | return StringRef((const char*) d, n-1); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 728 | } |
| 729 | |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 730 | /// \brief Whether the given identifier is "interesting". |
| 731 | static bool isInterestingIdentifier(IdentifierInfo &II) { |
| 732 | return II.isPoisoned() || |
| 733 | II.isExtensionToken() || |
| 734 | II.getObjCOrBuiltinID() || |
| 735 | II.hasRevertedTokenIDToIdentifier() || |
| 736 | II.hadMacroDefinition() || |
| 737 | II.getFETokenInfo<void>(); |
| 738 | } |
| 739 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 740 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 741 | const unsigned char* d, |
| 742 | unsigned DataLen) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 743 | using namespace llvm::support; |
| 744 | unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 745 | bool IsInteresting = RawID & 0x01; |
| 746 | |
| 747 | // Wipe out the "is interesting" bit. |
| 748 | RawID = RawID >> 1; |
| 749 | |
| 750 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 751 | if (!IsInteresting) { |
| 752 | // For uninteresting identifiers, just build the IdentifierInfo |
| 753 | // and associate it with the persistent ID. |
| 754 | IdentifierInfo *II = KnownII; |
| 755 | if (!II) { |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 756 | II = &Reader.getIdentifierTable().getOwn(k); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 757 | KnownII = II; |
| 758 | } |
| 759 | Reader.SetIdentifierInfo(ID, II); |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 760 | if (!II->isFromAST()) { |
| 761 | bool WasInteresting = isInterestingIdentifier(*II); |
| 762 | II->setIsFromAST(); |
| 763 | if (WasInteresting) |
| 764 | II->setChangedSinceDeserialization(); |
| 765 | } |
| 766 | Reader.markIdentifierUpToDate(II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 767 | return II; |
| 768 | } |
| 769 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 770 | unsigned ObjCOrBuiltinID = endian::readNext<uint16_t, little, unaligned>(d); |
| 771 | unsigned Bits = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 772 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 773 | Bits >>= 1; |
| 774 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 775 | Bits >>= 1; |
| 776 | bool Poisoned = Bits & 0x01; |
| 777 | Bits >>= 1; |
| 778 | bool ExtensionToken = Bits & 0x01; |
| 779 | Bits >>= 1; |
| 780 | bool hadMacroDefinition = Bits & 0x01; |
| 781 | Bits >>= 1; |
| 782 | |
| 783 | assert(Bits == 0 && "Extra bits in the identifier?"); |
| 784 | DataLen -= 8; |
| 785 | |
| 786 | // Build the IdentifierInfo itself and link the identifier ID with |
| 787 | // the new IdentifierInfo. |
| 788 | IdentifierInfo *II = KnownII; |
| 789 | if (!II) { |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 790 | II = &Reader.getIdentifierTable().getOwn(StringRef(k)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 791 | KnownII = II; |
| 792 | } |
| 793 | Reader.markIdentifierUpToDate(II); |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 794 | if (!II->isFromAST()) { |
| 795 | bool WasInteresting = isInterestingIdentifier(*II); |
| 796 | II->setIsFromAST(); |
| 797 | if (WasInteresting) |
| 798 | II->setChangedSinceDeserialization(); |
| 799 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 800 | |
| 801 | // Set or check the various bits in the IdentifierInfo structure. |
| 802 | // Token IDs are read-only. |
Argyrios Kyrtzidis | ddee8c9 | 2013-02-27 01:13:51 +0000 | [diff] [blame] | 803 | if (HasRevertedTokenIDToIdentifier && II->getTokenID() != tok::identifier) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 804 | II->RevertTokenIDToIdentifier(); |
| 805 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 806 | assert(II->isExtensionToken() == ExtensionToken && |
| 807 | "Incorrect extension token flag"); |
| 808 | (void)ExtensionToken; |
| 809 | if (Poisoned) |
| 810 | II->setIsPoisoned(true); |
| 811 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 812 | "Incorrect C++ operator keyword flag"); |
| 813 | (void)CPlusPlusOperatorKeyword; |
| 814 | |
| 815 | // If this identifier is a macro, deserialize the macro |
| 816 | // definition. |
| 817 | if (hadMacroDefinition) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 818 | uint32_t MacroDirectivesOffset = |
| 819 | endian::readNext<uint32_t, little, unaligned>(d); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 820 | DataLen -= 4; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 821 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 822 | Reader.addPendingMacro(II, &F, MacroDirectivesOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | Reader.SetIdentifierInfo(ID, II); |
| 826 | |
| 827 | // Read all of the declarations visible at global scope with this |
| 828 | // name. |
| 829 | if (DataLen > 0) { |
| 830 | SmallVector<uint32_t, 4> DeclIDs; |
| 831 | for (; DataLen > 0; DataLen -= 4) |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 832 | DeclIDs.push_back(Reader.getGlobalDeclID( |
| 833 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 834 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
| 835 | } |
| 836 | |
| 837 | return II; |
| 838 | } |
| 839 | |
| 840 | unsigned |
| 841 | ASTDeclContextNameLookupTrait::ComputeHash(const DeclNameKey &Key) const { |
| 842 | llvm::FoldingSetNodeID ID; |
| 843 | ID.AddInteger(Key.Kind); |
| 844 | |
| 845 | switch (Key.Kind) { |
| 846 | case DeclarationName::Identifier: |
| 847 | case DeclarationName::CXXLiteralOperatorName: |
| 848 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 849 | break; |
| 850 | case DeclarationName::ObjCZeroArgSelector: |
| 851 | case DeclarationName::ObjCOneArgSelector: |
| 852 | case DeclarationName::ObjCMultiArgSelector: |
| 853 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 854 | break; |
| 855 | case DeclarationName::CXXOperatorName: |
| 856 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 857 | break; |
| 858 | case DeclarationName::CXXConstructorName: |
| 859 | case DeclarationName::CXXDestructorName: |
| 860 | case DeclarationName::CXXConversionFunctionName: |
| 861 | case DeclarationName::CXXUsingDirective: |
| 862 | break; |
| 863 | } |
| 864 | |
| 865 | return ID.ComputeHash(); |
| 866 | } |
| 867 | |
| 868 | ASTDeclContextNameLookupTrait::internal_key_type |
| 869 | ASTDeclContextNameLookupTrait::GetInternalKey( |
| 870 | const external_key_type& Name) const { |
| 871 | DeclNameKey Key; |
| 872 | Key.Kind = Name.getNameKind(); |
| 873 | switch (Name.getNameKind()) { |
| 874 | case DeclarationName::Identifier: |
| 875 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 876 | break; |
| 877 | case DeclarationName::ObjCZeroArgSelector: |
| 878 | case DeclarationName::ObjCOneArgSelector: |
| 879 | case DeclarationName::ObjCMultiArgSelector: |
| 880 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 881 | break; |
| 882 | case DeclarationName::CXXOperatorName: |
| 883 | Key.Data = Name.getCXXOverloadedOperator(); |
| 884 | break; |
| 885 | case DeclarationName::CXXLiteralOperatorName: |
| 886 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 887 | break; |
| 888 | case DeclarationName::CXXConstructorName: |
| 889 | case DeclarationName::CXXDestructorName: |
| 890 | case DeclarationName::CXXConversionFunctionName: |
| 891 | case DeclarationName::CXXUsingDirective: |
| 892 | Key.Data = 0; |
| 893 | break; |
| 894 | } |
| 895 | |
| 896 | return Key; |
| 897 | } |
| 898 | |
| 899 | std::pair<unsigned, unsigned> |
| 900 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 901 | using namespace llvm::support; |
| 902 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 903 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 904 | return std::make_pair(KeyLen, DataLen); |
| 905 | } |
| 906 | |
| 907 | ASTDeclContextNameLookupTrait::internal_key_type |
| 908 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 909 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 910 | |
| 911 | DeclNameKey Key; |
| 912 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 913 | switch (Key.Kind) { |
| 914 | case DeclarationName::Identifier: |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 915 | Key.Data = (uint64_t)Reader.getLocalIdentifier( |
| 916 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 917 | break; |
| 918 | case DeclarationName::ObjCZeroArgSelector: |
| 919 | case DeclarationName::ObjCOneArgSelector: |
| 920 | case DeclarationName::ObjCMultiArgSelector: |
| 921 | Key.Data = |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 922 | (uint64_t)Reader.getLocalSelector( |
| 923 | F, endian::readNext<uint32_t, little, unaligned>( |
| 924 | d)).getAsOpaquePtr(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 925 | break; |
| 926 | case DeclarationName::CXXOperatorName: |
| 927 | Key.Data = *d++; // OverloadedOperatorKind |
| 928 | break; |
| 929 | case DeclarationName::CXXLiteralOperatorName: |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 930 | Key.Data = (uint64_t)Reader.getLocalIdentifier( |
| 931 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 932 | break; |
| 933 | case DeclarationName::CXXConstructorName: |
| 934 | case DeclarationName::CXXDestructorName: |
| 935 | case DeclarationName::CXXConversionFunctionName: |
| 936 | case DeclarationName::CXXUsingDirective: |
| 937 | Key.Data = 0; |
| 938 | break; |
| 939 | } |
| 940 | |
| 941 | return Key; |
| 942 | } |
| 943 | |
| 944 | ASTDeclContextNameLookupTrait::data_type |
| 945 | ASTDeclContextNameLookupTrait::ReadData(internal_key_type, |
| 946 | const unsigned char* d, |
| 947 | unsigned DataLen) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 948 | using namespace llvm::support; |
| 949 | unsigned NumDecls = endian::readNext<uint16_t, little, unaligned>(d); |
Argyrios Kyrtzidis | c57e503 | 2013-01-11 22:29:49 +0000 | [diff] [blame] | 950 | LE32DeclID *Start = reinterpret_cast<LE32DeclID *>( |
| 951 | const_cast<unsigned char *>(d)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 952 | return std::make_pair(Start, Start + NumDecls); |
| 953 | } |
| 954 | |
| 955 | bool ASTReader::ReadDeclContextStorage(ModuleFile &M, |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 956 | BitstreamCursor &Cursor, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 957 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 958 | DeclContextInfo &Info) { |
| 959 | SavedStreamPosition SavedPosition(Cursor); |
| 960 | // First the lexical decls. |
| 961 | if (Offsets.first != 0) { |
| 962 | Cursor.JumpToBit(Offsets.first); |
| 963 | |
| 964 | RecordData Record; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 965 | StringRef Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 966 | unsigned Code = Cursor.ReadCode(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 967 | unsigned RecCode = Cursor.readRecord(Code, Record, &Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 968 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 969 | Error("Expected lexical block"); |
| 970 | return true; |
| 971 | } |
| 972 | |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 973 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob.data()); |
| 974 | Info.NumLexicalDecls = Blob.size() / sizeof(KindDeclIDPair); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | // Now the lookup table. |
| 978 | if (Offsets.second != 0) { |
| 979 | Cursor.JumpToBit(Offsets.second); |
| 980 | |
| 981 | RecordData Record; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 982 | StringRef Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 983 | unsigned Code = Cursor.ReadCode(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 984 | unsigned RecCode = Cursor.readRecord(Code, Record, &Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 985 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 986 | Error("Expected visible lookup table block"); |
| 987 | return true; |
| 988 | } |
Justin Bogner | da4e650 | 2014-04-14 16:34:29 +0000 | [diff] [blame] | 989 | Info.NameLookupTableData = ASTDeclContextNameLookupTable::Create( |
| 990 | (const unsigned char *)Blob.data() + Record[0], |
| 991 | (const unsigned char *)Blob.data() + sizeof(uint32_t), |
| 992 | (const unsigned char *)Blob.data(), |
| 993 | ASTDeclContextNameLookupTrait(*this, M)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | return false; |
| 997 | } |
| 998 | |
| 999 | void ASTReader::Error(StringRef Msg) { |
| 1000 | Error(diag::err_fe_pch_malformed, Msg); |
Douglas Gregor | 940e805 | 2013-05-10 22:15:13 +0000 | [diff] [blame] | 1001 | if (Context.getLangOpts().Modules && !Diags.isDiagnosticInFlight()) { |
| 1002 | Diag(diag::note_module_cache_path) |
| 1003 | << PP.getHeaderSearchInfo().getModuleCachePath(); |
| 1004 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | void ASTReader::Error(unsigned DiagID, |
| 1008 | StringRef Arg1, StringRef Arg2) { |
| 1009 | if (Diags.isDiagnosticInFlight()) |
| 1010 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 1011 | else |
| 1012 | Diag(DiagID) << Arg1 << Arg2; |
| 1013 | } |
| 1014 | |
| 1015 | //===----------------------------------------------------------------------===// |
| 1016 | // Source Manager Deserialization |
| 1017 | //===----------------------------------------------------------------------===// |
| 1018 | |
| 1019 | /// \brief Read the line table in the source manager block. |
| 1020 | /// \returns true if there was an error. |
| 1021 | bool ASTReader::ParseLineTable(ModuleFile &F, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1022 | const RecordData &Record) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1023 | unsigned Idx = 0; |
| 1024 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1025 | |
| 1026 | // Parse the file names |
| 1027 | std::map<int, int> FileIDs; |
| 1028 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
| 1029 | // Extract the file name |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1030 | auto Filename = ReadPath(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1031 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
| 1032 | } |
| 1033 | |
| 1034 | // Parse the line entries |
| 1035 | std::vector<LineEntry> Entries; |
| 1036 | while (Idx < Record.size()) { |
| 1037 | int FID = Record[Idx++]; |
| 1038 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 1039 | // Remap FileID from 1-based old view. |
| 1040 | FID += F.SLocEntryBaseID - 1; |
| 1041 | |
| 1042 | // Extract the line entries |
| 1043 | unsigned NumEntries = Record[Idx++]; |
| 1044 | assert(NumEntries && "Numentries is 00000"); |
| 1045 | Entries.clear(); |
| 1046 | Entries.reserve(NumEntries); |
| 1047 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1048 | unsigned FileOffset = Record[Idx++]; |
| 1049 | unsigned LineNo = Record[Idx++]; |
| 1050 | int FilenameID = FileIDs[Record[Idx++]]; |
| 1051 | SrcMgr::CharacteristicKind FileKind |
| 1052 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1053 | unsigned IncludeOffset = Record[Idx++]; |
| 1054 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1055 | FileKind, IncludeOffset)); |
| 1056 | } |
| 1057 | LineTable.AddEntry(FileID::get(FID), Entries); |
| 1058 | } |
| 1059 | |
| 1060 | return false; |
| 1061 | } |
| 1062 | |
| 1063 | /// \brief Read a source manager block |
| 1064 | bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) { |
| 1065 | using namespace SrcMgr; |
| 1066 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1067 | BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1068 | |
| 1069 | // Set the source-location entry cursor to the current position in |
| 1070 | // the stream. This cursor will be used to read the contents of the |
| 1071 | // source manager block initially, and then lazily read |
| 1072 | // source-location entries as needed. |
| 1073 | SLocEntryCursor = F.Stream; |
| 1074 | |
| 1075 | // The stream itself is going to skip over the source manager block. |
| 1076 | if (F.Stream.SkipBlock()) { |
| 1077 | Error("malformed block record in AST file"); |
| 1078 | return true; |
| 1079 | } |
| 1080 | |
| 1081 | // Enter the source manager block. |
| 1082 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
| 1083 | Error("malformed source manager block record in AST file"); |
| 1084 | return true; |
| 1085 | } |
| 1086 | |
| 1087 | RecordData Record; |
| 1088 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1089 | llvm::BitstreamEntry E = SLocEntryCursor.advanceSkippingSubblocks(); |
| 1090 | |
| 1091 | switch (E.Kind) { |
| 1092 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1093 | case llvm::BitstreamEntry::Error: |
| 1094 | Error("malformed block record in AST file"); |
| 1095 | return true; |
| 1096 | case llvm::BitstreamEntry::EndBlock: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1097 | return false; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1098 | case llvm::BitstreamEntry::Record: |
| 1099 | // The interesting case. |
| 1100 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1101 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1102 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1103 | // Read a record. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1104 | Record.clear(); |
Chris Lattner | 15c3e7d | 2013-01-21 18:28:26 +0000 | [diff] [blame] | 1105 | StringRef Blob; |
| 1106 | switch (SLocEntryCursor.readRecord(E.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1107 | default: // Default behavior: ignore. |
| 1108 | break; |
| 1109 | |
| 1110 | case SM_SLOC_FILE_ENTRY: |
| 1111 | case SM_SLOC_BUFFER_ENTRY: |
| 1112 | case SM_SLOC_EXPANSION_ENTRY: |
| 1113 | // Once we hit one of the source location entries, we're done. |
| 1114 | return false; |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | /// \brief If a header file is not found at the path that we expect it to be |
| 1120 | /// and the PCH file was moved from its original location, try to resolve the |
| 1121 | /// file by assuming that header+PCH were moved together and the header is in |
| 1122 | /// the same place relative to the PCH. |
| 1123 | static std::string |
| 1124 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1125 | const std::string &OriginalDir, |
| 1126 | const std::string &CurrDir) { |
| 1127 | assert(OriginalDir != CurrDir && |
| 1128 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1129 | using namespace llvm::sys; |
| 1130 | SmallString<128> filePath(Filename); |
| 1131 | fs::make_absolute(filePath); |
| 1132 | assert(path::is_absolute(OriginalDir)); |
| 1133 | SmallString<128> currPCHPath(CurrDir); |
| 1134 | |
| 1135 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1136 | fileDirE = path::end(path::parent_path(filePath)); |
| 1137 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1138 | origDirE = path::end(OriginalDir); |
| 1139 | // Skip the common path components from filePath and OriginalDir. |
| 1140 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1141 | *fileDirI == *origDirI) { |
| 1142 | ++fileDirI; |
| 1143 | ++origDirI; |
| 1144 | } |
| 1145 | for (; origDirI != origDirE; ++origDirI) |
| 1146 | path::append(currPCHPath, ".."); |
| 1147 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1148 | path::append(currPCHPath, path::filename(Filename)); |
| 1149 | return currPCHPath.str(); |
| 1150 | } |
| 1151 | |
| 1152 | bool ASTReader::ReadSLocEntry(int ID) { |
| 1153 | if (ID == 0) |
| 1154 | return false; |
| 1155 | |
| 1156 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1157 | Error("source location entry ID out-of-range for AST file"); |
| 1158 | return true; |
| 1159 | } |
| 1160 | |
| 1161 | ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second; |
| 1162 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1163 | BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1164 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
| 1165 | |
| 1166 | ++NumSLocEntriesRead; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1167 | llvm::BitstreamEntry Entry = SLocEntryCursor.advance(); |
| 1168 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1169 | Error("incorrectly-formatted source location entry in AST file"); |
| 1170 | return true; |
| 1171 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1172 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1173 | RecordData Record; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1174 | StringRef Blob; |
| 1175 | switch (SLocEntryCursor.readRecord(Entry.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1176 | default: |
| 1177 | Error("incorrectly-formatted source location entry in AST file"); |
| 1178 | return true; |
| 1179 | |
| 1180 | case SM_SLOC_FILE_ENTRY: { |
| 1181 | // We will detect whether a file changed and return 'Failure' for it, but |
| 1182 | // we will also try to fail gracefully by setting up the SLocEntry. |
| 1183 | unsigned InputID = Record[4]; |
| 1184 | InputFile IF = getInputFile(*F, InputID); |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1185 | const FileEntry *File = IF.getFile(); |
| 1186 | bool OverriddenBuffer = IF.isOverridden(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1187 | |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1188 | // Note that we only check if a File was returned. If it was out-of-date |
| 1189 | // we have complained but we will continue creating a FileID to recover |
| 1190 | // gracefully. |
| 1191 | if (!File) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1192 | return true; |
| 1193 | |
| 1194 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
| 1195 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
| 1196 | // This is the module's main file. |
| 1197 | IncludeLoc = getImportLocation(F); |
| 1198 | } |
| 1199 | SrcMgr::CharacteristicKind |
| 1200 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1201 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter, |
| 1202 | ID, BaseOffset + Record[0]); |
| 1203 | SrcMgr::FileInfo &FileInfo = |
| 1204 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
| 1205 | FileInfo.NumCreatedFIDs = Record[5]; |
| 1206 | if (Record[3]) |
| 1207 | FileInfo.setHasLineDirectives(); |
| 1208 | |
| 1209 | const DeclID *FirstDecl = F->FileSortedDecls + Record[6]; |
| 1210 | unsigned NumFileDecls = Record[7]; |
| 1211 | if (NumFileDecls) { |
| 1212 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
| 1213 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 1214 | NumFileDecls)); |
| 1215 | } |
| 1216 | |
| 1217 | const SrcMgr::ContentCache *ContentCache |
| 1218 | = SourceMgr.getOrCreateContentCache(File, |
| 1219 | /*isSystemFile=*/FileCharacter != SrcMgr::C_User); |
| 1220 | if (OverriddenBuffer && !ContentCache->BufferOverridden && |
| 1221 | ContentCache->ContentsEntry == ContentCache->OrigEntry) { |
| 1222 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1223 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1224 | unsigned RecCode = SLocEntryCursor.readRecord(Code, Record, &Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1225 | |
| 1226 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
| 1227 | Error("AST record has invalid code"); |
| 1228 | return true; |
| 1229 | } |
| 1230 | |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 1231 | std::unique_ptr<llvm::MemoryBuffer> Buffer |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1232 | = llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), File->getName()); |
David Blaikie | 49cc318 | 2014-08-27 20:54:45 +0000 | [diff] [blame] | 1233 | SourceMgr.overrideFileContents(File, std::move(Buffer)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | break; |
| 1237 | } |
| 1238 | |
| 1239 | case SM_SLOC_BUFFER_ENTRY: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1240 | const char *Name = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1241 | unsigned Offset = Record[0]; |
| 1242 | SrcMgr::CharacteristicKind |
| 1243 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1244 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 1245 | if (IncludeLoc.isInvalid() && |
| 1246 | (F->Kind == MK_ImplicitModule || F->Kind == MK_ExplicitModule)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1247 | IncludeLoc = getImportLocation(F); |
| 1248 | } |
| 1249 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1250 | Record.clear(); |
| 1251 | unsigned RecCode |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1252 | = SLocEntryCursor.readRecord(Code, Record, &Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1253 | |
| 1254 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
| 1255 | Error("AST record has invalid code"); |
| 1256 | return true; |
| 1257 | } |
| 1258 | |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 1259 | std::unique_ptr<llvm::MemoryBuffer> Buffer = |
| 1260 | llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name); |
David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 1261 | SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID, |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 1262 | BaseOffset + Offset, IncludeLoc); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1263 | break; |
| 1264 | } |
| 1265 | |
| 1266 | case SM_SLOC_EXPANSION_ENTRY: { |
| 1267 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
| 1268 | SourceMgr.createExpansionLoc(SpellingLoc, |
| 1269 | ReadSourceLocation(*F, Record[2]), |
| 1270 | ReadSourceLocation(*F, Record[3]), |
| 1271 | Record[4], |
| 1272 | ID, |
| 1273 | BaseOffset + Record[0]); |
| 1274 | break; |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | return false; |
| 1279 | } |
| 1280 | |
| 1281 | std::pair<SourceLocation, StringRef> ASTReader::getModuleImportLoc(int ID) { |
| 1282 | if (ID == 0) |
| 1283 | return std::make_pair(SourceLocation(), ""); |
| 1284 | |
| 1285 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1286 | Error("source location entry ID out-of-range for AST file"); |
| 1287 | return std::make_pair(SourceLocation(), ""); |
| 1288 | } |
| 1289 | |
| 1290 | // Find which module file this entry lands in. |
| 1291 | ModuleFile *M = GlobalSLocEntryMap.find(-ID)->second; |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 1292 | if (M->Kind != MK_ImplicitModule && M->Kind != MK_ExplicitModule) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1293 | return std::make_pair(SourceLocation(), ""); |
| 1294 | |
| 1295 | // FIXME: Can we map this down to a particular submodule? That would be |
| 1296 | // ideal. |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1297 | return std::make_pair(M->ImportLoc, StringRef(M->ModuleName)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | /// \brief Find the location where the module F is imported. |
| 1301 | SourceLocation ASTReader::getImportLocation(ModuleFile *F) { |
| 1302 | if (F->ImportLoc.isValid()) |
| 1303 | return F->ImportLoc; |
| 1304 | |
| 1305 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1306 | // location of its includer. |
| 1307 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1308 | // Main file is the importer. |
| 1309 | assert(!SourceMgr.getMainFileID().isInvalid() && "missing main file"); |
| 1310 | return SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1311 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1312 | return F->ImportedBy[0]->FirstLoc; |
| 1313 | } |
| 1314 | |
| 1315 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1316 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1317 | /// and then leave the cursor pointing into the block. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1318 | bool ASTReader::ReadBlockAbbrevs(BitstreamCursor &Cursor, unsigned BlockID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1319 | if (Cursor.EnterSubBlock(BlockID)) { |
| 1320 | Error("malformed block record in AST file"); |
| 1321 | return Failure; |
| 1322 | } |
| 1323 | |
| 1324 | while (true) { |
| 1325 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
| 1326 | unsigned Code = Cursor.ReadCode(); |
| 1327 | |
| 1328 | // We expect all abbrevs to be at the start of the block. |
| 1329 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1330 | Cursor.JumpToBit(Offset); |
| 1331 | return false; |
| 1332 | } |
| 1333 | Cursor.ReadAbbrevRecord(); |
| 1334 | } |
| 1335 | } |
| 1336 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 1337 | Token ASTReader::ReadToken(ModuleFile &F, const RecordDataImpl &Record, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1338 | unsigned &Idx) { |
| 1339 | Token Tok; |
| 1340 | Tok.startToken(); |
| 1341 | Tok.setLocation(ReadSourceLocation(F, Record, Idx)); |
| 1342 | Tok.setLength(Record[Idx++]); |
| 1343 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[Idx++])) |
| 1344 | Tok.setIdentifierInfo(II); |
| 1345 | Tok.setKind((tok::TokenKind)Record[Idx++]); |
| 1346 | Tok.setFlag((Token::TokenFlags)Record[Idx++]); |
| 1347 | return Tok; |
| 1348 | } |
| 1349 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1350 | MacroInfo *ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1351 | BitstreamCursor &Stream = F.MacroCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1352 | |
| 1353 | // Keep track of where we are in the stream, then jump back there |
| 1354 | // after reading this macro. |
| 1355 | SavedStreamPosition SavedPosition(Stream); |
| 1356 | |
| 1357 | Stream.JumpToBit(Offset); |
| 1358 | RecordData Record; |
| 1359 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1360 | MacroInfo *Macro = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1361 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1362 | while (true) { |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1363 | // Advance to the next record, but if we get to the end of the block, don't |
| 1364 | // pop it (removing all the abbreviations from the cursor) since we want to |
| 1365 | // be able to reseek within the block and read entries. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1366 | unsigned Flags = BitstreamCursor::AF_DontPopBlockAtEnd; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1367 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(Flags); |
| 1368 | |
| 1369 | switch (Entry.Kind) { |
| 1370 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1371 | case llvm::BitstreamEntry::Error: |
| 1372 | Error("malformed block record in AST file"); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1373 | return Macro; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1374 | case llvm::BitstreamEntry::EndBlock: |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1375 | return Macro; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1376 | case llvm::BitstreamEntry::Record: |
| 1377 | // The interesting case. |
| 1378 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | // Read a record. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1382 | Record.clear(); |
| 1383 | PreprocessorRecordTypes RecType = |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1384 | (PreprocessorRecordTypes)Stream.readRecord(Entry.ID, Record); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1385 | switch (RecType) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1386 | case PP_MODULE_MACRO: |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1387 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 1388 | return Macro; |
| 1389 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1390 | case PP_MACRO_OBJECT_LIKE: |
| 1391 | case PP_MACRO_FUNCTION_LIKE: { |
| 1392 | // If we already have a macro, that means that we've hit the end |
| 1393 | // of the definition of the macro we were looking for. We're |
| 1394 | // done. |
| 1395 | if (Macro) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1396 | return Macro; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1397 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1398 | unsigned NextIndex = 1; // Skip identifier ID. |
| 1399 | SubmoduleID SubModID = getGlobalSubmoduleID(F, Record[NextIndex++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1400 | SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1401 | MacroInfo *MI = PP.AllocateDeserializedMacroInfo(Loc, SubModID); |
Argyrios Kyrtzidis | 7572be2 | 2013-01-07 19:16:23 +0000 | [diff] [blame] | 1402 | MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1403 | MI->setIsUsed(Record[NextIndex++]); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 1404 | MI->setUsedForHeaderGuard(Record[NextIndex++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1405 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1406 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
| 1407 | // Decode function-like macro info. |
| 1408 | bool isC99VarArgs = Record[NextIndex++]; |
| 1409 | bool isGNUVarArgs = Record[NextIndex++]; |
| 1410 | bool hasCommaPasting = Record[NextIndex++]; |
| 1411 | MacroArgs.clear(); |
| 1412 | unsigned NumArgs = Record[NextIndex++]; |
| 1413 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1414 | MacroArgs.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
| 1415 | |
| 1416 | // Install function-like macro info. |
| 1417 | MI->setIsFunctionLike(); |
| 1418 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1419 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
| 1420 | if (hasCommaPasting) MI->setHasCommaPasting(); |
| 1421 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
| 1422 | PP.getPreprocessorAllocator()); |
| 1423 | } |
| 1424 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1425 | // Remember that we saw this macro last so that we add the tokens that |
| 1426 | // form its body to it. |
| 1427 | Macro = MI; |
| 1428 | |
| 1429 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1430 | Record[NextIndex]) { |
| 1431 | // We have a macro definition. Register the association |
| 1432 | PreprocessedEntityID |
| 1433 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1434 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
Argyrios Kyrtzidis | 832de9f | 2013-02-22 18:35:59 +0000 | [diff] [blame] | 1435 | PreprocessingRecord::PPEntityID |
| 1436 | PPID = PPRec.getPPEntityID(GlobalID-1, /*isLoaded=*/true); |
| 1437 | MacroDefinition *PPDef = |
| 1438 | cast_or_null<MacroDefinition>(PPRec.getPreprocessedEntity(PPID)); |
| 1439 | if (PPDef) |
| 1440 | PPRec.RegisterMacroDefinition(Macro, PPDef); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | ++NumMacrosRead; |
| 1444 | break; |
| 1445 | } |
| 1446 | |
| 1447 | case PP_TOKEN: { |
| 1448 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1449 | // erroneous, just pretend we didn't see this. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1450 | if (!Macro) break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1451 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1452 | unsigned Idx = 0; |
| 1453 | Token Tok = ReadToken(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1454 | Macro->AddTokenToBody(Tok); |
| 1455 | break; |
| 1456 | } |
| 1457 | } |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | PreprocessedEntityID |
| 1462 | ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const { |
| 1463 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
| 1464 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1465 | assert(I != M.PreprocessedEntityRemap.end() |
| 1466 | && "Invalid index into preprocessed entity index remap"); |
| 1467 | |
| 1468 | return LocalID + I->second; |
| 1469 | } |
| 1470 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1471 | unsigned HeaderFileInfoTrait::ComputeHash(internal_key_ref ikey) { |
| 1472 | return llvm::hash_combine(ikey.Size, ikey.ModTime); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1473 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1474 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1475 | HeaderFileInfoTrait::internal_key_type |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1476 | HeaderFileInfoTrait::GetInternalKey(const FileEntry *FE) { |
| 1477 | internal_key_type ikey = { FE->getSize(), FE->getModificationTime(), |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1478 | FE->getName(), /*Imported*/false }; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1479 | return ikey; |
| 1480 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1481 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1482 | bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) { |
| 1483 | if (a.Size != b.Size || a.ModTime != b.ModTime) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1484 | return false; |
| 1485 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1486 | if (llvm::sys::path::is_absolute(a.Filename) && |
| 1487 | strcmp(a.Filename, b.Filename) == 0) |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1488 | return true; |
| 1489 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1490 | // Determine whether the actual files are equivalent. |
Argyrios Kyrtzidis | 2a513e8 | 2013-03-04 20:33:40 +0000 | [diff] [blame] | 1491 | FileManager &FileMgr = Reader.getFileManager(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1492 | auto GetFile = [&](const internal_key_type &Key) -> const FileEntry* { |
| 1493 | if (!Key.Imported) |
| 1494 | return FileMgr.getFile(Key.Filename); |
| 1495 | |
| 1496 | std::string Resolved = Key.Filename; |
| 1497 | Reader.ResolveImportedPath(M, Resolved); |
| 1498 | return FileMgr.getFile(Resolved); |
| 1499 | }; |
| 1500 | |
| 1501 | const FileEntry *FEA = GetFile(a); |
| 1502 | const FileEntry *FEB = GetFile(b); |
| 1503 | return FEA && FEA == FEB; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | std::pair<unsigned, unsigned> |
| 1507 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1508 | using namespace llvm::support; |
| 1509 | unsigned KeyLen = (unsigned) endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1510 | unsigned DataLen = (unsigned) *d++; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1511 | return std::make_pair(KeyLen, DataLen); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1512 | } |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1513 | |
| 1514 | HeaderFileInfoTrait::internal_key_type |
| 1515 | HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1516 | using namespace llvm::support; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1517 | internal_key_type ikey; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1518 | ikey.Size = off_t(endian::readNext<uint64_t, little, unaligned>(d)); |
| 1519 | ikey.ModTime = time_t(endian::readNext<uint64_t, little, unaligned>(d)); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1520 | ikey.Filename = (const char *)d; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1521 | ikey.Imported = true; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1522 | return ikey; |
| 1523 | } |
| 1524 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1525 | HeaderFileInfoTrait::data_type |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1526 | HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1527 | unsigned DataLen) { |
| 1528 | const unsigned char *End = d + DataLen; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1529 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1530 | HeaderFileInfo HFI; |
| 1531 | unsigned Flags = *d++; |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 1532 | HFI.HeaderRole = static_cast<ModuleMap::ModuleHeaderRole> |
| 1533 | ((Flags >> 6) & 0x03); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1534 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1535 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1536 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1537 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1538 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1539 | HFI.NumIncludes = endian::readNext<uint16_t, little, unaligned>(d); |
| 1540 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID( |
| 1541 | M, endian::readNext<uint32_t, little, unaligned>(d)); |
| 1542 | if (unsigned FrameworkOffset = |
| 1543 | endian::readNext<uint32_t, little, unaligned>(d)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1544 | // The framework offset is 1 greater than the actual offset, |
| 1545 | // since 0 is used as an indicator for "no framework name". |
| 1546 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1547 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1548 | } |
| 1549 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1550 | if (d != End) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1551 | uint32_t LocalSMID = endian::readNext<uint32_t, little, unaligned>(d); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1552 | if (LocalSMID) { |
| 1553 | // This header is part of a module. Associate it with the module to enable |
| 1554 | // implicit module import. |
| 1555 | SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID); |
| 1556 | Module *Mod = Reader.getSubmodule(GlobalSMID); |
| 1557 | HFI.isModuleHeader = true; |
| 1558 | FileManager &FileMgr = Reader.getFileManager(); |
| 1559 | ModuleMap &ModMap = |
| 1560 | Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1561 | // FIXME: This information should be propagated through the |
| 1562 | // SUBMODULE_HEADER etc records rather than from here. |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 1563 | // FIXME: We don't ever mark excluded headers. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1564 | std::string Filename = key.Filename; |
| 1565 | if (key.Imported) |
| 1566 | Reader.ResolveImportedPath(M, Filename); |
| 1567 | Module::Header H = { key.Filename, FileMgr.getFile(Filename) }; |
Hans Wennborg | 0101b54 | 2014-12-02 02:13:09 +0000 | [diff] [blame] | 1568 | ModMap.addHeader(Mod, H, HFI.getHeaderRole()); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1569 | } |
| 1570 | } |
| 1571 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1572 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1573 | (void)End; |
| 1574 | |
| 1575 | // This HeaderFileInfo was externally loaded. |
| 1576 | HFI.External = true; |
| 1577 | return HFI; |
| 1578 | } |
| 1579 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1580 | void ASTReader::addPendingMacro(IdentifierInfo *II, |
| 1581 | ModuleFile *M, |
| 1582 | uint64_t MacroDirectivesOffset) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1583 | assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard"); |
| 1584 | PendingMacroIDs[II].push_back(PendingMacroInfo(M, MacroDirectivesOffset)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | void ASTReader::ReadDefinedMacros() { |
| 1588 | // Note that we are loading defined macros. |
| 1589 | Deserializing Macros(this); |
| 1590 | |
| 1591 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1592 | E = ModuleMgr.rend(); I != E; ++I) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1593 | BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1594 | |
| 1595 | // If there was no preprocessor block, skip this file. |
| 1596 | if (!MacroCursor.getBitStreamReader()) |
| 1597 | continue; |
| 1598 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1599 | BitstreamCursor Cursor = MacroCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1600 | Cursor.JumpToBit((*I)->MacroStartOffset); |
| 1601 | |
| 1602 | RecordData Record; |
| 1603 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1604 | llvm::BitstreamEntry E = Cursor.advanceSkippingSubblocks(); |
| 1605 | |
| 1606 | switch (E.Kind) { |
| 1607 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1608 | case llvm::BitstreamEntry::Error: |
| 1609 | Error("malformed block record in AST file"); |
| 1610 | return; |
| 1611 | case llvm::BitstreamEntry::EndBlock: |
| 1612 | goto NextCursor; |
| 1613 | |
| 1614 | case llvm::BitstreamEntry::Record: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1615 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1616 | switch (Cursor.readRecord(E.ID, Record)) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1617 | default: // Default behavior: ignore. |
| 1618 | break; |
| 1619 | |
| 1620 | case PP_MACRO_OBJECT_LIKE: |
| 1621 | case PP_MACRO_FUNCTION_LIKE: |
| 1622 | getLocalIdentifier(**I, Record[0]); |
| 1623 | break; |
| 1624 | |
| 1625 | case PP_TOKEN: |
| 1626 | // Ignore tokens. |
| 1627 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1628 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1629 | break; |
| 1630 | } |
| 1631 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1632 | NextCursor: ; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | namespace { |
| 1637 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 1638 | class IdentifierLookupVisitor { |
| 1639 | StringRef Name; |
| 1640 | unsigned PriorGeneration; |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1641 | unsigned &NumIdentifierLookups; |
| 1642 | unsigned &NumIdentifierLookupHits; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1643 | IdentifierInfo *Found; |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1644 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1645 | public: |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1646 | IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration, |
| 1647 | unsigned &NumIdentifierLookups, |
| 1648 | unsigned &NumIdentifierLookupHits) |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1649 | : Name(Name), PriorGeneration(PriorGeneration), |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1650 | NumIdentifierLookups(NumIdentifierLookups), |
| 1651 | NumIdentifierLookupHits(NumIdentifierLookupHits), |
| 1652 | Found() |
| 1653 | { |
| 1654 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1655 | |
| 1656 | static bool visit(ModuleFile &M, void *UserData) { |
| 1657 | IdentifierLookupVisitor *This |
| 1658 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 1659 | |
| 1660 | // If we've already searched this module file, skip it now. |
| 1661 | if (M.Generation <= This->PriorGeneration) |
| 1662 | return true; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1663 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1664 | ASTIdentifierLookupTable *IdTable |
| 1665 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 1666 | if (!IdTable) |
| 1667 | return false; |
| 1668 | |
| 1669 | ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), |
| 1670 | M, This->Found); |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1671 | ++This->NumIdentifierLookups; |
| 1672 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(This->Name,&Trait); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1673 | if (Pos == IdTable->end()) |
| 1674 | return false; |
| 1675 | |
| 1676 | // Dereferencing the iterator has the effect of building the |
| 1677 | // IdentifierInfo node and populating it with the various |
| 1678 | // declarations it needs. |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1679 | ++This->NumIdentifierLookupHits; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1680 | This->Found = *Pos; |
| 1681 | return true; |
| 1682 | } |
| 1683 | |
| 1684 | // \brief Retrieve the identifier info found within the module |
| 1685 | // files. |
| 1686 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 1687 | }; |
| 1688 | } |
| 1689 | |
| 1690 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
| 1691 | // Note that we are loading an identifier. |
| 1692 | Deserializing AnIdentifier(this); |
| 1693 | |
| 1694 | unsigned PriorGeneration = 0; |
| 1695 | if (getContext().getLangOpts().Modules) |
| 1696 | PriorGeneration = IdentifierGeneration[&II]; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1697 | |
| 1698 | // If there is a global index, look there first to determine which modules |
| 1699 | // provably do not have any results for this identifier. |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1700 | GlobalModuleIndex::HitSet Hits; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1701 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1702 | if (!loadGlobalIndex()) { |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1703 | if (GlobalIndex->lookupIdentifier(II.getName(), Hits)) { |
| 1704 | HitsPtr = &Hits; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1705 | } |
| 1706 | } |
| 1707 | |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1708 | IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration, |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1709 | NumIdentifierLookups, |
| 1710 | NumIdentifierLookupHits); |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1711 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor, HitsPtr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1712 | markIdentifierUpToDate(&II); |
| 1713 | } |
| 1714 | |
| 1715 | void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { |
| 1716 | if (!II) |
| 1717 | return; |
| 1718 | |
| 1719 | II->setOutOfDate(false); |
| 1720 | |
| 1721 | // Update the generation for this identifier. |
| 1722 | if (getContext().getLangOpts().Modules) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1723 | IdentifierGeneration[II] = getGeneration(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1726 | void ASTReader::resolvePendingMacro(IdentifierInfo *II, |
| 1727 | const PendingMacroInfo &PMInfo) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1728 | ModuleFile &M = *PMInfo.M; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1729 | |
| 1730 | BitstreamCursor &Cursor = M.MacroCursor; |
| 1731 | SavedStreamPosition SavedPosition(Cursor); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1732 | Cursor.JumpToBit(PMInfo.MacroDirectivesOffset); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1733 | |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1734 | struct ModuleMacroRecord { |
| 1735 | SubmoduleID SubModID; |
| 1736 | MacroInfo *MI; |
| 1737 | SmallVector<SubmoduleID, 8> Overrides; |
| 1738 | }; |
| 1739 | llvm::SmallVector<ModuleMacroRecord, 8> ModuleMacros; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1740 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1741 | // We expect to see a sequence of PP_MODULE_MACRO records listing exported |
| 1742 | // macros, followed by a PP_MACRO_DIRECTIVE_HISTORY record with the complete |
| 1743 | // macro histroy. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1744 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1745 | while (true) { |
| 1746 | llvm::BitstreamEntry Entry = |
| 1747 | Cursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 1748 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 1749 | Error("malformed block record in AST file"); |
| 1750 | return; |
| 1751 | } |
| 1752 | |
| 1753 | Record.clear(); |
Aaron Ballman | c75a192 | 2015-04-22 15:25:05 +0000 | [diff] [blame] | 1754 | switch ((PreprocessorRecordTypes)Cursor.readRecord(Entry.ID, Record)) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1755 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 1756 | break; |
| 1757 | |
| 1758 | case PP_MODULE_MACRO: { |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1759 | ModuleMacros.push_back(ModuleMacroRecord()); |
| 1760 | auto &Info = ModuleMacros.back(); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1761 | Info.SubModID = getGlobalSubmoduleID(M, Record[0]); |
| 1762 | Info.MI = getMacro(getGlobalMacroID(M, Record[1])); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1763 | for (int I = 2, N = Record.size(); I != N; ++I) |
| 1764 | Info.Overrides.push_back(getGlobalSubmoduleID(M, Record[I])); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1765 | continue; |
| 1766 | } |
| 1767 | |
| 1768 | default: |
| 1769 | Error("malformed block record in AST file"); |
| 1770 | return; |
| 1771 | } |
| 1772 | |
| 1773 | // We found the macro directive history; that's the last record |
| 1774 | // for this macro. |
| 1775 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1778 | // Module macros are listed in reverse dependency order. |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1779 | { |
| 1780 | std::reverse(ModuleMacros.begin(), ModuleMacros.end()); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1781 | llvm::SmallVector<ModuleMacro*, 8> Overrides; |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1782 | for (auto &MMR : ModuleMacros) { |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1783 | Overrides.clear(); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1784 | for (unsigned ModID : MMR.Overrides) { |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 1785 | Module *Mod = getSubmodule(ModID); |
| 1786 | auto *Macro = PP.getModuleMacro(Mod, II); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1787 | assert(Macro && "missing definition for overridden macro"); |
Richard Smith | 5dbef92 | 2015-04-22 02:09:43 +0000 | [diff] [blame] | 1788 | Overrides.push_back(Macro); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | bool Inserted = false; |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1792 | Module *Owner = getSubmodule(MMR.SubModID); |
Richard Smith | 20e883e | 2015-04-29 23:20:19 +0000 | [diff] [blame] | 1793 | PP.addModuleMacro(Owner, II, MMR.MI, Overrides, Inserted); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1794 | } |
| 1795 | } |
| 1796 | |
| 1797 | // Don't read the directive history for a module; we don't have anywhere |
| 1798 | // to put it. |
| 1799 | if (M.Kind == MK_ImplicitModule || M.Kind == MK_ExplicitModule) |
| 1800 | return; |
| 1801 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1802 | // Deserialize the macro directives history in reverse source-order. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1803 | MacroDirective *Latest = nullptr, *Earliest = nullptr; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1804 | unsigned Idx = 0, N = Record.size(); |
| 1805 | while (Idx < N) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1806 | MacroDirective *MD = nullptr; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1807 | SourceLocation Loc = ReadSourceLocation(M, Record, Idx); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1808 | MacroDirective::Kind K = (MacroDirective::Kind)Record[Idx++]; |
| 1809 | switch (K) { |
| 1810 | case MacroDirective::MD_Define: { |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1811 | MacroInfo *MI = getMacro(getGlobalMacroID(M, Record[Idx++])); |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 1812 | MD = PP.AllocateDefMacroDirective(MI, Loc); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1813 | break; |
| 1814 | } |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 1815 | case MacroDirective::MD_Undefine: { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 1816 | MD = PP.AllocateUndefMacroDirective(Loc); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1817 | break; |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 1818 | } |
| 1819 | case MacroDirective::MD_Visibility: |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1820 | bool isPublic = Record[Idx++]; |
| 1821 | MD = PP.AllocateVisibilityMacroDirective(Loc, isPublic); |
| 1822 | break; |
| 1823 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1824 | |
| 1825 | if (!Latest) |
| 1826 | Latest = MD; |
| 1827 | if (Earliest) |
| 1828 | Earliest->setPrevious(MD); |
| 1829 | Earliest = MD; |
| 1830 | } |
| 1831 | |
| 1832 | PP.setLoadedMacroDirective(II, Latest); |
| 1833 | } |
| 1834 | |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 1835 | ASTReader::InputFileInfo |
| 1836 | ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1837 | // Go find this input file. |
| 1838 | BitstreamCursor &Cursor = F.InputFilesCursor; |
| 1839 | SavedStreamPosition SavedPosition(Cursor); |
| 1840 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
| 1841 | |
| 1842 | unsigned Code = Cursor.ReadCode(); |
| 1843 | RecordData Record; |
| 1844 | StringRef Blob; |
| 1845 | |
| 1846 | unsigned Result = Cursor.readRecord(Code, Record, &Blob); |
| 1847 | assert(static_cast<InputFileRecordTypes>(Result) == INPUT_FILE && |
| 1848 | "invalid record type for input file"); |
| 1849 | (void)Result; |
| 1850 | |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 1851 | std::string Filename; |
| 1852 | off_t StoredSize; |
| 1853 | time_t StoredTime; |
| 1854 | bool Overridden; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1855 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1856 | assert(Record[0] == ID && "Bogus stored ID or offset"); |
| 1857 | StoredSize = static_cast<off_t>(Record[1]); |
| 1858 | StoredTime = static_cast<time_t>(Record[2]); |
| 1859 | Overridden = static_cast<bool>(Record[3]); |
| 1860 | Filename = Blob; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1861 | ResolveImportedPath(F, Filename); |
| 1862 | |
Hans Wennborg | 7394514 | 2014-03-14 17:45:06 +0000 | [diff] [blame] | 1863 | InputFileInfo R = { std::move(Filename), StoredSize, StoredTime, Overridden }; |
| 1864 | return R; |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | std::string ASTReader::getInputFileName(ModuleFile &F, unsigned int ID) { |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 1868 | return readInputFileInfo(F, ID).Filename; |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1869 | } |
| 1870 | |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1871 | InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1872 | // If this ID is bogus, just return an empty input file. |
| 1873 | if (ID == 0 || ID > F.InputFilesLoaded.size()) |
| 1874 | return InputFile(); |
| 1875 | |
| 1876 | // If we've already loaded this input file, return it. |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1877 | if (F.InputFilesLoaded[ID-1].getFile()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1878 | return F.InputFilesLoaded[ID-1]; |
| 1879 | |
Argyrios Kyrtzidis | 9308f0a | 2014-01-08 19:13:34 +0000 | [diff] [blame] | 1880 | if (F.InputFilesLoaded[ID-1].isNotFound()) |
| 1881 | return InputFile(); |
| 1882 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1883 | // Go find this input file. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1884 | BitstreamCursor &Cursor = F.InputFilesCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1885 | SavedStreamPosition SavedPosition(Cursor); |
| 1886 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
| 1887 | |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 1888 | InputFileInfo FI = readInputFileInfo(F, ID); |
| 1889 | off_t StoredSize = FI.StoredSize; |
| 1890 | time_t StoredTime = FI.StoredTime; |
| 1891 | bool Overridden = FI.Overridden; |
| 1892 | StringRef Filename = FI.Filename; |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1893 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1894 | const FileEntry *File |
| 1895 | = Overridden? FileMgr.getVirtualFile(Filename, StoredSize, StoredTime) |
| 1896 | : FileMgr.getFile(Filename, /*OpenFile=*/false); |
| 1897 | |
| 1898 | // If we didn't find the file, resolve it relative to the |
| 1899 | // original directory from which this AST file was created. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1900 | if (File == nullptr && !F.OriginalDir.empty() && !CurrentDir.empty() && |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1901 | F.OriginalDir != CurrentDir) { |
| 1902 | std::string Resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1903 | F.OriginalDir, |
| 1904 | CurrentDir); |
| 1905 | if (!Resolved.empty()) |
| 1906 | File = FileMgr.getFile(Resolved); |
| 1907 | } |
| 1908 | |
| 1909 | // For an overridden file, create a virtual file with the stored |
| 1910 | // size/timestamp. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1911 | if (Overridden && File == nullptr) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1912 | File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime); |
| 1913 | } |
| 1914 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1915 | if (File == nullptr) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1916 | if (Complain) { |
| 1917 | std::string ErrorStr = "could not find file '"; |
| 1918 | ErrorStr += Filename; |
| 1919 | ErrorStr += "' referenced by AST file"; |
| 1920 | Error(ErrorStr.c_str()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1921 | } |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1922 | // Record that we didn't find the file. |
| 1923 | F.InputFilesLoaded[ID-1] = InputFile::getNotFound(); |
| 1924 | return InputFile(); |
| 1925 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1926 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1927 | // Check if there was a request to override the contents of the file |
| 1928 | // that was part of the precompiled header. Overridding such a file |
| 1929 | // can lead to problems when lexing using the source locations from the |
| 1930 | // PCH. |
| 1931 | SourceManager &SM = getSourceManager(); |
| 1932 | if (!Overridden && SM.isFileOverridden(File)) { |
| 1933 | if (Complain) |
| 1934 | Error(diag::err_fe_pch_file_overridden, Filename); |
| 1935 | // After emitting the diagnostic, recover by disabling the override so |
| 1936 | // that the original file will be used. |
| 1937 | SM.disableFileContentsOverride(File); |
| 1938 | // The FileEntry is a virtual file entry with the size of the contents |
| 1939 | // that would override the original contents. Set it to the original's |
| 1940 | // size/time. |
| 1941 | FileMgr.modifyFileEntry(const_cast<FileEntry*>(File), |
| 1942 | StoredSize, StoredTime); |
| 1943 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1944 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1945 | bool IsOutOfDate = false; |
| 1946 | |
| 1947 | // For an overridden file, there is nothing to validate. |
Richard Smith | 96fdab6 | 2014-10-28 16:24:08 +0000 | [diff] [blame] | 1948 | if (!Overridden && // |
| 1949 | (StoredSize != File->getSize() || |
| 1950 | #if defined(LLVM_ON_WIN32) |
| 1951 | false |
| 1952 | #else |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1953 | // In our regression testing, the Windows file system seems to |
| 1954 | // have inconsistent modification times that sometimes |
| 1955 | // erroneously trigger this error-handling path. |
Richard Smith | 96fdab6 | 2014-10-28 16:24:08 +0000 | [diff] [blame] | 1956 | // |
| 1957 | // This also happens in networked file systems, so disable this |
| 1958 | // check if validation is disabled or if we have an explicitly |
| 1959 | // built PCM file. |
| 1960 | // |
| 1961 | // FIXME: Should we also do this for PCH files? They could also |
| 1962 | // reasonably get shared across a network during a distributed build. |
| 1963 | (StoredTime != File->getModificationTime() && !DisableValidation && |
| 1964 | F.Kind != MK_ExplicitModule) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1965 | #endif |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1966 | )) { |
| 1967 | if (Complain) { |
| 1968 | // Build a list of the PCH imports that got us here (in reverse). |
| 1969 | SmallVector<ModuleFile *, 4> ImportStack(1, &F); |
| 1970 | while (ImportStack.back()->ImportedBy.size() > 0) |
| 1971 | ImportStack.push_back(ImportStack.back()->ImportedBy[0]); |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 1972 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1973 | // The top-level PCH is stale. |
| 1974 | StringRef TopLevelPCHName(ImportStack.back()->FileName); |
| 1975 | Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName); |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 1976 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1977 | // Print the import stack. |
| 1978 | if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) { |
| 1979 | Diag(diag::note_pch_required_by) |
| 1980 | << Filename << ImportStack[0]->FileName; |
| 1981 | for (unsigned I = 1; I < ImportStack.size(); ++I) |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 1982 | Diag(diag::note_pch_required_by) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1983 | << ImportStack[I-1]->FileName << ImportStack[I]->FileName; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 1984 | } |
| 1985 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1986 | if (!Diags.isDiagnosticInFlight()) |
| 1987 | Diag(diag::note_pch_rebuild_required) << TopLevelPCHName; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1988 | } |
| 1989 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1990 | IsOutOfDate = true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1991 | } |
| 1992 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1993 | InputFile IF = InputFile(File, Overridden, IsOutOfDate); |
| 1994 | |
| 1995 | // Note that we've loaded this input file. |
| 1996 | F.InputFilesLoaded[ID-1] = IF; |
| 1997 | return IF; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2000 | /// \brief If we are loading a relocatable PCH or module file, and the filename |
| 2001 | /// is not an absolute path, add the system or module root to the beginning of |
| 2002 | /// the file name. |
| 2003 | void ASTReader::ResolveImportedPath(ModuleFile &M, std::string &Filename) { |
| 2004 | // Resolve relative to the base directory, if we have one. |
| 2005 | if (!M.BaseDirectory.empty()) |
| 2006 | return ResolveImportedPath(Filename, M.BaseDirectory); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2007 | } |
| 2008 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2009 | void ASTReader::ResolveImportedPath(std::string &Filename, StringRef Prefix) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2010 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
| 2011 | return; |
| 2012 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2013 | SmallString<128> Buffer; |
| 2014 | llvm::sys::path::append(Buffer, Prefix, Filename); |
| 2015 | Filename.assign(Buffer.begin(), Buffer.end()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | ASTReader::ASTReadResult |
| 2019 | ASTReader::ReadControlBlock(ModuleFile &F, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2020 | SmallVectorImpl<ImportedModule> &Loaded, |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2021 | const ModuleFile *ImportedBy, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2022 | unsigned ClientLoadCapabilities) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2023 | BitstreamCursor &Stream = F.Stream; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2024 | |
| 2025 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
| 2026 | Error("malformed block record in AST file"); |
| 2027 | return Failure; |
| 2028 | } |
| 2029 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 2030 | // Should we allow the configuration of the module file to differ from the |
| 2031 | // configuration of the current translation unit in a compatible way? |
| 2032 | // |
| 2033 | // FIXME: Allow this for files explicitly specified with -include-pch too. |
| 2034 | bool AllowCompatibleConfigurationMismatch = F.Kind == MK_ExplicitModule; |
| 2035 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2036 | // Read all of the records and blocks in the control block. |
| 2037 | RecordData Record; |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2038 | unsigned NumInputs = 0; |
| 2039 | unsigned NumUserInputs = 0; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2040 | while (1) { |
| 2041 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 2042 | |
| 2043 | switch (Entry.Kind) { |
| 2044 | case llvm::BitstreamEntry::Error: |
| 2045 | Error("malformed block record in AST file"); |
| 2046 | return Failure; |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2047 | case llvm::BitstreamEntry::EndBlock: { |
| 2048 | // Validate input files. |
| 2049 | const HeaderSearchOptions &HSOpts = |
| 2050 | PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2051 | |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2052 | // All user input files reside at the index range [0, NumUserInputs), and |
| 2053 | // system input files reside at [NumUserInputs, NumInputs). |
Ben Langmuir | acb803e | 2014-11-10 22:13:10 +0000 | [diff] [blame] | 2054 | if (!DisableValidation) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2055 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2056 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2057 | // If we are reading a module, we will create a verification timestamp, |
| 2058 | // so we verify all input files. Otherwise, verify only user input |
| 2059 | // files. |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2060 | |
| 2061 | unsigned N = NumUserInputs; |
| 2062 | if (ValidateSystemInputs || |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 2063 | (HSOpts.ModulesValidateOncePerBuildSession && |
Ben Langmuir | acb803e | 2014-11-10 22:13:10 +0000 | [diff] [blame] | 2064 | F.InputFilesValidationTimestamp <= HSOpts.BuildSessionTimestamp && |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 2065 | F.Kind == MK_ImplicitModule)) |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2066 | N = NumInputs; |
| 2067 | |
Ben Langmuir | 3d4417c | 2014-02-07 17:31:11 +0000 | [diff] [blame] | 2068 | for (unsigned I = 0; I < N; ++I) { |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2069 | InputFile IF = getInputFile(F, I+1, Complain); |
| 2070 | if (!IF.getFile() || IF.isOutOfDate()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2071 | return OutOfDate; |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2072 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2073 | } |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2074 | |
Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 2075 | if (Listener) |
| 2076 | Listener->visitModuleFile(F.FileName); |
| 2077 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2078 | if (Listener && Listener->needsInputFileVisitation()) { |
| 2079 | unsigned N = Listener->needsSystemInputFileVisitation() ? NumInputs |
| 2080 | : NumUserInputs; |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 2081 | for (unsigned I = 0; I < N; ++I) { |
| 2082 | bool IsSystem = I >= NumUserInputs; |
| 2083 | InputFileInfo FI = readInputFileInfo(F, I+1); |
| 2084 | Listener->visitInputFile(FI.Filename, IsSystem, FI.Overridden); |
| 2085 | } |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2088 | return Success; |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2089 | } |
| 2090 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2091 | case llvm::BitstreamEntry::SubBlock: |
| 2092 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2093 | case INPUT_FILES_BLOCK_ID: |
| 2094 | F.InputFilesCursor = Stream; |
| 2095 | if (Stream.SkipBlock() || // Skip with the main cursor |
| 2096 | // Read the abbreviations |
| 2097 | ReadBlockAbbrevs(F.InputFilesCursor, INPUT_FILES_BLOCK_ID)) { |
| 2098 | Error("malformed block record in AST file"); |
| 2099 | return Failure; |
| 2100 | } |
| 2101 | continue; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2102 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2103 | default: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2104 | if (Stream.SkipBlock()) { |
| 2105 | Error("malformed block record in AST file"); |
| 2106 | return Failure; |
| 2107 | } |
| 2108 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2109 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2110 | |
| 2111 | case llvm::BitstreamEntry::Record: |
| 2112 | // The interesting case. |
| 2113 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | // Read and process a record. |
| 2117 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2118 | StringRef Blob; |
| 2119 | switch ((ControlRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2120 | case METADATA: { |
| 2121 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 2122 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 2123 | Diag(Record[0] < VERSION_MAJOR? diag::err_pch_version_too_old |
| 2124 | : diag::err_pch_version_too_new); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2125 | return VersionMismatch; |
| 2126 | } |
| 2127 | |
| 2128 | bool hasErrors = Record[5]; |
| 2129 | if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) { |
| 2130 | Diag(diag::err_pch_with_compiler_errors); |
| 2131 | return HadErrors; |
| 2132 | } |
| 2133 | |
| 2134 | F.RelocatablePCH = Record[4]; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2135 | // Relative paths in a relocatable PCH are relative to our sysroot. |
| 2136 | if (F.RelocatablePCH) |
| 2137 | F.BaseDirectory = isysroot.empty() ? "/" : isysroot; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2138 | |
| 2139 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2140 | StringRef ASTBranch = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2141 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2142 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 2143 | Diag(diag::err_pch_different_branch) << ASTBranch << CurBranch; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2144 | return VersionMismatch; |
| 2145 | } |
| 2146 | break; |
| 2147 | } |
| 2148 | |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 2149 | case SIGNATURE: |
| 2150 | assert((!F.Signature || F.Signature == Record[0]) && "signature changed"); |
| 2151 | F.Signature = Record[0]; |
| 2152 | break; |
| 2153 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2154 | case IMPORTS: { |
| 2155 | // Load each of the imported PCH files. |
| 2156 | unsigned Idx = 0, N = Record.size(); |
| 2157 | while (Idx < N) { |
| 2158 | // Read information about the AST file. |
| 2159 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 2160 | // The import location will be the local one for now; we will adjust |
| 2161 | // all import locations of module imports after the global source |
| 2162 | // location info are setup. |
| 2163 | SourceLocation ImportLoc = |
| 2164 | SourceLocation::getFromRawEncoding(Record[Idx++]); |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 2165 | off_t StoredSize = (off_t)Record[Idx++]; |
| 2166 | time_t StoredModTime = (time_t)Record[Idx++]; |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 2167 | ASTFileSignature StoredSignature = Record[Idx++]; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2168 | auto ImportedFile = ReadPath(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2169 | |
| 2170 | // Load the AST file. |
| 2171 | switch(ReadASTCore(ImportedFile, ImportedKind, ImportLoc, &F, Loaded, |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 2172 | StoredSize, StoredModTime, StoredSignature, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2173 | ClientLoadCapabilities)) { |
| 2174 | case Failure: return Failure; |
| 2175 | // If we have to ignore the dependency, we'll have to ignore this too. |
Douglas Gregor | 2f1806e | 2013-03-19 00:38:50 +0000 | [diff] [blame] | 2176 | case Missing: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2177 | case OutOfDate: return OutOfDate; |
| 2178 | case VersionMismatch: return VersionMismatch; |
| 2179 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 2180 | case HadErrors: return HadErrors; |
| 2181 | case Success: break; |
| 2182 | } |
| 2183 | } |
| 2184 | break; |
| 2185 | } |
| 2186 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 2187 | case KNOWN_MODULE_FILES: |
| 2188 | break; |
| 2189 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2190 | case LANGUAGE_OPTIONS: { |
| 2191 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 2192 | // FIXME: The &F == *ModuleMgr.begin() check is wrong for modules. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2193 | if (Listener && &F == *ModuleMgr.begin() && |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 2194 | ParseLanguageOptions(Record, Complain, *Listener, |
| 2195 | AllowCompatibleConfigurationMismatch) && |
Ben Langmuir | 2cb4a78 | 2014-02-05 22:21:15 +0000 | [diff] [blame] | 2196 | !DisableValidation && !AllowConfigurationMismatch) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2197 | return ConfigurationMismatch; |
| 2198 | break; |
| 2199 | } |
| 2200 | |
| 2201 | case TARGET_OPTIONS: { |
| 2202 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 2203 | if (Listener && &F == *ModuleMgr.begin() && |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 2204 | ParseTargetOptions(Record, Complain, *Listener, |
| 2205 | AllowCompatibleConfigurationMismatch) && |
Ben Langmuir | 2cb4a78 | 2014-02-05 22:21:15 +0000 | [diff] [blame] | 2206 | !DisableValidation && !AllowConfigurationMismatch) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2207 | return ConfigurationMismatch; |
| 2208 | break; |
| 2209 | } |
| 2210 | |
| 2211 | case DIAGNOSTIC_OPTIONS: { |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 2212 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate)==0; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2213 | if (Listener && &F == *ModuleMgr.begin() && |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 2214 | !AllowCompatibleConfigurationMismatch && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2215 | ParseDiagnosticOptions(Record, Complain, *Listener) && |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 2216 | !DisableValidation) |
| 2217 | return OutOfDate; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2218 | break; |
| 2219 | } |
| 2220 | |
| 2221 | case FILE_SYSTEM_OPTIONS: { |
| 2222 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 2223 | if (Listener && &F == *ModuleMgr.begin() && |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 2224 | !AllowCompatibleConfigurationMismatch && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2225 | ParseFileSystemOptions(Record, Complain, *Listener) && |
Ben Langmuir | 2cb4a78 | 2014-02-05 22:21:15 +0000 | [diff] [blame] | 2226 | !DisableValidation && !AllowConfigurationMismatch) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2227 | return ConfigurationMismatch; |
| 2228 | break; |
| 2229 | } |
| 2230 | |
| 2231 | case HEADER_SEARCH_OPTIONS: { |
| 2232 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 2233 | if (Listener && &F == *ModuleMgr.begin() && |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 2234 | !AllowCompatibleConfigurationMismatch && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2235 | ParseHeaderSearchOptions(Record, Complain, *Listener) && |
Ben Langmuir | 2cb4a78 | 2014-02-05 22:21:15 +0000 | [diff] [blame] | 2236 | !DisableValidation && !AllowConfigurationMismatch) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2237 | return ConfigurationMismatch; |
| 2238 | break; |
| 2239 | } |
| 2240 | |
| 2241 | case PREPROCESSOR_OPTIONS: { |
| 2242 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; |
| 2243 | if (Listener && &F == *ModuleMgr.begin() && |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 2244 | !AllowCompatibleConfigurationMismatch && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2245 | ParsePreprocessorOptions(Record, Complain, *Listener, |
| 2246 | SuggestedPredefines) && |
Ben Langmuir | 2cb4a78 | 2014-02-05 22:21:15 +0000 | [diff] [blame] | 2247 | !DisableValidation && !AllowConfigurationMismatch) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2248 | return ConfigurationMismatch; |
| 2249 | break; |
| 2250 | } |
| 2251 | |
| 2252 | case ORIGINAL_FILE: |
| 2253 | F.OriginalSourceFileID = FileID::get(Record[0]); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2254 | F.ActualOriginalSourceFileName = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2255 | F.OriginalSourceFileName = F.ActualOriginalSourceFileName; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2256 | ResolveImportedPath(F, F.OriginalSourceFileName); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2257 | break; |
| 2258 | |
| 2259 | case ORIGINAL_FILE_ID: |
| 2260 | F.OriginalSourceFileID = FileID::get(Record[0]); |
| 2261 | break; |
| 2262 | |
| 2263 | case ORIGINAL_PCH_DIR: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2264 | F.OriginalDir = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2265 | break; |
| 2266 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2267 | case MODULE_NAME: |
| 2268 | F.ModuleName = Blob; |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 2269 | if (Listener) |
| 2270 | Listener->ReadModuleName(F.ModuleName); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2271 | break; |
| 2272 | |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2273 | case MODULE_DIRECTORY: { |
| 2274 | assert(!F.ModuleName.empty() && |
| 2275 | "MODULE_DIRECTORY found before MODULE_NAME"); |
| 2276 | // If we've already loaded a module map file covering this module, we may |
| 2277 | // have a better path for it (relative to the current build). |
| 2278 | Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName); |
| 2279 | if (M && M->Directory) { |
| 2280 | // If we're implicitly loading a module, the base directory can't |
| 2281 | // change between the build and use. |
| 2282 | if (F.Kind != MK_ExplicitModule) { |
| 2283 | const DirectoryEntry *BuildDir = |
| 2284 | PP.getFileManager().getDirectory(Blob); |
| 2285 | if (!BuildDir || BuildDir != M->Directory) { |
| 2286 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 2287 | Diag(diag::err_imported_module_relocated) |
| 2288 | << F.ModuleName << Blob << M->Directory->getName(); |
| 2289 | return OutOfDate; |
| 2290 | } |
| 2291 | } |
| 2292 | F.BaseDirectory = M->Directory->getName(); |
| 2293 | } else { |
| 2294 | F.BaseDirectory = Blob; |
| 2295 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2296 | break; |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2297 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2298 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2299 | case MODULE_MAP_FILE: |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 2300 | if (ASTReadResult Result = |
| 2301 | ReadModuleMapFileBlock(Record, F, ImportedBy, ClientLoadCapabilities)) |
| 2302 | return Result; |
Ben Langmuir | 264ea15 | 2014-11-08 00:06:39 +0000 | [diff] [blame] | 2303 | break; |
| 2304 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2305 | case INPUT_FILE_OFFSETS: |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2306 | NumInputs = Record[0]; |
| 2307 | NumUserInputs = Record[1]; |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 2308 | F.InputFileOffsets = (const uint64_t *)Blob.data(); |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2309 | F.InputFilesLoaded.resize(NumInputs); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2310 | break; |
| 2311 | } |
| 2312 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2315 | ASTReader::ASTReadResult |
| 2316 | ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2317 | BitstreamCursor &Stream = F.Stream; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2318 | |
| 2319 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
| 2320 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2321 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | // Read all of the records and blocks for the AST file. |
| 2325 | RecordData Record; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2326 | while (1) { |
| 2327 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 2328 | |
| 2329 | switch (Entry.Kind) { |
| 2330 | case llvm::BitstreamEntry::Error: |
| 2331 | Error("error at end of module block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2332 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2333 | case llvm::BitstreamEntry::EndBlock: { |
Richard Smith | c0fbba7 | 2013-04-03 22:49:41 +0000 | [diff] [blame] | 2334 | // Outside of C++, we do not store a lookup map for the translation unit. |
| 2335 | // Instead, mark it as needing a lookup map to be built if this module |
| 2336 | // contains any declarations lexically within it (which it always does!). |
| 2337 | // This usually has no cost, since we very rarely need the lookup map for |
| 2338 | // the translation unit outside C++. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2339 | DeclContext *DC = Context.getTranslationUnitDecl(); |
Richard Smith | c0fbba7 | 2013-04-03 22:49:41 +0000 | [diff] [blame] | 2340 | if (DC->hasExternalLexicalStorage() && |
| 2341 | !getContext().getLangOpts().CPlusPlus) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2342 | DC->setMustBuildLookupTable(); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2343 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2344 | return Success; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2345 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2346 | case llvm::BitstreamEntry::SubBlock: |
| 2347 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2348 | case DECLTYPES_BLOCK_ID: |
| 2349 | // We lazily load the decls block, but we want to set up the |
| 2350 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 2351 | // cursor to it, enter the block and read the abbrevs in that block. |
| 2352 | // With the main cursor, we just skip over it. |
| 2353 | F.DeclsCursor = Stream; |
| 2354 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 2355 | // Read the abbrevs. |
| 2356 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
| 2357 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2358 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2359 | } |
| 2360 | break; |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 2361 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2362 | case PREPROCESSOR_BLOCK_ID: |
| 2363 | F.MacroCursor = Stream; |
| 2364 | if (!PP.getExternalSource()) |
| 2365 | PP.setExternalSource(this); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2366 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2367 | if (Stream.SkipBlock() || |
| 2368 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
| 2369 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2370 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2371 | } |
| 2372 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
| 2373 | break; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2374 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2375 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 2376 | F.PreprocessorDetailCursor = Stream; |
| 2377 | if (Stream.SkipBlock() || |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2378 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2379 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2380 | Error("malformed preprocessor detail record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2381 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2382 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2383 | F.PreprocessorDetailStartOffset |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2384 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 2385 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2386 | if (!PP.getPreprocessingRecord()) |
| 2387 | PP.createPreprocessingRecord(); |
| 2388 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2389 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2390 | break; |
| 2391 | |
| 2392 | case SOURCE_MANAGER_BLOCK_ID: |
| 2393 | if (ReadSourceManagerBlock(F)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2394 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2395 | break; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2396 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2397 | case SUBMODULE_BLOCK_ID: |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2398 | if (ASTReadResult Result = ReadSubmoduleBlock(F, ClientLoadCapabilities)) |
| 2399 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2400 | break; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2401 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2402 | case COMMENTS_BLOCK_ID: { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2403 | BitstreamCursor C = Stream; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2404 | if (Stream.SkipBlock() || |
| 2405 | ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) { |
| 2406 | Error("malformed comments block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2407 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2408 | } |
| 2409 | CommentsCursors.push_back(std::make_pair(C, &F)); |
| 2410 | break; |
| 2411 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2412 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2413 | default: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2414 | if (Stream.SkipBlock()) { |
| 2415 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2416 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2417 | } |
| 2418 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2419 | } |
| 2420 | continue; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2421 | |
| 2422 | case llvm::BitstreamEntry::Record: |
| 2423 | // The interesting case. |
| 2424 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | // Read and process a record. |
| 2428 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2429 | StringRef Blob; |
| 2430 | switch ((ASTRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2431 | default: // Default behavior: ignore. |
| 2432 | break; |
| 2433 | |
| 2434 | case TYPE_OFFSET: { |
| 2435 | if (F.LocalNumTypes != 0) { |
| 2436 | Error("duplicate TYPE_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2437 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2438 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2439 | F.TypeOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2440 | F.LocalNumTypes = Record[0]; |
| 2441 | unsigned LocalBaseTypeIndex = Record[1]; |
| 2442 | F.BaseTypeIndex = getTotalNumTypes(); |
| 2443 | |
| 2444 | if (F.LocalNumTypes > 0) { |
| 2445 | // Introduce the global -> local mapping for types within this module. |
| 2446 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 2447 | |
| 2448 | // Introduce the local -> global mapping for types within this module. |
| 2449 | F.TypeRemap.insertOrReplace( |
| 2450 | std::make_pair(LocalBaseTypeIndex, |
| 2451 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2452 | |
| 2453 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2454 | } |
| 2455 | break; |
| 2456 | } |
| 2457 | |
| 2458 | case DECL_OFFSET: { |
| 2459 | if (F.LocalNumDecls != 0) { |
| 2460 | Error("duplicate DECL_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2461 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2462 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2463 | F.DeclOffsets = (const DeclOffset *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2464 | F.LocalNumDecls = Record[0]; |
| 2465 | unsigned LocalBaseDeclID = Record[1]; |
| 2466 | F.BaseDeclID = getTotalNumDecls(); |
| 2467 | |
| 2468 | if (F.LocalNumDecls > 0) { |
| 2469 | // Introduce the global -> local mapping for declarations within this |
| 2470 | // module. |
| 2471 | GlobalDeclMap.insert( |
| 2472 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
| 2473 | |
| 2474 | // Introduce the local -> global mapping for declarations within this |
| 2475 | // module. |
| 2476 | F.DeclRemap.insertOrReplace( |
| 2477 | std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID)); |
| 2478 | |
| 2479 | // Introduce the global -> local mapping for declarations within this |
| 2480 | // module. |
| 2481 | F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID; |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 2482 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2483 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 2484 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2485 | break; |
| 2486 | } |
| 2487 | |
| 2488 | case TU_UPDATE_LEXICAL: { |
| 2489 | DeclContext *TU = Context.getTranslationUnitDecl(); |
| 2490 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2491 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(Blob.data()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2492 | Info.NumLexicalDecls |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2493 | = static_cast<unsigned int>(Blob.size() / sizeof(KindDeclIDPair)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2494 | TU->setHasExternalLexicalStorage(true); |
| 2495 | break; |
| 2496 | } |
| 2497 | |
| 2498 | case UPDATE_VISIBLE: { |
| 2499 | unsigned Idx = 0; |
| 2500 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
| 2501 | ASTDeclContextNameLookupTable *Table = |
Justin Bogner | da4e650 | 2014-04-14 16:34:29 +0000 | [diff] [blame] | 2502 | ASTDeclContextNameLookupTable::Create( |
| 2503 | (const unsigned char *)Blob.data() + Record[Idx++], |
| 2504 | (const unsigned char *)Blob.data() + sizeof(uint32_t), |
| 2505 | (const unsigned char *)Blob.data(), |
| 2506 | ASTDeclContextNameLookupTrait(*this, F)); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 2507 | if (Decl *D = GetExistingDecl(ID)) { |
Richard Smith | d917479 | 2014-03-11 03:10:46 +0000 | [diff] [blame] | 2508 | auto *DC = cast<DeclContext>(D); |
| 2509 | DC->getPrimaryContext()->setHasExternalVisibleStorage(true); |
Richard Smith | 52e3fba | 2014-03-11 07:17:35 +0000 | [diff] [blame] | 2510 | auto *&LookupTable = F.DeclContextInfos[DC].NameLookupTableData; |
| 2511 | delete LookupTable; |
| 2512 | LookupTable = Table; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2513 | } else |
| 2514 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
| 2515 | break; |
| 2516 | } |
| 2517 | |
| 2518 | case IDENTIFIER_TABLE: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2519 | F.IdentifierTableData = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2520 | if (Record[0]) { |
Justin Bogner | da4e650 | 2014-04-14 16:34:29 +0000 | [diff] [blame] | 2521 | F.IdentifierLookupTable = ASTIdentifierLookupTable::Create( |
| 2522 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2523 | (const unsigned char *)F.IdentifierTableData + sizeof(uint32_t), |
| 2524 | (const unsigned char *)F.IdentifierTableData, |
| 2525 | ASTIdentifierLookupTrait(*this, F)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2526 | |
| 2527 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
| 2528 | } |
| 2529 | break; |
| 2530 | |
| 2531 | case IDENTIFIER_OFFSET: { |
| 2532 | if (F.LocalNumIdentifiers != 0) { |
| 2533 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2534 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2535 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2536 | F.IdentifierOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2537 | F.LocalNumIdentifiers = Record[0]; |
| 2538 | unsigned LocalBaseIdentifierID = Record[1]; |
| 2539 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
| 2540 | |
| 2541 | if (F.LocalNumIdentifiers > 0) { |
| 2542 | // Introduce the global -> local mapping for identifiers within this |
| 2543 | // module. |
| 2544 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 2545 | &F)); |
| 2546 | |
| 2547 | // Introduce the local -> global mapping for identifiers within this |
| 2548 | // module. |
| 2549 | F.IdentifierRemap.insertOrReplace( |
| 2550 | std::make_pair(LocalBaseIdentifierID, |
| 2551 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 2552 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2553 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2554 | + F.LocalNumIdentifiers); |
| 2555 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2556 | break; |
| 2557 | } |
| 2558 | |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2559 | case EAGERLY_DESERIALIZED_DECLS: |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 2560 | // FIXME: Skip reading this record if our ASTConsumer doesn't care |
| 2561 | // about "interesting" decls (for instance, if we're building a module). |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2562 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2563 | EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2564 | break; |
| 2565 | |
| 2566 | case SPECIAL_TYPES: |
Douglas Gregor | 44180f8 | 2013-02-01 23:45:03 +0000 | [diff] [blame] | 2567 | if (SpecialTypes.empty()) { |
| 2568 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2569 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
| 2570 | break; |
| 2571 | } |
| 2572 | |
| 2573 | if (SpecialTypes.size() != Record.size()) { |
| 2574 | Error("invalid special-types record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2575 | return Failure; |
Douglas Gregor | 44180f8 | 2013-02-01 23:45:03 +0000 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 2579 | serialization::TypeID ID = getGlobalTypeID(F, Record[I]); |
| 2580 | if (!SpecialTypes[I]) |
| 2581 | SpecialTypes[I] = ID; |
| 2582 | // FIXME: If ID && SpecialTypes[I] != ID, do we need a separate |
| 2583 | // merge step? |
| 2584 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2585 | break; |
| 2586 | |
| 2587 | case STATISTICS: |
| 2588 | TotalNumStatements += Record[0]; |
| 2589 | TotalNumMacros += Record[1]; |
| 2590 | TotalLexicalDeclContexts += Record[2]; |
| 2591 | TotalVisibleDeclContexts += Record[3]; |
| 2592 | break; |
| 2593 | |
| 2594 | case UNUSED_FILESCOPED_DECLS: |
| 2595 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2596 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2597 | break; |
| 2598 | |
| 2599 | case DELEGATING_CTORS: |
| 2600 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2601 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2602 | break; |
| 2603 | |
| 2604 | case WEAK_UNDECLARED_IDENTIFIERS: |
| 2605 | if (Record.size() % 4 != 0) { |
| 2606 | Error("invalid weak identifiers record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2607 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 2611 | // files. This isn't the way to do it :) |
| 2612 | WeakUndeclaredIdentifiers.clear(); |
| 2613 | |
| 2614 | // Translate the weak, undeclared identifiers into global IDs. |
| 2615 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2616 | WeakUndeclaredIdentifiers.push_back( |
| 2617 | getGlobalIdentifierID(F, Record[I++])); |
| 2618 | WeakUndeclaredIdentifiers.push_back( |
| 2619 | getGlobalIdentifierID(F, Record[I++])); |
| 2620 | WeakUndeclaredIdentifiers.push_back( |
| 2621 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2622 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2623 | } |
| 2624 | break; |
| 2625 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2626 | case SELECTOR_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2627 | F.SelectorOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2628 | F.LocalNumSelectors = Record[0]; |
| 2629 | unsigned LocalBaseSelectorID = Record[1]; |
| 2630 | F.BaseSelectorID = getTotalNumSelectors(); |
| 2631 | |
| 2632 | if (F.LocalNumSelectors > 0) { |
| 2633 | // Introduce the global -> local mapping for selectors within this |
| 2634 | // module. |
| 2635 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 2636 | |
| 2637 | // Introduce the local -> global mapping for selectors within this |
| 2638 | // module. |
| 2639 | F.SelectorRemap.insertOrReplace( |
| 2640 | std::make_pair(LocalBaseSelectorID, |
| 2641 | F.BaseSelectorID - LocalBaseSelectorID)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2642 | |
| 2643 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2644 | } |
| 2645 | break; |
| 2646 | } |
| 2647 | |
| 2648 | case METHOD_POOL: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2649 | F.SelectorLookupTableData = (const unsigned char *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2650 | if (Record[0]) |
| 2651 | F.SelectorLookupTable |
| 2652 | = ASTSelectorLookupTable::Create( |
| 2653 | F.SelectorLookupTableData + Record[0], |
| 2654 | F.SelectorLookupTableData, |
| 2655 | ASTSelectorLookupTrait(*this, F)); |
| 2656 | TotalNumMethodPoolEntries += Record[1]; |
| 2657 | break; |
| 2658 | |
| 2659 | case REFERENCED_SELECTOR_POOL: |
| 2660 | if (!Record.empty()) { |
| 2661 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2662 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 2663 | Record[Idx++])); |
| 2664 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2665 | getRawEncoding()); |
| 2666 | } |
| 2667 | } |
| 2668 | break; |
| 2669 | |
| 2670 | case PP_COUNTER_VALUE: |
| 2671 | if (!Record.empty() && Listener) |
| 2672 | Listener->ReadCounter(F, Record[0]); |
| 2673 | break; |
| 2674 | |
| 2675 | case FILE_SORTED_DECLS: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2676 | F.FileSortedDecls = (const DeclID *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2677 | F.NumFileSortedDecls = Record[0]; |
| 2678 | break; |
| 2679 | |
| 2680 | case SOURCE_LOCATION_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2681 | F.SLocEntryOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2682 | F.LocalNumSLocEntries = Record[0]; |
| 2683 | unsigned SLocSpaceSize = Record[1]; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 2684 | std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2685 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2686 | SLocSpaceSize); |
| 2687 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2688 | // we invert it. Because we invert it, though, we need the other end of |
| 2689 | // the range. |
| 2690 | unsigned RangeStart = |
| 2691 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2692 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2693 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2694 | |
| 2695 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 2696 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 2697 | GlobalSLocOffsetMap.insert( |
| 2698 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 2699 | - SLocSpaceSize,&F)); |
| 2700 | |
| 2701 | // Initialize the remapping table. |
| 2702 | // Invalid stays invalid. |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 2703 | F.SLocRemap.insertOrReplace(std::make_pair(0U, 0)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2704 | // This module. Base was 2 when being compiled. |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 2705 | F.SLocRemap.insertOrReplace(std::make_pair(2U, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2706 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
| 2707 | |
| 2708 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
| 2709 | break; |
| 2710 | } |
| 2711 | |
| 2712 | case MODULE_OFFSET_MAP: { |
| 2713 | // Additional remapping information. |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2714 | const unsigned char *Data = (const unsigned char*)Blob.data(); |
| 2715 | const unsigned char *DataEnd = Data + Blob.size(); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 2716 | |
| 2717 | // If we see this entry before SOURCE_LOCATION_OFFSETS, add placeholders. |
| 2718 | if (F.SLocRemap.find(0) == F.SLocRemap.end()) { |
| 2719 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2720 | F.SLocRemap.insert(std::make_pair(2U, 1)); |
| 2721 | } |
| 2722 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2723 | // Continuous range maps we may be updating in our module. |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 2724 | typedef ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2725 | RemapBuilder; |
| 2726 | RemapBuilder SLocRemap(F.SLocRemap); |
| 2727 | RemapBuilder IdentifierRemap(F.IdentifierRemap); |
| 2728 | RemapBuilder MacroRemap(F.MacroRemap); |
| 2729 | RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2730 | RemapBuilder SubmoduleRemap(F.SubmoduleRemap); |
| 2731 | RemapBuilder SelectorRemap(F.SelectorRemap); |
| 2732 | RemapBuilder DeclRemap(F.DeclRemap); |
| 2733 | RemapBuilder TypeRemap(F.TypeRemap); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2734 | |
| 2735 | while(Data < DataEnd) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 2736 | using namespace llvm::support; |
| 2737 | uint16_t Len = endian::readNext<uint16_t, little, unaligned>(Data); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2738 | StringRef Name = StringRef((const char*)Data, Len); |
| 2739 | Data += Len; |
| 2740 | ModuleFile *OM = ModuleMgr.lookup(Name); |
| 2741 | if (!OM) { |
| 2742 | Error("SourceLocation remap refers to unknown module"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2743 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2744 | } |
| 2745 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 2746 | uint32_t SLocOffset = |
| 2747 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 2748 | uint32_t IdentifierIDOffset = |
| 2749 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 2750 | uint32_t MacroIDOffset = |
| 2751 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 2752 | uint32_t PreprocessedEntityIDOffset = |
| 2753 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 2754 | uint32_t SubmoduleIDOffset = |
| 2755 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 2756 | uint32_t SelectorIDOffset = |
| 2757 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 2758 | uint32_t DeclIDOffset = |
| 2759 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 2760 | uint32_t TypeIndexOffset = |
| 2761 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 2762 | |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 2763 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 2764 | |
| 2765 | auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset, |
| 2766 | RemapBuilder &Remap) { |
| 2767 | if (Offset != None) |
| 2768 | Remap.insert(std::make_pair(Offset, |
| 2769 | static_cast<int>(BaseOffset - Offset))); |
| 2770 | }; |
| 2771 | mapOffset(SLocOffset, OM->SLocEntryBaseOffset, SLocRemap); |
| 2772 | mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap); |
| 2773 | mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap); |
| 2774 | mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID, |
| 2775 | PreprocessedEntityRemap); |
| 2776 | mapOffset(SubmoduleIDOffset, OM->BaseSubmoduleID, SubmoduleRemap); |
| 2777 | mapOffset(SelectorIDOffset, OM->BaseSelectorID, SelectorRemap); |
| 2778 | mapOffset(DeclIDOffset, OM->BaseDeclID, DeclRemap); |
| 2779 | mapOffset(TypeIndexOffset, OM->BaseTypeIndex, TypeRemap); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2780 | |
| 2781 | // Global -> local mappings. |
| 2782 | F.GlobalToLocalDeclIDs[OM] = DeclIDOffset; |
| 2783 | } |
| 2784 | break; |
| 2785 | } |
| 2786 | |
| 2787 | case SOURCE_MANAGER_LINE_TABLE: |
| 2788 | if (ParseLineTable(F, Record)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2789 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2790 | break; |
| 2791 | |
| 2792 | case SOURCE_LOCATION_PRELOADS: { |
| 2793 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2794 | // which is based off F.SLocEntryBaseID. |
| 2795 | if (!F.PreloadSLocEntries.empty()) { |
| 2796 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2797 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | F.PreloadSLocEntries.swap(Record); |
| 2801 | break; |
| 2802 | } |
| 2803 | |
| 2804 | case EXT_VECTOR_DECLS: |
| 2805 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2806 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2807 | break; |
| 2808 | |
| 2809 | case VTABLE_USES: |
| 2810 | if (Record.size() % 3 != 0) { |
| 2811 | Error("Invalid VTABLE_USES record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2812 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | // Later tables overwrite earlier ones. |
| 2816 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2817 | // the right way to do this. |
| 2818 | VTableUses.clear(); |
| 2819 | |
| 2820 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2821 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2822 | VTableUses.push_back( |
| 2823 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2824 | VTableUses.push_back(Record[Idx++]); |
| 2825 | } |
| 2826 | break; |
| 2827 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2828 | case PENDING_IMPLICIT_INSTANTIATIONS: |
| 2829 | if (PendingInstantiations.size() % 2 != 0) { |
| 2830 | Error("Invalid existing PendingInstantiations"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2831 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | if (Record.size() % 2 != 0) { |
| 2835 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2836 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2840 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2841 | PendingInstantiations.push_back( |
| 2842 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2843 | } |
| 2844 | break; |
| 2845 | |
| 2846 | case SEMA_DECL_REFS: |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 2847 | if (Record.size() != 2) { |
| 2848 | Error("Invalid SEMA_DECL_REFS block"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2849 | return Failure; |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 2850 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2851 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2852 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 2853 | break; |
| 2854 | |
| 2855 | case PPD_ENTITIES_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2856 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)Blob.data(); |
| 2857 | assert(Blob.size() % sizeof(PPEntityOffset) == 0); |
| 2858 | F.NumPreprocessedEntities = Blob.size() / sizeof(PPEntityOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2859 | |
| 2860 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
| 2861 | |
| 2862 | unsigned StartingID; |
| 2863 | if (!PP.getPreprocessingRecord()) |
| 2864 | PP.createPreprocessingRecord(); |
| 2865 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2866 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2867 | StartingID |
| 2868 | = PP.getPreprocessingRecord() |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2869 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2870 | F.BasePreprocessedEntityID = StartingID; |
| 2871 | |
| 2872 | if (F.NumPreprocessedEntities > 0) { |
| 2873 | // Introduce the global -> local mapping for preprocessed entities in |
| 2874 | // this module. |
| 2875 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2876 | |
| 2877 | // Introduce the local -> global mapping for preprocessed entities in |
| 2878 | // this module. |
| 2879 | F.PreprocessedEntityRemap.insertOrReplace( |
| 2880 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2881 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2882 | } |
| 2883 | |
| 2884 | break; |
| 2885 | } |
| 2886 | |
| 2887 | case DECL_UPDATE_OFFSETS: { |
| 2888 | if (Record.size() % 2 != 0) { |
| 2889 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2890 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2891 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 2892 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) { |
| 2893 | GlobalDeclID ID = getGlobalDeclID(F, Record[I]); |
| 2894 | DeclUpdateOffsets[ID].push_back(std::make_pair(&F, Record[I + 1])); |
| 2895 | |
| 2896 | // If we've already loaded the decl, perform the updates when we finish |
| 2897 | // loading this block. |
| 2898 | if (Decl *D = GetExistingDecl(ID)) |
| 2899 | PendingUpdateRecords.push_back(std::make_pair(ID, D)); |
| 2900 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2901 | break; |
| 2902 | } |
| 2903 | |
| 2904 | case DECL_REPLACEMENTS: { |
| 2905 | if (Record.size() % 3 != 0) { |
| 2906 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2907 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2908 | } |
| 2909 | for (unsigned I = 0, N = Record.size(); I != N; I += 3) |
| 2910 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
| 2911 | = ReplacedDeclInfo(&F, Record[I+1], Record[I+2]); |
| 2912 | break; |
| 2913 | } |
| 2914 | |
| 2915 | case OBJC_CATEGORIES_MAP: { |
| 2916 | if (F.LocalNumObjCCategoriesInMap != 0) { |
| 2917 | Error("duplicate OBJC_CATEGORIES_MAP record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2918 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | F.LocalNumObjCCategoriesInMap = Record[0]; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2922 | F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2923 | break; |
| 2924 | } |
| 2925 | |
| 2926 | case OBJC_CATEGORIES: |
| 2927 | F.ObjCCategories.swap(Record); |
| 2928 | break; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2929 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2930 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2931 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2932 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2933 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2934 | } |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2935 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2936 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2937 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)Blob.data(); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2938 | break; |
| 2939 | } |
| 2940 | |
| 2941 | case CXX_CTOR_INITIALIZERS_OFFSETS: { |
| 2942 | if (F.LocalNumCXXCtorInitializers != 0) { |
| 2943 | Error("duplicate CXX_CTOR_INITIALIZERS_OFFSETS record in AST file"); |
| 2944 | return Failure; |
| 2945 | } |
| 2946 | |
| 2947 | F.LocalNumCXXCtorInitializers = Record[0]; |
| 2948 | F.CXXCtorInitializersOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2949 | break; |
| 2950 | } |
| 2951 | |
| 2952 | case DIAG_PRAGMA_MAPPINGS: |
| 2953 | if (F.PragmaDiagMappings.empty()) |
| 2954 | F.PragmaDiagMappings.swap(Record); |
| 2955 | else |
| 2956 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2957 | Record.begin(), Record.end()); |
| 2958 | break; |
| 2959 | |
| 2960 | case CUDA_SPECIAL_DECL_REFS: |
| 2961 | // Later tables overwrite earlier ones. |
| 2962 | // FIXME: Modules will have trouble with this. |
| 2963 | CUDASpecialDeclRefs.clear(); |
| 2964 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2965 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 2966 | break; |
| 2967 | |
| 2968 | case HEADER_SEARCH_TABLE: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2969 | F.HeaderFileInfoTableData = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2970 | F.LocalNumHeaderFileInfos = Record[1]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2971 | if (Record[0]) { |
| 2972 | F.HeaderFileInfoTable |
| 2973 | = HeaderFileInfoLookupTable::Create( |
| 2974 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 2975 | (const unsigned char *)F.HeaderFileInfoTableData, |
| 2976 | HeaderFileInfoTrait(*this, F, |
| 2977 | &PP.getHeaderSearchInfo(), |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2978 | Blob.data() + Record[2])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2979 | |
| 2980 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 2981 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 2982 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
| 2983 | } |
| 2984 | break; |
| 2985 | } |
| 2986 | |
| 2987 | case FP_PRAGMA_OPTIONS: |
| 2988 | // Later tables overwrite earlier ones. |
| 2989 | FPPragmaOptions.swap(Record); |
| 2990 | break; |
| 2991 | |
| 2992 | case OPENCL_EXTENSIONS: |
| 2993 | // Later tables overwrite earlier ones. |
| 2994 | OpenCLExtensions.swap(Record); |
| 2995 | break; |
| 2996 | |
| 2997 | case TENTATIVE_DEFINITIONS: |
| 2998 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2999 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
| 3000 | break; |
| 3001 | |
| 3002 | case KNOWN_NAMESPACES: |
| 3003 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3004 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
| 3005 | break; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3006 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3007 | case UNDEFINED_BUT_USED: |
| 3008 | if (UndefinedButUsed.size() % 2 != 0) { |
| 3009 | Error("Invalid existing UndefinedButUsed"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3010 | return Failure; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | if (Record.size() % 2 != 0) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3014 | Error("invalid undefined-but-used record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3015 | return Failure; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3016 | } |
| 3017 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3018 | UndefinedButUsed.push_back(getGlobalDeclID(F, Record[I++])); |
| 3019 | UndefinedButUsed.push_back( |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3020 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3021 | } |
| 3022 | break; |
| 3023 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3024 | case IMPORTED_MODULES: { |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3025 | if (F.Kind != MK_ImplicitModule && F.Kind != MK_ExplicitModule) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3026 | // If we aren't loading a module (which has its own exports), make |
| 3027 | // all of the imported modules visible. |
| 3028 | // FIXME: Deal with macros-only imports. |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 3029 | for (unsigned I = 0, N = Record.size(); I != N; /**/) { |
| 3030 | unsigned GlobalID = getGlobalSubmoduleID(F, Record[I++]); |
| 3031 | SourceLocation Loc = ReadSourceLocation(F, Record, I); |
| 3032 | if (GlobalID) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 3033 | ImportedModules.push_back(ImportedSubmodule(GlobalID, Loc)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3034 | } |
| 3035 | } |
| 3036 | break; |
| 3037 | } |
| 3038 | |
| 3039 | case LOCAL_REDECLARATIONS: { |
| 3040 | F.RedeclarationChains.swap(Record); |
| 3041 | break; |
| 3042 | } |
| 3043 | |
| 3044 | case LOCAL_REDECLARATIONS_MAP: { |
| 3045 | if (F.LocalNumRedeclarationsInMap != 0) { |
| 3046 | Error("duplicate LOCAL_REDECLARATIONS_MAP record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3047 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | F.LocalNumRedeclarationsInMap = Record[0]; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3051 | F.RedeclarationsMap = (const LocalRedeclarationsInfo *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3052 | break; |
| 3053 | } |
| 3054 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3055 | case MACRO_OFFSET: { |
| 3056 | if (F.LocalNumMacros != 0) { |
| 3057 | Error("duplicate MACRO_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3058 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3059 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3060 | F.MacroOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3061 | F.LocalNumMacros = Record[0]; |
| 3062 | unsigned LocalBaseMacroID = Record[1]; |
| 3063 | F.BaseMacroID = getTotalNumMacros(); |
| 3064 | |
| 3065 | if (F.LocalNumMacros > 0) { |
| 3066 | // Introduce the global -> local mapping for macros within this module. |
| 3067 | GlobalMacroMap.insert(std::make_pair(getTotalNumMacros() + 1, &F)); |
| 3068 | |
| 3069 | // Introduce the local -> global mapping for macros within this module. |
| 3070 | F.MacroRemap.insertOrReplace( |
| 3071 | std::make_pair(LocalBaseMacroID, |
| 3072 | F.BaseMacroID - LocalBaseMacroID)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3073 | |
| 3074 | MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3075 | } |
| 3076 | break; |
| 3077 | } |
| 3078 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3079 | case LATE_PARSED_TEMPLATE: { |
| 3080 | LateParsedTemplates.append(Record.begin(), Record.end()); |
| 3081 | break; |
| 3082 | } |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 3083 | |
| 3084 | case OPTIMIZE_PRAGMA_OPTIONS: |
| 3085 | if (Record.size() != 1) { |
| 3086 | Error("invalid pragma optimize record"); |
| 3087 | return Failure; |
| 3088 | } |
| 3089 | OptimizeOffPragmaLocation = ReadSourceLocation(F, Record[0]); |
| 3090 | break; |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 3091 | |
| 3092 | case UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES: |
| 3093 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3094 | UnusedLocalTypedefNameCandidates.push_back( |
| 3095 | getGlobalDeclID(F, Record[I])); |
| 3096 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3097 | } |
| 3098 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3099 | } |
| 3100 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3101 | ASTReader::ASTReadResult |
| 3102 | ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, |
| 3103 | const ModuleFile *ImportedBy, |
| 3104 | unsigned ClientLoadCapabilities) { |
| 3105 | unsigned Idx = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3106 | F.ModuleMapPath = ReadPath(F, Record, Idx); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3107 | |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3108 | if (F.Kind == MK_ExplicitModule) { |
| 3109 | // For an explicitly-loaded module, we don't care whether the original |
| 3110 | // module map file exists or matches. |
| 3111 | return Success; |
| 3112 | } |
| 3113 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3114 | // Try to resolve ModuleName in the current header search context and |
| 3115 | // verify that it is found in the same module map file as we saved. If the |
| 3116 | // top-level AST file is a main file, skip this check because there is no |
| 3117 | // usable header search context. |
| 3118 | assert(!F.ModuleName.empty() && |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3119 | "MODULE_NAME should come before MODULE_MAP_FILE"); |
| 3120 | if (F.Kind == MK_ImplicitModule && |
| 3121 | (*ModuleMgr.begin())->Kind != MK_MainFile) { |
| 3122 | // An implicitly-loaded module file should have its module listed in some |
| 3123 | // module map file that we've already loaded. |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3124 | Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName); |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3125 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 3126 | const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr; |
| 3127 | if (!ModMap) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3128 | assert(ImportedBy && "top-level import should be verified"); |
| 3129 | if ((ClientLoadCapabilities & ARR_Missing) == 0) |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3130 | Diag(diag::err_imported_module_not_found) << F.ModuleName << F.FileName |
| 3131 | << ImportedBy->FileName |
| 3132 | << F.ModuleMapPath; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3133 | return Missing; |
| 3134 | } |
| 3135 | |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3136 | assert(M->Name == F.ModuleName && "found module with different name"); |
| 3137 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3138 | // Check the primary module map file. |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3139 | const FileEntry *StoredModMap = FileMgr.getFile(F.ModuleMapPath); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3140 | if (StoredModMap == nullptr || StoredModMap != ModMap) { |
| 3141 | assert(ModMap && "found module is missing module map file"); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3142 | assert(ImportedBy && "top-level import should be verified"); |
| 3143 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3144 | Diag(diag::err_imported_module_modmap_changed) |
| 3145 | << F.ModuleName << ImportedBy->FileName |
| 3146 | << ModMap->getName() << F.ModuleMapPath; |
| 3147 | return OutOfDate; |
| 3148 | } |
| 3149 | |
| 3150 | llvm::SmallPtrSet<const FileEntry *, 1> AdditionalStoredMaps; |
| 3151 | for (unsigned I = 0, N = Record[Idx++]; I < N; ++I) { |
| 3152 | // FIXME: we should use input files rather than storing names. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3153 | std::string Filename = ReadPath(F, Record, Idx); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3154 | const FileEntry *F = |
| 3155 | FileMgr.getFile(Filename, false, false); |
| 3156 | if (F == nullptr) { |
| 3157 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3158 | Error("could not find file '" + Filename +"' referenced by AST file"); |
| 3159 | return OutOfDate; |
| 3160 | } |
| 3161 | AdditionalStoredMaps.insert(F); |
| 3162 | } |
| 3163 | |
| 3164 | // Check any additional module map files (e.g. module.private.modulemap) |
| 3165 | // that are not in the pcm. |
| 3166 | if (auto *AdditionalModuleMaps = Map.getAdditionalModuleMapFiles(M)) { |
| 3167 | for (const FileEntry *ModMap : *AdditionalModuleMaps) { |
| 3168 | // Remove files that match |
| 3169 | // Note: SmallPtrSet::erase is really remove |
| 3170 | if (!AdditionalStoredMaps.erase(ModMap)) { |
| 3171 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3172 | Diag(diag::err_module_different_modmap) |
| 3173 | << F.ModuleName << /*new*/0 << ModMap->getName(); |
| 3174 | return OutOfDate; |
| 3175 | } |
| 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | // Check any additional module map files that are in the pcm, but not |
| 3180 | // found in header search. Cases that match are already removed. |
| 3181 | for (const FileEntry *ModMap : AdditionalStoredMaps) { |
| 3182 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3183 | Diag(diag::err_module_different_modmap) |
| 3184 | << F.ModuleName << /*not new*/1 << ModMap->getName(); |
| 3185 | return OutOfDate; |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | if (Listener) |
| 3190 | Listener->ReadModuleMapFile(F.ModuleMapPath); |
| 3191 | return Success; |
| 3192 | } |
| 3193 | |
| 3194 | |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3195 | /// \brief Move the given method to the back of the global list of methods. |
| 3196 | static void moveMethodToBackOfGlobalList(Sema &S, ObjCMethodDecl *Method) { |
| 3197 | // Find the entry for this selector in the method pool. |
| 3198 | Sema::GlobalMethodPool::iterator Known |
| 3199 | = S.MethodPool.find(Method->getSelector()); |
| 3200 | if (Known == S.MethodPool.end()) |
| 3201 | return; |
| 3202 | |
| 3203 | // Retrieve the appropriate method list. |
| 3204 | ObjCMethodList &Start = Method->isInstanceMethod()? Known->second.first |
| 3205 | : Known->second.second; |
| 3206 | bool Found = false; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3207 | for (ObjCMethodList *List = &Start; List; List = List->getNext()) { |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3208 | if (!Found) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3209 | if (List->getMethod() == Method) { |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3210 | Found = true; |
| 3211 | } else { |
| 3212 | // Keep searching. |
| 3213 | continue; |
| 3214 | } |
| 3215 | } |
| 3216 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3217 | if (List->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3218 | List->setMethod(List->getNext()->getMethod()); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3219 | else |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3220 | List->setMethod(Method); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3221 | } |
| 3222 | } |
| 3223 | |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 3224 | void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner) { |
| 3225 | assert(Owner->NameVisibility >= Module::MacrosVisible && |
| 3226 | "nothing to make visible?"); |
| 3227 | |
Richard Smith | e657bbd | 2014-07-18 22:13:40 +0000 | [diff] [blame] | 3228 | // FIXME: Only do this if Owner->NameVisibility == AllVisible. |
Richard Smith | 20e883e | 2015-04-29 23:20:19 +0000 | [diff] [blame] | 3229 | for (Decl *D : Names) { |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3230 | bool wasHidden = D->Hidden; |
| 3231 | D->Hidden = false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3232 | |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3233 | if (wasHidden && SemaObj) { |
| 3234 | if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D)) { |
| 3235 | moveMethodToBackOfGlobalList(*SemaObj, Method); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3236 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3237 | } |
| 3238 | } |
| 3239 | } |
| 3240 | |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3241 | void ASTReader::makeModuleVisible(Module *Mod, |
Argyrios Kyrtzidis | 125df05 | 2013-02-01 16:36:12 +0000 | [diff] [blame] | 3242 | Module::NameVisibilityKind NameVisibility, |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3243 | SourceLocation ImportLoc, |
| 3244 | bool Complain) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3245 | llvm::SmallPtrSet<Module *, 4> Visited; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3246 | SmallVector<Module *, 4> Stack; |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3247 | Stack.push_back(Mod); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3248 | while (!Stack.empty()) { |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3249 | Mod = Stack.pop_back_val(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3250 | |
| 3251 | if (NameVisibility <= Mod->NameVisibility) { |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3252 | // This module already has this level of visibility (or greater), so |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3253 | // there is nothing more to do. |
| 3254 | continue; |
| 3255 | } |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3256 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3257 | if (!Mod->isAvailable()) { |
| 3258 | // Modules that aren't available cannot be made visible. |
| 3259 | continue; |
| 3260 | } |
| 3261 | |
| 3262 | // Update the module's name visibility. |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3263 | if (NameVisibility >= Module::MacrosVisible && |
| 3264 | Mod->NameVisibility < Module::MacrosVisible) |
| 3265 | Mod->MacroVisibilityLoc = ImportLoc; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3266 | Mod->NameVisibility = NameVisibility; |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3267 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3268 | // If we've already deserialized any names from this module, |
| 3269 | // mark them as visible. |
| 3270 | HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod); |
| 3271 | if (Hidden != HiddenNamesMap.end()) { |
Richard Smith | 57721ac | 2014-07-21 04:10:40 +0000 | [diff] [blame] | 3272 | auto HiddenNames = std::move(*Hidden); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3273 | HiddenNamesMap.erase(Hidden); |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 3274 | makeNamesVisible(HiddenNames.second, HiddenNames.first); |
Richard Smith | 57721ac | 2014-07-21 04:10:40 +0000 | [diff] [blame] | 3275 | assert(HiddenNamesMap.find(Mod) == HiddenNamesMap.end() && |
| 3276 | "making names visible added hidden names"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3277 | } |
Dmitri Gribenko | e9bcf5b | 2013-11-04 21:51:33 +0000 | [diff] [blame] | 3278 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3279 | // Push any exported modules onto the stack to be marked as visible. |
Argyrios Kyrtzidis | 8739f7b | 2013-02-19 19:34:40 +0000 | [diff] [blame] | 3280 | SmallVector<Module *, 16> Exports; |
| 3281 | Mod->getExportedModules(Exports); |
| 3282 | for (SmallVectorImpl<Module *>::iterator |
| 3283 | I = Exports.begin(), E = Exports.end(); I != E; ++I) { |
| 3284 | Module *Exported = *I; |
David Blaikie | 82e95a3 | 2014-11-19 07:49:47 +0000 | [diff] [blame] | 3285 | if (Visited.insert(Exported).second) |
Argyrios Kyrtzidis | 8739f7b | 2013-02-19 19:34:40 +0000 | [diff] [blame] | 3286 | Stack.push_back(Exported); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3287 | } |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3288 | |
| 3289 | // Detect any conflicts. |
| 3290 | if (Complain) { |
| 3291 | assert(ImportLoc.isValid() && "Missing import location"); |
| 3292 | for (unsigned I = 0, N = Mod->Conflicts.size(); I != N; ++I) { |
| 3293 | if (Mod->Conflicts[I].Other->NameVisibility >= NameVisibility) { |
| 3294 | Diag(ImportLoc, diag::warn_module_conflict) |
| 3295 | << Mod->getFullModuleName() |
| 3296 | << Mod->Conflicts[I].Other->getFullModuleName() |
| 3297 | << Mod->Conflicts[I].Message; |
| 3298 | // FIXME: Need note where the other module was imported. |
| 3299 | } |
| 3300 | } |
| 3301 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3302 | } |
| 3303 | } |
| 3304 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3305 | bool ASTReader::loadGlobalIndex() { |
| 3306 | if (GlobalIndex) |
| 3307 | return false; |
| 3308 | |
| 3309 | if (TriedLoadingGlobalIndex || !UseGlobalIndex || |
| 3310 | !Context.getLangOpts().Modules) |
| 3311 | return true; |
| 3312 | |
| 3313 | // Try to load the global index. |
| 3314 | TriedLoadingGlobalIndex = true; |
| 3315 | StringRef ModuleCachePath |
| 3316 | = getPreprocessor().getHeaderSearchInfo().getModuleCachePath(); |
| 3317 | std::pair<GlobalModuleIndex *, GlobalModuleIndex::ErrorCode> Result |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3318 | = GlobalModuleIndex::readIndex(ModuleCachePath); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3319 | if (!Result.first) |
| 3320 | return true; |
| 3321 | |
| 3322 | GlobalIndex.reset(Result.first); |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 3323 | ModuleMgr.setGlobalIndex(GlobalIndex.get()); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3324 | return false; |
| 3325 | } |
| 3326 | |
| 3327 | bool ASTReader::isGlobalIndexUnavailable() const { |
| 3328 | return Context.getLangOpts().Modules && UseGlobalIndex && |
| 3329 | !hasGlobalIndex() && TriedLoadingGlobalIndex; |
| 3330 | } |
| 3331 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3332 | static void updateModuleTimestamp(ModuleFile &MF) { |
| 3333 | // Overwrite the timestamp file contents so that file's mtime changes. |
| 3334 | std::string TimestampFilename = MF.getTimestampFilename(); |
Rafael Espindola | dae941a | 2014-08-25 18:17:04 +0000 | [diff] [blame] | 3335 | std::error_code EC; |
| 3336 | llvm::raw_fd_ostream OS(TimestampFilename, EC, llvm::sys::fs::F_Text); |
| 3337 | if (EC) |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3338 | return; |
| 3339 | OS << "Timestamp file\n"; |
| 3340 | } |
| 3341 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3342 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 3343 | ModuleKind Type, |
| 3344 | SourceLocation ImportLoc, |
| 3345 | unsigned ClientLoadCapabilities) { |
Argyrios Kyrtzidis | dc9fdaf | 2013-05-24 05:44:08 +0000 | [diff] [blame] | 3346 | llvm::SaveAndRestore<SourceLocation> |
| 3347 | SetCurImportLocRAII(CurrentImportLoc, ImportLoc); |
| 3348 | |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 3349 | // Defer any pending actions until we get to the end of reading the AST file. |
| 3350 | Deserializing AnASTFile(this); |
| 3351 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3352 | // Bump the generation number. |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3353 | unsigned PreviousGeneration = incrementGeneration(Context); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3354 | |
| 3355 | unsigned NumModules = ModuleMgr.size(); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3356 | SmallVector<ImportedModule, 4> Loaded; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3357 | switch(ASTReadResult ReadResult = ReadASTCore(FileName, Type, ImportLoc, |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3358 | /*ImportedBy=*/nullptr, Loaded, |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 3359 | 0, 0, 0, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3360 | ClientLoadCapabilities)) { |
| 3361 | case Failure: |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3362 | case Missing: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3363 | case OutOfDate: |
| 3364 | case VersionMismatch: |
| 3365 | case ConfigurationMismatch: |
Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3366 | case HadErrors: { |
| 3367 | llvm::SmallPtrSet<ModuleFile *, 4> LoadedSet; |
| 3368 | for (const ImportedModule &IM : Loaded) |
| 3369 | LoadedSet.insert(IM.Mod); |
| 3370 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3371 | ModuleMgr.removeModules(ModuleMgr.begin() + NumModules, ModuleMgr.end(), |
Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3372 | LoadedSet, |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3373 | Context.getLangOpts().Modules |
| 3374 | ? &PP.getHeaderSearchInfo().getModuleMap() |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3375 | : nullptr); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3376 | |
| 3377 | // If we find that any modules are unusable, the global index is going |
| 3378 | // to be out-of-date. Just remove it. |
| 3379 | GlobalIndex.reset(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3380 | ModuleMgr.setGlobalIndex(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3381 | return ReadResult; |
Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3382 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3383 | case Success: |
| 3384 | break; |
| 3385 | } |
| 3386 | |
| 3387 | // Here comes stuff that we only do once the entire chain is loaded. |
| 3388 | |
| 3389 | // Load the AST blocks of all of the modules that we loaded. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3390 | for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(), |
| 3391 | MEnd = Loaded.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3392 | M != MEnd; ++M) { |
| 3393 | ModuleFile &F = *M->Mod; |
| 3394 | |
| 3395 | // Read the AST block. |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3396 | if (ASTReadResult Result = ReadASTBlock(F, ClientLoadCapabilities)) |
| 3397 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3398 | |
| 3399 | // Once read, set the ModuleFile bit base offset and update the size in |
| 3400 | // bits of all files we've seen. |
| 3401 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 3402 | TotalModulesSizeInBits += F.SizeInBits; |
| 3403 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
| 3404 | |
| 3405 | // Preload SLocEntries. |
| 3406 | for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) { |
| 3407 | int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
| 3408 | // Load it through the SourceManager and don't call ReadSLocEntry() |
| 3409 | // directly because the entry may have already been loaded in which case |
| 3410 | // calling ReadSLocEntry() directly would trigger an assertion in |
| 3411 | // SourceManager. |
| 3412 | SourceMgr.getLoadedSLocEntryByID(Index); |
| 3413 | } |
| 3414 | } |
| 3415 | |
Douglas Gregor | 603cd86 | 2013-03-22 18:50:14 +0000 | [diff] [blame] | 3416 | // Setup the import locations and notify the module manager that we've |
| 3417 | // committed to these module files. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3418 | for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(), |
| 3419 | MEnd = Loaded.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3420 | M != MEnd; ++M) { |
| 3421 | ModuleFile &F = *M->Mod; |
Douglas Gregor | 603cd86 | 2013-03-22 18:50:14 +0000 | [diff] [blame] | 3422 | |
| 3423 | ModuleMgr.moduleFileAccepted(&F); |
| 3424 | |
| 3425 | // Set the import location. |
Argyrios Kyrtzidis | 71c1af8 | 2013-02-01 16:36:14 +0000 | [diff] [blame] | 3426 | F.DirectImportLoc = ImportLoc; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3427 | if (!M->ImportedBy) |
| 3428 | F.ImportLoc = M->ImportLoc; |
| 3429 | else |
| 3430 | F.ImportLoc = ReadSourceLocation(*M->ImportedBy, |
| 3431 | M->ImportLoc.getRawEncoding()); |
| 3432 | } |
| 3433 | |
| 3434 | // Mark all of the identifiers in the identifier table as being out of date, |
| 3435 | // so that various accessors know to check the loaded modules when the |
| 3436 | // identifier is used. |
| 3437 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 3438 | IdEnd = PP.getIdentifierTable().end(); |
| 3439 | Id != IdEnd; ++Id) |
| 3440 | Id->second->setOutOfDate(true); |
| 3441 | |
| 3442 | // Resolve any unresolved module exports. |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3443 | for (unsigned I = 0, N = UnresolvedModuleRefs.size(); I != N; ++I) { |
| 3444 | UnresolvedModuleRef &Unresolved = UnresolvedModuleRefs[I]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3445 | SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID); |
| 3446 | Module *ResolvedMod = getSubmodule(GlobalID); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3447 | |
| 3448 | switch (Unresolved.Kind) { |
| 3449 | case UnresolvedModuleRef::Conflict: |
| 3450 | if (ResolvedMod) { |
| 3451 | Module::Conflict Conflict; |
| 3452 | Conflict.Other = ResolvedMod; |
| 3453 | Conflict.Message = Unresolved.String.str(); |
| 3454 | Unresolved.Mod->Conflicts.push_back(Conflict); |
| 3455 | } |
| 3456 | continue; |
| 3457 | |
| 3458 | case UnresolvedModuleRef::Import: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3459 | if (ResolvedMod) |
| 3460 | Unresolved.Mod->Imports.push_back(ResolvedMod); |
| 3461 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3462 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3463 | case UnresolvedModuleRef::Export: |
| 3464 | if (ResolvedMod || Unresolved.IsWildcard) |
| 3465 | Unresolved.Mod->Exports.push_back( |
| 3466 | Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard)); |
| 3467 | continue; |
| 3468 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3469 | } |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3470 | UnresolvedModuleRefs.clear(); |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 3471 | |
| 3472 | // FIXME: How do we load the 'use'd modules? They may not be submodules. |
| 3473 | // Might be unnecessary as use declarations are only used to build the |
| 3474 | // module itself. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3475 | |
| 3476 | InitializeContext(); |
| 3477 | |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3478 | if (SemaObj) |
| 3479 | UpdateSema(); |
| 3480 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3481 | if (DeserializationListener) |
| 3482 | DeserializationListener->ReaderInitialized(this); |
| 3483 | |
| 3484 | ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule(); |
| 3485 | if (!PrimaryModule.OriginalSourceFileID.isInvalid()) { |
| 3486 | PrimaryModule.OriginalSourceFileID |
| 3487 | = FileID::get(PrimaryModule.SLocEntryBaseID |
| 3488 | + PrimaryModule.OriginalSourceFileID.getOpaqueValue() - 1); |
| 3489 | |
| 3490 | // If this AST file is a precompiled preamble, then set the |
| 3491 | // preamble file ID of the source manager to the file source file |
| 3492 | // from which the preamble was built. |
| 3493 | if (Type == MK_Preamble) { |
| 3494 | SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID); |
| 3495 | } else if (Type == MK_MainFile) { |
| 3496 | SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID); |
| 3497 | } |
| 3498 | } |
| 3499 | |
| 3500 | // For any Objective-C class definitions we have already loaded, make sure |
| 3501 | // that we load any additional categories. |
| 3502 | for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { |
| 3503 | loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), |
| 3504 | ObjCClassesLoaded[I], |
| 3505 | PreviousGeneration); |
| 3506 | } |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3507 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3508 | if (PP.getHeaderSearchInfo() |
| 3509 | .getHeaderSearchOpts() |
| 3510 | .ModulesValidateOncePerBuildSession) { |
| 3511 | // Now we are certain that the module and all modules it depends on are |
| 3512 | // up to date. Create or update timestamp files for modules that are |
| 3513 | // located in the module cache (not for PCH files that could be anywhere |
| 3514 | // in the filesystem). |
| 3515 | for (unsigned I = 0, N = Loaded.size(); I != N; ++I) { |
| 3516 | ImportedModule &M = Loaded[I]; |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3517 | if (M.Mod->Kind == MK_ImplicitModule) { |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3518 | updateModuleTimestamp(*M.Mod); |
| 3519 | } |
| 3520 | } |
| 3521 | } |
| 3522 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3523 | return Success; |
| 3524 | } |
| 3525 | |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 3526 | static ASTFileSignature readASTFileSignature(llvm::BitstreamReader &StreamFile); |
| 3527 | |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 3528 | /// \brief Whether \p Stream starts with the AST/PCH file magic number 'CPCH'. |
| 3529 | static bool startsWithASTFileMagic(BitstreamCursor &Stream) { |
| 3530 | return Stream.Read(8) == 'C' && |
| 3531 | Stream.Read(8) == 'P' && |
| 3532 | Stream.Read(8) == 'C' && |
| 3533 | Stream.Read(8) == 'H'; |
| 3534 | } |
| 3535 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3536 | ASTReader::ASTReadResult |
| 3537 | ASTReader::ReadASTCore(StringRef FileName, |
| 3538 | ModuleKind Type, |
| 3539 | SourceLocation ImportLoc, |
| 3540 | ModuleFile *ImportedBy, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3541 | SmallVectorImpl<ImportedModule> &Loaded, |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3542 | off_t ExpectedSize, time_t ExpectedModTime, |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 3543 | ASTFileSignature ExpectedSignature, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3544 | unsigned ClientLoadCapabilities) { |
| 3545 | ModuleFile *M; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3546 | std::string ErrorStr; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3547 | ModuleManager::AddModuleResult AddResult |
| 3548 | = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy, |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3549 | getGeneration(), ExpectedSize, ExpectedModTime, |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 3550 | ExpectedSignature, readASTFileSignature, |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3551 | M, ErrorStr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3552 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3553 | switch (AddResult) { |
| 3554 | case ModuleManager::AlreadyLoaded: |
| 3555 | return Success; |
| 3556 | |
| 3557 | case ModuleManager::NewlyLoaded: |
| 3558 | // Load module file below. |
| 3559 | break; |
| 3560 | |
| 3561 | case ModuleManager::Missing: |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3562 | // The module file was missing; if the client can handle that, return |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3563 | // it. |
| 3564 | if (ClientLoadCapabilities & ARR_Missing) |
| 3565 | return Missing; |
| 3566 | |
| 3567 | // Otherwise, return an error. |
| 3568 | { |
| 3569 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 3570 | + ErrorStr; |
| 3571 | Error(Msg); |
| 3572 | } |
| 3573 | return Failure; |
| 3574 | |
| 3575 | case ModuleManager::OutOfDate: |
| 3576 | // We couldn't load the module file because it is out-of-date. If the |
| 3577 | // client can handle out-of-date, return it. |
| 3578 | if (ClientLoadCapabilities & ARR_OutOfDate) |
| 3579 | return OutOfDate; |
| 3580 | |
| 3581 | // Otherwise, return an error. |
| 3582 | { |
| 3583 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 3584 | + ErrorStr; |
| 3585 | Error(Msg); |
| 3586 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3587 | return Failure; |
| 3588 | } |
| 3589 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3590 | assert(M && "Missing module file"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3591 | |
| 3592 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 3593 | // module? |
| 3594 | if (FileName != "-") { |
| 3595 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 3596 | if (CurrentDir.empty()) CurrentDir = "."; |
| 3597 | } |
| 3598 | |
| 3599 | ModuleFile &F = *M; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 3600 | BitstreamCursor &Stream = F.Stream; |
Rafael Espindola | fd83239 | 2014-11-12 14:48:44 +0000 | [diff] [blame] | 3601 | Stream.init(&F.StreamFile); |
Adrian Prantl | cbc368c | 2015-02-25 02:44:04 +0000 | [diff] [blame] | 3602 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
| 3603 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3604 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 3605 | if (!startsWithASTFileMagic(Stream)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3606 | Diag(diag::err_not_a_pch_file) << FileName; |
| 3607 | return Failure; |
| 3608 | } |
| 3609 | |
| 3610 | // This is used for compatibility with older PCH formats. |
| 3611 | bool HaveReadControlBlock = false; |
| 3612 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 3613 | while (1) { |
| 3614 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 3615 | |
| 3616 | switch (Entry.Kind) { |
| 3617 | case llvm::BitstreamEntry::Error: |
| 3618 | case llvm::BitstreamEntry::EndBlock: |
| 3619 | case llvm::BitstreamEntry::Record: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3620 | Error("invalid record at top-level of AST file"); |
| 3621 | return Failure; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 3622 | |
| 3623 | case llvm::BitstreamEntry::SubBlock: |
| 3624 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3625 | } |
| 3626 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3627 | // We only know the control subblock ID. |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 3628 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3629 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
| 3630 | if (Stream.ReadBlockInfoBlock()) { |
| 3631 | Error("malformed BlockInfoBlock in AST file"); |
| 3632 | return Failure; |
| 3633 | } |
| 3634 | break; |
| 3635 | case CONTROL_BLOCK_ID: |
| 3636 | HaveReadControlBlock = true; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 3637 | switch (ReadControlBlock(F, Loaded, ImportedBy, ClientLoadCapabilities)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3638 | case Success: |
| 3639 | break; |
| 3640 | |
| 3641 | case Failure: return Failure; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3642 | case Missing: return Missing; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3643 | case OutOfDate: return OutOfDate; |
| 3644 | case VersionMismatch: return VersionMismatch; |
| 3645 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 3646 | case HadErrors: return HadErrors; |
| 3647 | } |
| 3648 | break; |
| 3649 | case AST_BLOCK_ID: |
| 3650 | if (!HaveReadControlBlock) { |
| 3651 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 3652 | Diag(diag::err_pch_version_too_old); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3653 | return VersionMismatch; |
| 3654 | } |
| 3655 | |
| 3656 | // Record that we've loaded this module. |
| 3657 | Loaded.push_back(ImportedModule(M, ImportedBy, ImportLoc)); |
| 3658 | return Success; |
| 3659 | |
| 3660 | default: |
| 3661 | if (Stream.SkipBlock()) { |
| 3662 | Error("malformed block record in AST file"); |
| 3663 | return Failure; |
| 3664 | } |
| 3665 | break; |
| 3666 | } |
| 3667 | } |
| 3668 | |
| 3669 | return Success; |
| 3670 | } |
| 3671 | |
| 3672 | void ASTReader::InitializeContext() { |
| 3673 | // If there's a listener, notify them that we "read" the translation unit. |
| 3674 | if (DeserializationListener) |
| 3675 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 3676 | Context.getTranslationUnitDecl()); |
| 3677 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3678 | // FIXME: Find a better way to deal with collisions between these |
| 3679 | // built-in types. Right now, we just ignore the problem. |
| 3680 | |
| 3681 | // Load the special types. |
| 3682 | if (SpecialTypes.size() >= NumSpecialTypeIDs) { |
| 3683 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 3684 | if (!Context.CFConstantStringTypeDecl) |
| 3685 | Context.setCFConstantStringType(GetType(String)); |
| 3686 | } |
| 3687 | |
| 3688 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 3689 | QualType FileType = GetType(File); |
| 3690 | if (FileType.isNull()) { |
| 3691 | Error("FILE type is NULL"); |
| 3692 | return; |
| 3693 | } |
| 3694 | |
| 3695 | if (!Context.FILEDecl) { |
| 3696 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 3697 | Context.setFILEDecl(Typedef->getDecl()); |
| 3698 | else { |
| 3699 | const TagType *Tag = FileType->getAs<TagType>(); |
| 3700 | if (!Tag) { |
| 3701 | Error("Invalid FILE type in AST file"); |
| 3702 | return; |
| 3703 | } |
| 3704 | Context.setFILEDecl(Tag->getDecl()); |
| 3705 | } |
| 3706 | } |
| 3707 | } |
| 3708 | |
| 3709 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
| 3710 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 3711 | if (Jmp_bufType.isNull()) { |
| 3712 | Error("jmp_buf type is NULL"); |
| 3713 | return; |
| 3714 | } |
| 3715 | |
| 3716 | if (!Context.jmp_bufDecl) { |
| 3717 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 3718 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 3719 | else { |
| 3720 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 3721 | if (!Tag) { |
| 3722 | Error("Invalid jmp_buf type in AST file"); |
| 3723 | return; |
| 3724 | } |
| 3725 | Context.setjmp_bufDecl(Tag->getDecl()); |
| 3726 | } |
| 3727 | } |
| 3728 | } |
| 3729 | |
| 3730 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
| 3731 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 3732 | if (Sigjmp_bufType.isNull()) { |
| 3733 | Error("sigjmp_buf type is NULL"); |
| 3734 | return; |
| 3735 | } |
| 3736 | |
| 3737 | if (!Context.sigjmp_bufDecl) { |
| 3738 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 3739 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 3740 | else { |
| 3741 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 3742 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 3743 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 3744 | } |
| 3745 | } |
| 3746 | } |
| 3747 | |
| 3748 | if (unsigned ObjCIdRedef |
| 3749 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 3750 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 3751 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 3752 | } |
| 3753 | |
| 3754 | if (unsigned ObjCClassRedef |
| 3755 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 3756 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 3757 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 3758 | } |
| 3759 | |
| 3760 | if (unsigned ObjCSelRedef |
| 3761 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 3762 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 3763 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 3764 | } |
| 3765 | |
| 3766 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 3767 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 3768 | if (Ucontext_tType.isNull()) { |
| 3769 | Error("ucontext_t type is NULL"); |
| 3770 | return; |
| 3771 | } |
| 3772 | |
| 3773 | if (!Context.ucontext_tDecl) { |
| 3774 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| 3775 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 3776 | else { |
| 3777 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| 3778 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 3779 | Context.setucontext_tDecl(Tag->getDecl()); |
| 3780 | } |
| 3781 | } |
| 3782 | } |
| 3783 | } |
| 3784 | |
| 3785 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
| 3786 | |
| 3787 | // If there were any CUDA special declarations, deserialize them. |
| 3788 | if (!CUDASpecialDeclRefs.empty()) { |
| 3789 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 3790 | Context.setcudaConfigureCallDecl( |
| 3791 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 3792 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 3793 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3794 | // Re-export any modules that were imported by a non-module AST file. |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 3795 | // FIXME: This does not make macro-only imports visible again. It also doesn't |
| 3796 | // make #includes mapped to module imports visible. |
| 3797 | for (auto &Import : ImportedModules) { |
| 3798 | if (Module *Imported = getSubmodule(Import.ID)) |
Argyrios Kyrtzidis | 125df05 | 2013-02-01 16:36:12 +0000 | [diff] [blame] | 3799 | makeModuleVisible(Imported, Module::AllVisible, |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 3800 | /*ImportLoc=*/Import.ImportLoc, |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3801 | /*Complain=*/false); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3802 | } |
| 3803 | ImportedModules.clear(); |
| 3804 | } |
| 3805 | |
| 3806 | void ASTReader::finalizeForWriting() { |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 3807 | // Nothing to do for now. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 3810 | /// \brief Given a cursor at the start of an AST file, scan ahead and drop the |
| 3811 | /// cursor into the start of the given block ID, returning false on success and |
| 3812 | /// true on failure. |
| 3813 | static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 3814 | while (1) { |
| 3815 | llvm::BitstreamEntry Entry = Cursor.advance(); |
| 3816 | switch (Entry.Kind) { |
| 3817 | case llvm::BitstreamEntry::Error: |
| 3818 | case llvm::BitstreamEntry::EndBlock: |
| 3819 | return true; |
| 3820 | |
| 3821 | case llvm::BitstreamEntry::Record: |
| 3822 | // Ignore top-level records. |
| 3823 | Cursor.skipRecord(Entry.ID); |
| 3824 | break; |
| 3825 | |
| 3826 | case llvm::BitstreamEntry::SubBlock: |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 3827 | if (Entry.ID == BlockID) { |
| 3828 | if (Cursor.EnterSubBlock(BlockID)) |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 3829 | return true; |
| 3830 | // Found it! |
| 3831 | return false; |
| 3832 | } |
| 3833 | |
| 3834 | if (Cursor.SkipBlock()) |
| 3835 | return true; |
| 3836 | } |
| 3837 | } |
| 3838 | } |
| 3839 | |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 3840 | /// \brief Reads and return the signature record from \p StreamFile's control |
| 3841 | /// block, or else returns 0. |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 3842 | static ASTFileSignature readASTFileSignature(llvm::BitstreamReader &StreamFile){ |
| 3843 | BitstreamCursor Stream(StreamFile); |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 3844 | if (!startsWithASTFileMagic(Stream)) |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 3845 | return 0; |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 3846 | |
| 3847 | // Scan for the CONTROL_BLOCK_ID block. |
| 3848 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) |
| 3849 | return 0; |
| 3850 | |
| 3851 | // Scan for SIGNATURE inside the control block. |
| 3852 | ASTReader::RecordData Record; |
| 3853 | while (1) { |
| 3854 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
| 3855 | if (Entry.Kind == llvm::BitstreamEntry::EndBlock || |
| 3856 | Entry.Kind != llvm::BitstreamEntry::Record) |
| 3857 | return 0; |
| 3858 | |
| 3859 | Record.clear(); |
| 3860 | StringRef Blob; |
| 3861 | if (SIGNATURE == Stream.readRecord(Entry.ID, Record, &Blob)) |
| 3862 | return Record[0]; |
| 3863 | } |
| 3864 | } |
| 3865 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3866 | /// \brief Retrieve the name of the original source file name |
| 3867 | /// directly from the AST file, without actually loading the AST |
| 3868 | /// file. |
| 3869 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
| 3870 | FileManager &FileMgr, |
| 3871 | DiagnosticsEngine &Diags) { |
| 3872 | // Open the AST file. |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 3873 | auto Buffer = FileMgr.getBufferForFile(ASTFileName); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3874 | if (!Buffer) { |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 3875 | Diags.Report(diag::err_fe_unable_to_read_pch_file) |
| 3876 | << ASTFileName << Buffer.getError().message(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3877 | return std::string(); |
| 3878 | } |
| 3879 | |
| 3880 | // Initialize the stream |
| 3881 | llvm::BitstreamReader StreamFile; |
Adrian Prantl | cbc368c | 2015-02-25 02:44:04 +0000 | [diff] [blame] | 3882 | StreamFile.init((const unsigned char *)(*Buffer)->getBufferStart(), |
| 3883 | (const unsigned char *)(*Buffer)->getBufferEnd()); |
Rafael Espindola | af0e40a | 2014-11-12 14:42:25 +0000 | [diff] [blame] | 3884 | BitstreamCursor Stream(StreamFile); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3885 | |
| 3886 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 3887 | if (!startsWithASTFileMagic(Stream)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3888 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
| 3889 | return std::string(); |
| 3890 | } |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 3891 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 3892 | // Scan for the CONTROL_BLOCK_ID block. |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 3893 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 3894 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| 3895 | return std::string(); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 3896 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3897 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 3898 | // Scan for ORIGINAL_FILE inside the control block. |
| 3899 | RecordData Record; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 3900 | while (1) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 3901 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 3902 | if (Entry.Kind == llvm::BitstreamEntry::EndBlock) |
| 3903 | return std::string(); |
| 3904 | |
| 3905 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 3906 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| 3907 | return std::string(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3908 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 3909 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3910 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3911 | StringRef Blob; |
| 3912 | if (Stream.readRecord(Entry.ID, Record, &Blob) == ORIGINAL_FILE) |
| 3913 | return Blob.str(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3914 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | namespace { |
| 3918 | class SimplePCHValidator : public ASTReaderListener { |
| 3919 | const LangOptions &ExistingLangOpts; |
| 3920 | const TargetOptions &ExistingTargetOpts; |
| 3921 | const PreprocessorOptions &ExistingPPOpts; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 3922 | std::string ExistingModuleCachePath; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3923 | FileManager &FileMgr; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 3924 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3925 | public: |
| 3926 | SimplePCHValidator(const LangOptions &ExistingLangOpts, |
| 3927 | const TargetOptions &ExistingTargetOpts, |
| 3928 | const PreprocessorOptions &ExistingPPOpts, |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 3929 | StringRef ExistingModuleCachePath, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3930 | FileManager &FileMgr) |
| 3931 | : ExistingLangOpts(ExistingLangOpts), |
| 3932 | ExistingTargetOpts(ExistingTargetOpts), |
| 3933 | ExistingPPOpts(ExistingPPOpts), |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 3934 | ExistingModuleCachePath(ExistingModuleCachePath), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3935 | FileMgr(FileMgr) |
| 3936 | { |
| 3937 | } |
| 3938 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 3939 | bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, |
| 3940 | bool AllowCompatibleDifferences) override { |
| 3941 | return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr, |
| 3942 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3943 | } |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 3944 | bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, |
| 3945 | bool AllowCompatibleDifferences) override { |
| 3946 | return checkTargetOptions(ExistingTargetOpts, TargetOpts, nullptr, |
| 3947 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3948 | } |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 3949 | bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 3950 | StringRef SpecificModuleCachePath, |
| 3951 | bool Complain) override { |
| 3952 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 3953 | ExistingModuleCachePath, |
| 3954 | nullptr, ExistingLangOpts); |
| 3955 | } |
Craig Topper | 3e89dfe | 2014-03-13 02:13:41 +0000 | [diff] [blame] | 3956 | bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 3957 | bool Complain, |
| 3958 | std::string &SuggestedPredefines) override { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3959 | return checkPreprocessorOptions(ExistingPPOpts, PPOpts, nullptr, FileMgr, |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 3960 | SuggestedPredefines, ExistingLangOpts); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3961 | } |
| 3962 | }; |
| 3963 | } |
| 3964 | |
| 3965 | bool ASTReader::readASTFileControlBlock(StringRef Filename, |
| 3966 | FileManager &FileMgr, |
| 3967 | ASTReaderListener &Listener) { |
| 3968 | // Open the AST file. |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 3969 | // FIXME: This allows use of the VFS; we do not allow use of the |
| 3970 | // VFS when actually loading a module. |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 3971 | auto Buffer = FileMgr.getBufferForFile(Filename); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3972 | if (!Buffer) { |
| 3973 | return true; |
| 3974 | } |
| 3975 | |
| 3976 | // Initialize the stream |
| 3977 | llvm::BitstreamReader StreamFile; |
Adrian Prantl | cbc368c | 2015-02-25 02:44:04 +0000 | [diff] [blame] | 3978 | StreamFile.init((const unsigned char *)(*Buffer)->getBufferStart(), |
| 3979 | (const unsigned char *)(*Buffer)->getBufferEnd()); |
Rafael Espindola | af0e40a | 2014-11-12 14:42:25 +0000 | [diff] [blame] | 3980 | BitstreamCursor Stream(StreamFile); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3981 | |
| 3982 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 3983 | if (!startsWithASTFileMagic(Stream)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3984 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3985 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 3986 | // Scan for the CONTROL_BLOCK_ID block. |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 3987 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 3988 | return true; |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 3989 | |
| 3990 | bool NeedsInputFiles = Listener.needsInputFileVisitation(); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 3991 | bool NeedsSystemInputFiles = Listener.needsSystemInputFileVisitation(); |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 3992 | bool NeedsImports = Listener.needsImportVisitation(); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 3993 | BitstreamCursor InputFilesCursor; |
| 3994 | if (NeedsInputFiles) { |
| 3995 | InputFilesCursor = Stream; |
| 3996 | if (SkipCursorToBlock(InputFilesCursor, INPUT_FILES_BLOCK_ID)) |
| 3997 | return true; |
| 3998 | |
| 3999 | // Read the abbreviations |
| 4000 | while (true) { |
| 4001 | uint64_t Offset = InputFilesCursor.GetCurrentBitNo(); |
| 4002 | unsigned Code = InputFilesCursor.ReadCode(); |
| 4003 | |
| 4004 | // We expect all abbrevs to be at the start of the block. |
| 4005 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 4006 | InputFilesCursor.JumpToBit(Offset); |
| 4007 | break; |
| 4008 | } |
| 4009 | InputFilesCursor.ReadAbbrevRecord(); |
| 4010 | } |
| 4011 | } |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4012 | |
| 4013 | // Scan for ORIGINAL_FILE inside the control block. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4014 | RecordData Record; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4015 | std::string ModuleDir; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4016 | while (1) { |
| 4017 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
| 4018 | if (Entry.Kind == llvm::BitstreamEntry::EndBlock) |
| 4019 | return false; |
| 4020 | |
| 4021 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
| 4022 | return true; |
| 4023 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4024 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4025 | StringRef Blob; |
| 4026 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4027 | switch ((ControlRecordTypes)RecCode) { |
| 4028 | case METADATA: { |
| 4029 | if (Record[0] != VERSION_MAJOR) |
| 4030 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4031 | |
Douglas Gregor | bf7fc9c | 2013-03-27 16:47:18 +0000 | [diff] [blame] | 4032 | if (Listener.ReadFullVersionInformation(Blob)) |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4033 | return true; |
Douglas Gregor | bf7fc9c | 2013-03-27 16:47:18 +0000 | [diff] [blame] | 4034 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4035 | break; |
| 4036 | } |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 4037 | case MODULE_NAME: |
| 4038 | Listener.ReadModuleName(Blob); |
| 4039 | break; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4040 | case MODULE_DIRECTORY: |
| 4041 | ModuleDir = Blob; |
| 4042 | break; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 4043 | case MODULE_MAP_FILE: { |
| 4044 | unsigned Idx = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4045 | auto Path = ReadString(Record, Idx); |
| 4046 | ResolveImportedPath(Path, ModuleDir); |
| 4047 | Listener.ReadModuleMapFile(Path); |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 4048 | break; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 4049 | } |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4050 | case LANGUAGE_OPTIONS: |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 4051 | if (ParseLanguageOptions(Record, false, Listener, |
| 4052 | /*AllowCompatibleConfigurationMismatch*/false)) |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4053 | return true; |
| 4054 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4055 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4056 | case TARGET_OPTIONS: |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 4057 | if (ParseTargetOptions(Record, false, Listener, |
| 4058 | /*AllowCompatibleConfigurationMismatch*/ false)) |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4059 | return true; |
| 4060 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4061 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4062 | case DIAGNOSTIC_OPTIONS: |
| 4063 | if (ParseDiagnosticOptions(Record, false, Listener)) |
| 4064 | return true; |
| 4065 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4066 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4067 | case FILE_SYSTEM_OPTIONS: |
| 4068 | if (ParseFileSystemOptions(Record, false, Listener)) |
| 4069 | return true; |
| 4070 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4071 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4072 | case HEADER_SEARCH_OPTIONS: |
| 4073 | if (ParseHeaderSearchOptions(Record, false, Listener)) |
| 4074 | return true; |
| 4075 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4076 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4077 | case PREPROCESSOR_OPTIONS: { |
| 4078 | std::string IgnoredSuggestedPredefines; |
| 4079 | if (ParsePreprocessorOptions(Record, false, Listener, |
| 4080 | IgnoredSuggestedPredefines)) |
| 4081 | return true; |
| 4082 | break; |
| 4083 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4084 | |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4085 | case INPUT_FILE_OFFSETS: { |
| 4086 | if (!NeedsInputFiles) |
| 4087 | break; |
| 4088 | |
| 4089 | unsigned NumInputFiles = Record[0]; |
| 4090 | unsigned NumUserFiles = Record[1]; |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 4091 | const uint64_t *InputFileOffs = (const uint64_t *)Blob.data(); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4092 | for (unsigned I = 0; I != NumInputFiles; ++I) { |
| 4093 | // Go find this input file. |
| 4094 | bool isSystemFile = I >= NumUserFiles; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 4095 | |
| 4096 | if (isSystemFile && !NeedsSystemInputFiles) |
| 4097 | break; // the rest are system input files |
| 4098 | |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4099 | BitstreamCursor &Cursor = InputFilesCursor; |
| 4100 | SavedStreamPosition SavedPosition(Cursor); |
| 4101 | Cursor.JumpToBit(InputFileOffs[I]); |
| 4102 | |
| 4103 | unsigned Code = Cursor.ReadCode(); |
| 4104 | RecordData Record; |
| 4105 | StringRef Blob; |
| 4106 | bool shouldContinue = false; |
| 4107 | switch ((InputFileRecordTypes)Cursor.readRecord(Code, Record, &Blob)) { |
| 4108 | case INPUT_FILE: |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 4109 | bool Overridden = static_cast<bool>(Record[3]); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4110 | std::string Filename = Blob; |
| 4111 | ResolveImportedPath(Filename, ModuleDir); |
| 4112 | shouldContinue = |
| 4113 | Listener.visitInputFile(Filename, isSystemFile, Overridden); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4114 | break; |
| 4115 | } |
| 4116 | if (!shouldContinue) |
| 4117 | break; |
| 4118 | } |
| 4119 | break; |
| 4120 | } |
| 4121 | |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4122 | case IMPORTS: { |
| 4123 | if (!NeedsImports) |
| 4124 | break; |
| 4125 | |
| 4126 | unsigned Idx = 0, N = Record.size(); |
| 4127 | while (Idx < N) { |
| 4128 | // Read information about the AST file. |
Richard Smith | 79c98cc | 2014-10-27 23:25:15 +0000 | [diff] [blame] | 4129 | Idx += 5; // ImportLoc, Size, ModTime, Signature |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4130 | std::string Filename = ReadString(Record, Idx); |
| 4131 | ResolveImportedPath(Filename, ModuleDir); |
| 4132 | Listener.visitImport(Filename); |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4133 | } |
| 4134 | break; |
| 4135 | } |
| 4136 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 4137 | case KNOWN_MODULE_FILES: { |
| 4138 | // Known-but-not-technically-used module files are treated as imports. |
| 4139 | if (!NeedsImports) |
| 4140 | break; |
| 4141 | |
| 4142 | unsigned Idx = 0, N = Record.size(); |
| 4143 | while (Idx < N) { |
| 4144 | std::string Filename = ReadString(Record, Idx); |
| 4145 | ResolveImportedPath(Filename, ModuleDir); |
| 4146 | Listener.visitImport(Filename); |
| 4147 | } |
| 4148 | break; |
| 4149 | } |
| 4150 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4151 | default: |
| 4152 | // No other validation to perform. |
| 4153 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4154 | } |
| 4155 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | |
| 4159 | bool ASTReader::isAcceptableASTFile(StringRef Filename, |
| 4160 | FileManager &FileMgr, |
| 4161 | const LangOptions &LangOpts, |
| 4162 | const TargetOptions &TargetOpts, |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4163 | const PreprocessorOptions &PPOpts, |
| 4164 | std::string ExistingModuleCachePath) { |
| 4165 | SimplePCHValidator validator(LangOpts, TargetOpts, PPOpts, |
| 4166 | ExistingModuleCachePath, FileMgr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4167 | return !readASTFileControlBlock(Filename, FileMgr, validator); |
| 4168 | } |
| 4169 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4170 | ASTReader::ASTReadResult |
| 4171 | ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4172 | // Enter the submodule block. |
| 4173 | if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) { |
| 4174 | Error("malformed submodule block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4175 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4176 | } |
| 4177 | |
| 4178 | ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); |
| 4179 | bool First = true; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4180 | Module *CurrentModule = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4181 | RecordData Record; |
| 4182 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4183 | llvm::BitstreamEntry Entry = F.Stream.advanceSkippingSubblocks(); |
| 4184 | |
| 4185 | switch (Entry.Kind) { |
| 4186 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 4187 | case llvm::BitstreamEntry::Error: |
| 4188 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4189 | return Failure; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4190 | case llvm::BitstreamEntry::EndBlock: |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4191 | return Success; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4192 | case llvm::BitstreamEntry::Record: |
| 4193 | // The interesting case. |
| 4194 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4195 | } |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4196 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4197 | // Read a record. |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4198 | StringRef Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4199 | Record.clear(); |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4200 | auto Kind = F.Stream.readRecord(Entry.ID, Record, &Blob); |
| 4201 | |
| 4202 | if ((Kind == SUBMODULE_METADATA) != First) { |
| 4203 | Error("submodule metadata record should be at beginning of block"); |
| 4204 | return Failure; |
| 4205 | } |
| 4206 | First = false; |
| 4207 | |
| 4208 | // Submodule information is only valid if we have a current module. |
| 4209 | // FIXME: Should we error on these cases? |
| 4210 | if (!CurrentModule && Kind != SUBMODULE_METADATA && |
| 4211 | Kind != SUBMODULE_DEFINITION) |
| 4212 | continue; |
| 4213 | |
| 4214 | switch (Kind) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4215 | default: // Default behavior: ignore. |
| 4216 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4217 | |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4218 | case SUBMODULE_DEFINITION: { |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4219 | if (Record.size() < 8) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4220 | Error("malformed module definition"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4221 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4222 | } |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4223 | |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4224 | StringRef Name = Blob; |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 4225 | unsigned Idx = 0; |
| 4226 | SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]); |
| 4227 | SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]); |
| 4228 | bool IsFramework = Record[Idx++]; |
| 4229 | bool IsExplicit = Record[Idx++]; |
| 4230 | bool IsSystem = Record[Idx++]; |
| 4231 | bool IsExternC = Record[Idx++]; |
| 4232 | bool InferSubmodules = Record[Idx++]; |
| 4233 | bool InferExplicitSubmodules = Record[Idx++]; |
| 4234 | bool InferExportWildcard = Record[Idx++]; |
| 4235 | bool ConfigMacrosExhaustive = Record[Idx++]; |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4236 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4237 | Module *ParentModule = nullptr; |
Ben Langmuir | 9d6448b | 2014-08-09 00:57:23 +0000 | [diff] [blame] | 4238 | if (Parent) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4239 | ParentModule = getSubmodule(Parent); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4240 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4241 | // Retrieve this (sub)module from the module map, creating it if |
| 4242 | // necessary. |
Ben Langmuir | 9d6448b | 2014-08-09 00:57:23 +0000 | [diff] [blame] | 4243 | CurrentModule = ModMap.findOrCreateModule(Name, ParentModule, IsFramework, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4244 | IsExplicit).first; |
Ben Langmuir | 9d6448b | 2014-08-09 00:57:23 +0000 | [diff] [blame] | 4245 | |
| 4246 | // FIXME: set the definition loc for CurrentModule, or call |
| 4247 | // ModMap.setInferredModuleAllowedBy() |
| 4248 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4249 | SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS; |
| 4250 | if (GlobalIndex >= SubmodulesLoaded.size() || |
| 4251 | SubmodulesLoaded[GlobalIndex]) { |
| 4252 | Error("too many submodules"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4253 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4254 | } |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4255 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4256 | if (!ParentModule) { |
| 4257 | if (const FileEntry *CurFile = CurrentModule->getASTFile()) { |
| 4258 | if (CurFile != F.File) { |
| 4259 | if (!Diags.isDiagnosticInFlight()) { |
| 4260 | Diag(diag::err_module_file_conflict) |
| 4261 | << CurrentModule->getTopLevelModuleName() |
| 4262 | << CurFile->getName() |
| 4263 | << F.File->getName(); |
| 4264 | } |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4265 | return Failure; |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4266 | } |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4267 | } |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4268 | |
| 4269 | CurrentModule->setASTFile(F.File); |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4270 | } |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4271 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4272 | CurrentModule->IsFromModuleFile = true; |
| 4273 | CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 4274 | CurrentModule->IsExternC = IsExternC; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4275 | CurrentModule->InferSubmodules = InferSubmodules; |
| 4276 | CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; |
| 4277 | CurrentModule->InferExportWildcard = InferExportWildcard; |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4278 | CurrentModule->ConfigMacrosExhaustive = ConfigMacrosExhaustive; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4279 | if (DeserializationListener) |
| 4280 | DeserializationListener->ModuleRead(GlobalID, CurrentModule); |
| 4281 | |
| 4282 | SubmodulesLoaded[GlobalIndex] = CurrentModule; |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 4283 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4284 | // Clear out data that will be replaced by what is the module file. |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 4285 | CurrentModule->LinkLibraries.clear(); |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4286 | CurrentModule->ConfigMacros.clear(); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4287 | CurrentModule->UnresolvedConflicts.clear(); |
| 4288 | CurrentModule->Conflicts.clear(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4289 | break; |
| 4290 | } |
| 4291 | |
| 4292 | case SUBMODULE_UMBRELLA_HEADER: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4293 | if (const FileEntry *Umbrella = PP.getFileManager().getFile(Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4294 | if (!CurrentModule->getUmbrellaHeader()) |
| 4295 | ModMap.setUmbrellaHeader(CurrentModule, Umbrella); |
| 4296 | else if (CurrentModule->getUmbrellaHeader() != Umbrella) { |
Ben Langmuir | bc35fbe | 2015-02-20 21:46:39 +0000 | [diff] [blame] | 4297 | // This can be a spurious difference caused by changing the VFS to |
| 4298 | // point to a different copy of the file, and it is too late to |
| 4299 | // to rebuild safely. |
| 4300 | // FIXME: If we wrote the virtual paths instead of the 'real' paths, |
| 4301 | // after input file validation only real problems would remain and we |
| 4302 | // could just error. For now, assume it's okay. |
| 4303 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4304 | } |
| 4305 | } |
| 4306 | break; |
| 4307 | } |
| 4308 | |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 4309 | case SUBMODULE_HEADER: |
| 4310 | case SUBMODULE_EXCLUDED_HEADER: |
| 4311 | case SUBMODULE_PRIVATE_HEADER: |
| 4312 | // We lazily associate headers with their modules via the HeaderInfo table. |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 4313 | // FIXME: Re-evaluate this section; maybe only store InputFile IDs instead |
| 4314 | // of complete filenames or remove it entirely. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 4315 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4316 | |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 4317 | case SUBMODULE_TEXTUAL_HEADER: |
| 4318 | case SUBMODULE_PRIVATE_TEXTUAL_HEADER: |
| 4319 | // FIXME: Textual headers are not marked in the HeaderInfo table. Load |
| 4320 | // them here. |
| 4321 | break; |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 4322 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4323 | case SUBMODULE_TOPHEADER: { |
Argyrios Kyrtzidis | 3c5305c | 2013-03-13 21:13:43 +0000 | [diff] [blame] | 4324 | CurrentModule->addTopHeaderFilename(Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4325 | break; |
| 4326 | } |
| 4327 | |
| 4328 | case SUBMODULE_UMBRELLA_DIR: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4329 | if (const DirectoryEntry *Umbrella |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4330 | = PP.getFileManager().getDirectory(Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4331 | if (!CurrentModule->getUmbrellaDir()) |
| 4332 | ModMap.setUmbrellaDir(CurrentModule, Umbrella); |
| 4333 | else if (CurrentModule->getUmbrellaDir() != Umbrella) { |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4334 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 4335 | Error("mismatched umbrella directories in submodule"); |
| 4336 | return OutOfDate; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4337 | } |
| 4338 | } |
| 4339 | break; |
| 4340 | } |
| 4341 | |
| 4342 | case SUBMODULE_METADATA: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4343 | F.BaseSubmoduleID = getTotalNumSubmodules(); |
| 4344 | F.LocalNumSubmodules = Record[0]; |
| 4345 | unsigned LocalBaseSubmoduleID = Record[1]; |
| 4346 | if (F.LocalNumSubmodules > 0) { |
| 4347 | // Introduce the global -> local mapping for submodules within this |
| 4348 | // module. |
| 4349 | GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F)); |
| 4350 | |
| 4351 | // Introduce the local -> global mapping for submodules within this |
| 4352 | // module. |
| 4353 | F.SubmoduleRemap.insertOrReplace( |
| 4354 | std::make_pair(LocalBaseSubmoduleID, |
| 4355 | F.BaseSubmoduleID - LocalBaseSubmoduleID)); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4356 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 4357 | SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules); |
| 4358 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4359 | break; |
| 4360 | } |
| 4361 | |
| 4362 | case SUBMODULE_IMPORTS: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4363 | for (unsigned Idx = 0; Idx != Record.size(); ++Idx) { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4364 | UnresolvedModuleRef Unresolved; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4365 | Unresolved.File = &F; |
| 4366 | Unresolved.Mod = CurrentModule; |
| 4367 | Unresolved.ID = Record[Idx]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4368 | Unresolved.Kind = UnresolvedModuleRef::Import; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4369 | Unresolved.IsWildcard = false; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4370 | UnresolvedModuleRefs.push_back(Unresolved); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4371 | } |
| 4372 | break; |
| 4373 | } |
| 4374 | |
| 4375 | case SUBMODULE_EXPORTS: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4376 | for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4377 | UnresolvedModuleRef Unresolved; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4378 | Unresolved.File = &F; |
| 4379 | Unresolved.Mod = CurrentModule; |
| 4380 | Unresolved.ID = Record[Idx]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4381 | Unresolved.Kind = UnresolvedModuleRef::Export; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4382 | Unresolved.IsWildcard = Record[Idx + 1]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4383 | UnresolvedModuleRefs.push_back(Unresolved); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4384 | } |
| 4385 | |
| 4386 | // Once we've loaded the set of exports, there's no reason to keep |
| 4387 | // the parsed, unresolved exports around. |
| 4388 | CurrentModule->UnresolvedExports.clear(); |
| 4389 | break; |
| 4390 | } |
| 4391 | case SUBMODULE_REQUIRES: { |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 4392 | CurrentModule->addRequirement(Blob, Record[0], Context.getLangOpts(), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4393 | Context.getTargetInfo()); |
| 4394 | break; |
| 4395 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 4396 | |
| 4397 | case SUBMODULE_LINK_LIBRARY: |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 4398 | CurrentModule->LinkLibraries.push_back( |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4399 | Module::LinkLibrary(Blob, Record[0])); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 4400 | break; |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 4401 | |
| 4402 | case SUBMODULE_CONFIG_MACRO: |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 4403 | CurrentModule->ConfigMacros.push_back(Blob.str()); |
| 4404 | break; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4405 | |
| 4406 | case SUBMODULE_CONFLICT: { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4407 | UnresolvedModuleRef Unresolved; |
| 4408 | Unresolved.File = &F; |
| 4409 | Unresolved.Mod = CurrentModule; |
| 4410 | Unresolved.ID = Record[0]; |
| 4411 | Unresolved.Kind = UnresolvedModuleRef::Conflict; |
| 4412 | Unresolved.IsWildcard = false; |
| 4413 | Unresolved.String = Blob; |
| 4414 | UnresolvedModuleRefs.push_back(Unresolved); |
| 4415 | break; |
| 4416 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4417 | } |
| 4418 | } |
| 4419 | } |
| 4420 | |
| 4421 | /// \brief Parse the record that corresponds to a LangOptions data |
| 4422 | /// structure. |
| 4423 | /// |
| 4424 | /// This routine parses the language options from the AST file and then gives |
| 4425 | /// them to the AST listener if one is set. |
| 4426 | /// |
| 4427 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
| 4428 | bool ASTReader::ParseLanguageOptions(const RecordData &Record, |
| 4429 | bool Complain, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 4430 | ASTReaderListener &Listener, |
| 4431 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4432 | LangOptions LangOpts; |
| 4433 | unsigned Idx = 0; |
| 4434 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 4435 | LangOpts.Name = Record[Idx++]; |
| 4436 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 4437 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 4438 | #include "clang/Basic/LangOptions.def" |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 4439 | #define SANITIZER(NAME, ID) \ |
| 4440 | LangOpts.Sanitize.set(SanitizerKind::ID, Record[Idx++]); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 4441 | #include "clang/Basic/Sanitizers.def" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4442 | |
| 4443 | ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++]; |
| 4444 | VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx); |
| 4445 | LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion); |
| 4446 | |
| 4447 | unsigned Length = Record[Idx++]; |
| 4448 | LangOpts.CurrentModule.assign(Record.begin() + Idx, |
| 4449 | Record.begin() + Idx + Length); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 4450 | |
| 4451 | Idx += Length; |
| 4452 | |
| 4453 | // Comment options. |
| 4454 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4455 | LangOpts.CommentOpts.BlockCommandNames.push_back( |
| 4456 | ReadString(Record, Idx)); |
| 4457 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 4458 | LangOpts.CommentOpts.ParseAllComments = Record[Idx++]; |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 4459 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 4460 | return Listener.ReadLanguageOptions(LangOpts, Complain, |
| 4461 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 4464 | bool ASTReader::ParseTargetOptions(const RecordData &Record, bool Complain, |
| 4465 | ASTReaderListener &Listener, |
| 4466 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4467 | unsigned Idx = 0; |
| 4468 | TargetOptions TargetOpts; |
| 4469 | TargetOpts.Triple = ReadString(Record, Idx); |
| 4470 | TargetOpts.CPU = ReadString(Record, Idx); |
| 4471 | TargetOpts.ABI = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4472 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4473 | TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx)); |
| 4474 | } |
| 4475 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4476 | TargetOpts.Features.push_back(ReadString(Record, Idx)); |
| 4477 | } |
| 4478 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 4479 | return Listener.ReadTargetOptions(TargetOpts, Complain, |
| 4480 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4481 | } |
| 4482 | |
| 4483 | bool ASTReader::ParseDiagnosticOptions(const RecordData &Record, bool Complain, |
| 4484 | ASTReaderListener &Listener) { |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 4485 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4486 | unsigned Idx = 0; |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 4487 | #define DIAGOPT(Name, Bits, Default) DiagOpts->Name = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4488 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 4489 | DiagOpts->set##Name(static_cast<Type>(Record[Idx++])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4490 | #include "clang/Basic/DiagnosticOptions.def" |
| 4491 | |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 4492 | for (unsigned N = Record[Idx++]; N; --N) |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 4493 | DiagOpts->Warnings.push_back(ReadString(Record, Idx)); |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 4494 | for (unsigned N = Record[Idx++]; N; --N) |
| 4495 | DiagOpts->Remarks.push_back(ReadString(Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4496 | |
| 4497 | return Listener.ReadDiagnosticOptions(DiagOpts, Complain); |
| 4498 | } |
| 4499 | |
| 4500 | bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain, |
| 4501 | ASTReaderListener &Listener) { |
| 4502 | FileSystemOptions FSOpts; |
| 4503 | unsigned Idx = 0; |
| 4504 | FSOpts.WorkingDir = ReadString(Record, Idx); |
| 4505 | return Listener.ReadFileSystemOptions(FSOpts, Complain); |
| 4506 | } |
| 4507 | |
| 4508 | bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record, |
| 4509 | bool Complain, |
| 4510 | ASTReaderListener &Listener) { |
| 4511 | HeaderSearchOptions HSOpts; |
| 4512 | unsigned Idx = 0; |
| 4513 | HSOpts.Sysroot = ReadString(Record, Idx); |
| 4514 | |
| 4515 | // Include entries. |
| 4516 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4517 | std::string Path = ReadString(Record, Idx); |
| 4518 | frontend::IncludeDirGroup Group |
| 4519 | = static_cast<frontend::IncludeDirGroup>(Record[Idx++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4520 | bool IsFramework = Record[Idx++]; |
| 4521 | bool IgnoreSysRoot = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4522 | HSOpts.UserEntries.push_back( |
Daniel Dunbar | 5368173 | 2013-01-30 00:34:26 +0000 | [diff] [blame] | 4523 | HeaderSearchOptions::Entry(Path, Group, IsFramework, IgnoreSysRoot)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4524 | } |
| 4525 | |
| 4526 | // System header prefixes. |
| 4527 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4528 | std::string Prefix = ReadString(Record, Idx); |
| 4529 | bool IsSystemHeader = Record[Idx++]; |
| 4530 | HSOpts.SystemHeaderPrefixes.push_back( |
| 4531 | HeaderSearchOptions::SystemHeaderPrefix(Prefix, IsSystemHeader)); |
| 4532 | } |
| 4533 | |
| 4534 | HSOpts.ResourceDir = ReadString(Record, Idx); |
| 4535 | HSOpts.ModuleCachePath = ReadString(Record, Idx); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 4536 | HSOpts.ModuleUserBuildPath = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4537 | HSOpts.DisableModuleHash = Record[Idx++]; |
| 4538 | HSOpts.UseBuiltinIncludes = Record[Idx++]; |
| 4539 | HSOpts.UseStandardSystemIncludes = Record[Idx++]; |
| 4540 | HSOpts.UseStandardCXXIncludes = Record[Idx++]; |
| 4541 | HSOpts.UseLibcxx = Record[Idx++]; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4542 | std::string SpecificModuleCachePath = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4543 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4544 | return Listener.ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 4545 | Complain); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4546 | } |
| 4547 | |
| 4548 | bool ASTReader::ParsePreprocessorOptions(const RecordData &Record, |
| 4549 | bool Complain, |
| 4550 | ASTReaderListener &Listener, |
| 4551 | std::string &SuggestedPredefines) { |
| 4552 | PreprocessorOptions PPOpts; |
| 4553 | unsigned Idx = 0; |
| 4554 | |
| 4555 | // Macro definitions/undefs |
| 4556 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4557 | std::string Macro = ReadString(Record, Idx); |
| 4558 | bool IsUndef = Record[Idx++]; |
| 4559 | PPOpts.Macros.push_back(std::make_pair(Macro, IsUndef)); |
| 4560 | } |
| 4561 | |
| 4562 | // Includes |
| 4563 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4564 | PPOpts.Includes.push_back(ReadString(Record, Idx)); |
| 4565 | } |
| 4566 | |
| 4567 | // Macro Includes |
| 4568 | for (unsigned N = Record[Idx++]; N; --N) { |
| 4569 | PPOpts.MacroIncludes.push_back(ReadString(Record, Idx)); |
| 4570 | } |
| 4571 | |
| 4572 | PPOpts.UsePredefines = Record[Idx++]; |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 4573 | PPOpts.DetailedRecord = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4574 | PPOpts.ImplicitPCHInclude = ReadString(Record, Idx); |
| 4575 | PPOpts.ImplicitPTHInclude = ReadString(Record, Idx); |
| 4576 | PPOpts.ObjCXXARCStandardLibrary = |
| 4577 | static_cast<ObjCXXARCStandardLibraryKind>(Record[Idx++]); |
| 4578 | SuggestedPredefines.clear(); |
| 4579 | return Listener.ReadPreprocessorOptions(PPOpts, Complain, |
| 4580 | SuggestedPredefines); |
| 4581 | } |
| 4582 | |
| 4583 | std::pair<ModuleFile *, unsigned> |
| 4584 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
| 4585 | GlobalPreprocessedEntityMapType::iterator |
| 4586 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
| 4587 | assert(I != GlobalPreprocessedEntityMap.end() && |
| 4588 | "Corrupted global preprocessed entity map"); |
| 4589 | ModuleFile *M = I->second; |
| 4590 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 4591 | return std::make_pair(M, LocalIndex); |
| 4592 | } |
| 4593 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 4594 | llvm::iterator_range<PreprocessingRecord::iterator> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4595 | ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const { |
| 4596 | if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord()) |
| 4597 | return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID, |
| 4598 | Mod.NumPreprocessedEntities); |
| 4599 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 4600 | return llvm::make_range(PreprocessingRecord::iterator(), |
| 4601 | PreprocessingRecord::iterator()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4602 | } |
| 4603 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 4604 | llvm::iterator_range<ASTReader::ModuleDeclIterator> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4605 | ASTReader::getModuleFileLevelDecls(ModuleFile &Mod) { |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 4606 | return llvm::make_range( |
| 4607 | ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls), |
| 4608 | ModuleDeclIterator(this, &Mod, |
| 4609 | Mod.FileSortedDecls + Mod.NumFileSortedDecls)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 4613 | PreprocessedEntityID PPID = Index+1; |
| 4614 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 4615 | ModuleFile &M = *PPInfo.first; |
| 4616 | unsigned LocalIndex = PPInfo.second; |
| 4617 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 4618 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4619 | if (!PP.getPreprocessingRecord()) { |
| 4620 | Error("no preprocessing record"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4621 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4622 | } |
| 4623 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4624 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
| 4625 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
| 4626 | |
| 4627 | llvm::BitstreamEntry Entry = |
| 4628 | M.PreprocessorDetailCursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 4629 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4630 | return nullptr; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4631 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4632 | // Read the record. |
| 4633 | SourceRange Range(ReadSourceLocation(M, PPOffs.Begin), |
| 4634 | ReadSourceLocation(M, PPOffs.End)); |
| 4635 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4636 | StringRef Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4637 | RecordData Record; |
| 4638 | PreprocessorDetailRecordTypes RecType = |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4639 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.readRecord( |
| 4640 | Entry.ID, Record, &Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4641 | switch (RecType) { |
| 4642 | case PPD_MACRO_EXPANSION: { |
| 4643 | bool isBuiltin = Record[0]; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4644 | IdentifierInfo *Name = nullptr; |
| 4645 | MacroDefinition *Def = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4646 | if (isBuiltin) |
| 4647 | Name = getLocalIdentifier(M, Record[1]); |
| 4648 | else { |
| 4649 | PreprocessedEntityID |
| 4650 | GlobalID = getGlobalPreprocessedEntityID(M, Record[1]); |
| 4651 | Def =cast<MacroDefinition>(PPRec.getLoadedPreprocessedEntity(GlobalID-1)); |
| 4652 | } |
| 4653 | |
| 4654 | MacroExpansion *ME; |
| 4655 | if (isBuiltin) |
| 4656 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 4657 | else |
| 4658 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 4659 | |
| 4660 | return ME; |
| 4661 | } |
| 4662 | |
| 4663 | case PPD_MACRO_DEFINITION: { |
| 4664 | // Decode the identifier info and then check again; if the macro is |
| 4665 | // still defined and associated with the identifier, |
| 4666 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
| 4667 | MacroDefinition *MD |
| 4668 | = new (PPRec) MacroDefinition(II, Range); |
| 4669 | |
| 4670 | if (DeserializationListener) |
| 4671 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 4672 | |
| 4673 | return MD; |
| 4674 | } |
| 4675 | |
| 4676 | case PPD_INCLUSION_DIRECTIVE: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4677 | const char *FullFileNameStart = Blob.data() + Record[0]; |
| 4678 | StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4679 | const FileEntry *File = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4680 | if (!FullFileName.empty()) |
| 4681 | File = PP.getFileManager().getFile(FullFileName); |
| 4682 | |
| 4683 | // FIXME: Stable encoding |
| 4684 | InclusionDirective::InclusionKind Kind |
| 4685 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
| 4686 | InclusionDirective *ID |
| 4687 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4688 | StringRef(Blob.data(), Record[0]), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4689 | Record[1], Record[3], |
| 4690 | File, |
| 4691 | Range); |
| 4692 | return ID; |
| 4693 | } |
| 4694 | } |
| 4695 | |
| 4696 | llvm_unreachable("Invalid PreprocessorDetailRecordTypes"); |
| 4697 | } |
| 4698 | |
| 4699 | /// \brief \arg SLocMapI points at a chunk of a module that contains no |
| 4700 | /// preprocessed entities or the entities it contains are not the ones we are |
| 4701 | /// looking for. Find the next module that contains entities and return the ID |
| 4702 | /// of the first entry. |
| 4703 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 4704 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 4705 | ++SLocMapI; |
| 4706 | for (GlobalSLocOffsetMapType::const_iterator |
| 4707 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
| 4708 | ModuleFile &M = *SLocMapI->second; |
| 4709 | if (M.NumPreprocessedEntities) |
| 4710 | return M.BasePreprocessedEntityID; |
| 4711 | } |
| 4712 | |
| 4713 | return getTotalNumPreprocessedEntities(); |
| 4714 | } |
| 4715 | |
| 4716 | namespace { |
| 4717 | |
| 4718 | template <unsigned PPEntityOffset::*PPLoc> |
| 4719 | struct PPEntityComp { |
| 4720 | const ASTReader &Reader; |
| 4721 | ModuleFile &M; |
| 4722 | |
| 4723 | PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) { } |
| 4724 | |
| 4725 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 4726 | SourceLocation LHS = getLoc(L); |
| 4727 | SourceLocation RHS = getLoc(R); |
| 4728 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4729 | } |
| 4730 | |
| 4731 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
| 4732 | SourceLocation LHS = getLoc(L); |
| 4733 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4734 | } |
| 4735 | |
| 4736 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
| 4737 | SourceLocation RHS = getLoc(R); |
| 4738 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4739 | } |
| 4740 | |
| 4741 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
| 4742 | return Reader.ReadSourceLocation(M, PPE.*PPLoc); |
| 4743 | } |
| 4744 | }; |
| 4745 | |
| 4746 | } |
| 4747 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 4748 | PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc, |
| 4749 | bool EndsAfter) const { |
| 4750 | if (SourceMgr.isLocalSourceLocation(Loc)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4751 | return getTotalNumPreprocessedEntities(); |
| 4752 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 4753 | GlobalSLocOffsetMapType::const_iterator SLocMapI = GlobalSLocOffsetMap.find( |
| 4754 | SourceManager::MaxLoadedOffset - Loc.getOffset() - 1); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4755 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 4756 | "Corrupted global sloc offset map"); |
| 4757 | |
| 4758 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 4759 | return findNextPreprocessedEntity(SLocMapI); |
| 4760 | |
| 4761 | ModuleFile &M = *SLocMapI->second; |
| 4762 | typedef const PPEntityOffset *pp_iterator; |
| 4763 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 4764 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 4765 | |
| 4766 | size_t Count = M.NumPreprocessedEntities; |
| 4767 | size_t Half; |
| 4768 | pp_iterator First = pp_begin; |
| 4769 | pp_iterator PPI; |
| 4770 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 4771 | if (EndsAfter) { |
| 4772 | PPI = std::upper_bound(pp_begin, pp_end, Loc, |
| 4773 | PPEntityComp<&PPEntityOffset::Begin>(*this, M)); |
| 4774 | } else { |
| 4775 | // Do a binary search manually instead of using std::lower_bound because |
| 4776 | // The end locations of entities may be unordered (when a macro expansion |
| 4777 | // is inside another macro argument), but for this case it is not important |
| 4778 | // whether we get the first macro expansion or its containing macro. |
| 4779 | while (Count > 0) { |
| 4780 | Half = Count / 2; |
| 4781 | PPI = First; |
| 4782 | std::advance(PPI, Half); |
| 4783 | if (SourceMgr.isBeforeInTranslationUnit(ReadSourceLocation(M, PPI->End), |
| 4784 | Loc)) { |
| 4785 | First = PPI; |
| 4786 | ++First; |
| 4787 | Count = Count - Half - 1; |
| 4788 | } else |
| 4789 | Count = Half; |
| 4790 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | if (PPI == pp_end) |
| 4794 | return findNextPreprocessedEntity(SLocMapI); |
| 4795 | |
| 4796 | return M.BasePreprocessedEntityID + (PPI - pp_begin); |
| 4797 | } |
| 4798 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4799 | /// \brief Returns a pair of [Begin, End) indices of preallocated |
| 4800 | /// preprocessed entities that \arg Range encompasses. |
| 4801 | std::pair<unsigned, unsigned> |
| 4802 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 4803 | if (Range.isInvalid()) |
| 4804 | return std::make_pair(0,0); |
| 4805 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 4806 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 4807 | PreprocessedEntityID BeginID = |
| 4808 | findPreprocessedEntity(Range.getBegin(), false); |
| 4809 | PreprocessedEntityID EndID = findPreprocessedEntity(Range.getEnd(), true); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4810 | return std::make_pair(BeginID, EndID); |
| 4811 | } |
| 4812 | |
| 4813 | /// \brief Optionally returns true or false if the preallocated preprocessed |
| 4814 | /// entity with index \arg Index came from file \arg FID. |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4815 | Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4816 | FileID FID) { |
| 4817 | if (FID.isInvalid()) |
| 4818 | return false; |
| 4819 | |
| 4820 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 4821 | ModuleFile &M = *PPInfo.first; |
| 4822 | unsigned LocalIndex = PPInfo.second; |
| 4823 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 4824 | |
| 4825 | SourceLocation Loc = ReadSourceLocation(M, PPOffs.Begin); |
| 4826 | if (Loc.isInvalid()) |
| 4827 | return false; |
| 4828 | |
| 4829 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 4830 | return true; |
| 4831 | else |
| 4832 | return false; |
| 4833 | } |
| 4834 | |
| 4835 | namespace { |
| 4836 | /// \brief Visitor used to search for information about a header file. |
| 4837 | class HeaderFileInfoVisitor { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4838 | const FileEntry *FE; |
| 4839 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4840 | Optional<HeaderFileInfo> HFI; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4841 | |
| 4842 | public: |
Argyrios Kyrtzidis | 61a3896 | 2013-03-06 18:12:44 +0000 | [diff] [blame] | 4843 | explicit HeaderFileInfoVisitor(const FileEntry *FE) |
| 4844 | : FE(FE) { } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4845 | |
| 4846 | static bool visit(ModuleFile &M, void *UserData) { |
| 4847 | HeaderFileInfoVisitor *This |
| 4848 | = static_cast<HeaderFileInfoVisitor *>(UserData); |
| 4849 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4850 | HeaderFileInfoLookupTable *Table |
| 4851 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 4852 | if (!Table) |
| 4853 | return false; |
| 4854 | |
| 4855 | // Look in the on-disk hash table for an entry for this file name. |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 4856 | HeaderFileInfoLookupTable::iterator Pos = Table->find(This->FE); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4857 | if (Pos == Table->end()) |
| 4858 | return false; |
| 4859 | |
| 4860 | This->HFI = *Pos; |
| 4861 | return true; |
| 4862 | } |
| 4863 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4864 | Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4865 | }; |
| 4866 | } |
| 4867 | |
| 4868 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Argyrios Kyrtzidis | 61a3896 | 2013-03-06 18:12:44 +0000 | [diff] [blame] | 4869 | HeaderFileInfoVisitor Visitor(FE); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4870 | ModuleMgr.visit(&HeaderFileInfoVisitor::visit, &Visitor); |
Argyrios Kyrtzidis | 1054bbf | 2013-05-08 23:46:55 +0000 | [diff] [blame] | 4871 | if (Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4872 | return *HFI; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4873 | |
| 4874 | return HeaderFileInfo(); |
| 4875 | } |
| 4876 | |
| 4877 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
| 4878 | // FIXME: Make it work properly with modules. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4879 | SmallVector<DiagnosticsEngine::DiagState *, 32> DiagStates; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4880 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
| 4881 | ModuleFile &F = *(*I); |
| 4882 | unsigned Idx = 0; |
| 4883 | DiagStates.clear(); |
| 4884 | assert(!Diag.DiagStates.empty()); |
| 4885 | DiagStates.push_back(&Diag.DiagStates.front()); // the command-line one. |
| 4886 | while (Idx < F.PragmaDiagMappings.size()) { |
| 4887 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 4888 | unsigned DiagStateID = F.PragmaDiagMappings[Idx++]; |
| 4889 | if (DiagStateID != 0) { |
| 4890 | Diag.DiagStatePoints.push_back( |
| 4891 | DiagnosticsEngine::DiagStatePoint(DiagStates[DiagStateID-1], |
| 4892 | FullSourceLoc(Loc, SourceMgr))); |
| 4893 | continue; |
| 4894 | } |
| 4895 | |
| 4896 | assert(DiagStateID == 0); |
| 4897 | // A new DiagState was created here. |
| 4898 | Diag.DiagStates.push_back(*Diag.GetCurDiagState()); |
| 4899 | DiagnosticsEngine::DiagState *NewState = &Diag.DiagStates.back(); |
| 4900 | DiagStates.push_back(NewState); |
| 4901 | Diag.DiagStatePoints.push_back( |
| 4902 | DiagnosticsEngine::DiagStatePoint(NewState, |
| 4903 | FullSourceLoc(Loc, SourceMgr))); |
| 4904 | while (1) { |
| 4905 | assert(Idx < F.PragmaDiagMappings.size() && |
| 4906 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 4907 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 4908 | break; // Something is messed up but at least avoid infinite loop in |
| 4909 | // release build. |
| 4910 | } |
| 4911 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 4912 | if (DiagID == (unsigned)-1) { |
| 4913 | break; // no more diag/map pairs for this location. |
| 4914 | } |
Alp Toker | c726c36 | 2014-06-10 09:31:37 +0000 | [diff] [blame] | 4915 | diag::Severity Map = (diag::Severity)F.PragmaDiagMappings[Idx++]; |
| 4916 | DiagnosticMapping Mapping = Diag.makeUserMapping(Map, Loc); |
| 4917 | Diag.GetCurDiagState()->setMapping(DiagID, Mapping); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4918 | } |
| 4919 | } |
| 4920 | } |
| 4921 | } |
| 4922 | |
| 4923 | /// \brief Get the correct cursor and offset for loading a type. |
| 4924 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
| 4925 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
| 4926 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
| 4927 | ModuleFile *M = I->second; |
| 4928 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
| 4929 | } |
| 4930 | |
| 4931 | /// \brief Read and return the type with the given index.. |
| 4932 | /// |
| 4933 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 4934 | /// routine actually reads the record corresponding to the type at the given |
| 4935 | /// location. It is a helper routine for GetType, which deals with reading type |
| 4936 | /// IDs. |
| 4937 | QualType ASTReader::readTypeRecord(unsigned Index) { |
| 4938 | RecordLocation Loc = TypeCursorForIndex(Index); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4939 | BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4940 | |
| 4941 | // Keep track of where we are in the stream, then jump back there |
| 4942 | // after reading this type. |
| 4943 | SavedStreamPosition SavedPosition(DeclsCursor); |
| 4944 | |
| 4945 | ReadingKindTracker ReadingKind(Read_Type, *this); |
| 4946 | |
| 4947 | // Note that we are loading a type record. |
| 4948 | Deserializing AType(this); |
| 4949 | |
| 4950 | unsigned Idx = 0; |
| 4951 | DeclsCursor.JumpToBit(Loc.Offset); |
| 4952 | RecordData Record; |
| 4953 | unsigned Code = DeclsCursor.ReadCode(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4954 | switch ((TypeCode)DeclsCursor.readRecord(Code, Record)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4955 | case TYPE_EXT_QUAL: { |
| 4956 | if (Record.size() != 2) { |
| 4957 | Error("Incorrect encoding of extended qualifier type"); |
| 4958 | return QualType(); |
| 4959 | } |
| 4960 | QualType Base = readType(*Loc.F, Record, Idx); |
| 4961 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
| 4962 | return Context.getQualifiedType(Base, Quals); |
| 4963 | } |
| 4964 | |
| 4965 | case TYPE_COMPLEX: { |
| 4966 | if (Record.size() != 1) { |
| 4967 | Error("Incorrect encoding of complex type"); |
| 4968 | return QualType(); |
| 4969 | } |
| 4970 | QualType ElemType = readType(*Loc.F, Record, Idx); |
| 4971 | return Context.getComplexType(ElemType); |
| 4972 | } |
| 4973 | |
| 4974 | case TYPE_POINTER: { |
| 4975 | if (Record.size() != 1) { |
| 4976 | Error("Incorrect encoding of pointer type"); |
| 4977 | return QualType(); |
| 4978 | } |
| 4979 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 4980 | return Context.getPointerType(PointeeType); |
| 4981 | } |
| 4982 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 4983 | case TYPE_DECAYED: { |
| 4984 | if (Record.size() != 1) { |
| 4985 | Error("Incorrect encoding of decayed type"); |
| 4986 | return QualType(); |
| 4987 | } |
| 4988 | QualType OriginalType = readType(*Loc.F, Record, Idx); |
| 4989 | QualType DT = Context.getAdjustedParameterType(OriginalType); |
| 4990 | if (!isa<DecayedType>(DT)) |
| 4991 | Error("Decayed type does not decay"); |
| 4992 | return DT; |
| 4993 | } |
| 4994 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 4995 | case TYPE_ADJUSTED: { |
| 4996 | if (Record.size() != 2) { |
| 4997 | Error("Incorrect encoding of adjusted type"); |
| 4998 | return QualType(); |
| 4999 | } |
| 5000 | QualType OriginalTy = readType(*Loc.F, Record, Idx); |
| 5001 | QualType AdjustedTy = readType(*Loc.F, Record, Idx); |
| 5002 | return Context.getAdjustedType(OriginalTy, AdjustedTy); |
| 5003 | } |
| 5004 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5005 | case TYPE_BLOCK_POINTER: { |
| 5006 | if (Record.size() != 1) { |
| 5007 | Error("Incorrect encoding of block pointer type"); |
| 5008 | return QualType(); |
| 5009 | } |
| 5010 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5011 | return Context.getBlockPointerType(PointeeType); |
| 5012 | } |
| 5013 | |
| 5014 | case TYPE_LVALUE_REFERENCE: { |
| 5015 | if (Record.size() != 2) { |
| 5016 | Error("Incorrect encoding of lvalue reference type"); |
| 5017 | return QualType(); |
| 5018 | } |
| 5019 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5020 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
| 5021 | } |
| 5022 | |
| 5023 | case TYPE_RVALUE_REFERENCE: { |
| 5024 | if (Record.size() != 1) { |
| 5025 | Error("Incorrect encoding of rvalue reference type"); |
| 5026 | return QualType(); |
| 5027 | } |
| 5028 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5029 | return Context.getRValueReferenceType(PointeeType); |
| 5030 | } |
| 5031 | |
| 5032 | case TYPE_MEMBER_POINTER: { |
| 5033 | if (Record.size() != 2) { |
| 5034 | Error("Incorrect encoding of member pointer type"); |
| 5035 | return QualType(); |
| 5036 | } |
| 5037 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5038 | QualType ClassType = readType(*Loc.F, Record, Idx); |
| 5039 | if (PointeeType.isNull() || ClassType.isNull()) |
| 5040 | return QualType(); |
| 5041 | |
| 5042 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
| 5043 | } |
| 5044 | |
| 5045 | case TYPE_CONSTANT_ARRAY: { |
| 5046 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5047 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5048 | unsigned IndexTypeQuals = Record[2]; |
| 5049 | unsigned Idx = 3; |
| 5050 | llvm::APInt Size = ReadAPInt(Record, Idx); |
| 5051 | return Context.getConstantArrayType(ElementType, Size, |
| 5052 | ASM, IndexTypeQuals); |
| 5053 | } |
| 5054 | |
| 5055 | case TYPE_INCOMPLETE_ARRAY: { |
| 5056 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5057 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5058 | unsigned IndexTypeQuals = Record[2]; |
| 5059 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
| 5060 | } |
| 5061 | |
| 5062 | case TYPE_VARIABLE_ARRAY: { |
| 5063 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5064 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5065 | unsigned IndexTypeQuals = Record[2]; |
| 5066 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 5067 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 5068 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
| 5069 | ASM, IndexTypeQuals, |
| 5070 | SourceRange(LBLoc, RBLoc)); |
| 5071 | } |
| 5072 | |
| 5073 | case TYPE_VECTOR: { |
| 5074 | if (Record.size() != 3) { |
| 5075 | Error("incorrect encoding of vector type in AST file"); |
| 5076 | return QualType(); |
| 5077 | } |
| 5078 | |
| 5079 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5080 | unsigned NumElements = Record[1]; |
| 5081 | unsigned VecKind = Record[2]; |
| 5082 | return Context.getVectorType(ElementType, NumElements, |
| 5083 | (VectorType::VectorKind)VecKind); |
| 5084 | } |
| 5085 | |
| 5086 | case TYPE_EXT_VECTOR: { |
| 5087 | if (Record.size() != 3) { |
| 5088 | Error("incorrect encoding of extended vector type in AST file"); |
| 5089 | return QualType(); |
| 5090 | } |
| 5091 | |
| 5092 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5093 | unsigned NumElements = Record[1]; |
| 5094 | return Context.getExtVectorType(ElementType, NumElements); |
| 5095 | } |
| 5096 | |
| 5097 | case TYPE_FUNCTION_NO_PROTO: { |
| 5098 | if (Record.size() != 6) { |
| 5099 | Error("incorrect encoding of no-proto function type"); |
| 5100 | return QualType(); |
| 5101 | } |
| 5102 | QualType ResultType = readType(*Loc.F, Record, Idx); |
| 5103 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 5104 | (CallingConv)Record[4], Record[5]); |
| 5105 | return Context.getFunctionNoProtoType(ResultType, Info); |
| 5106 | } |
| 5107 | |
| 5108 | case TYPE_FUNCTION_PROTO: { |
| 5109 | QualType ResultType = readType(*Loc.F, Record, Idx); |
| 5110 | |
| 5111 | FunctionProtoType::ExtProtoInfo EPI; |
| 5112 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
| 5113 | /*hasregparm*/ Record[2], |
| 5114 | /*regparm*/ Record[3], |
| 5115 | static_cast<CallingConv>(Record[4]), |
| 5116 | /*produces*/ Record[5]); |
| 5117 | |
| 5118 | unsigned Idx = 6; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5119 | |
| 5120 | EPI.Variadic = Record[Idx++]; |
| 5121 | EPI.HasTrailingReturn = Record[Idx++]; |
| 5122 | EPI.TypeQuals = Record[Idx++]; |
| 5123 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5124 | SmallVector<QualType, 8> ExceptionStorage; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 5125 | readExceptionSpec(*Loc.F, ExceptionStorage, EPI.ExceptionSpec, Record, Idx); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 5126 | |
| 5127 | unsigned NumParams = Record[Idx++]; |
| 5128 | SmallVector<QualType, 16> ParamTypes; |
| 5129 | for (unsigned I = 0; I != NumParams; ++I) |
| 5130 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
| 5131 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 5132 | return Context.getFunctionType(ResultType, ParamTypes, EPI); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5133 | } |
| 5134 | |
| 5135 | case TYPE_UNRESOLVED_USING: { |
| 5136 | unsigned Idx = 0; |
| 5137 | return Context.getTypeDeclType( |
| 5138 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 5139 | } |
| 5140 | |
| 5141 | case TYPE_TYPEDEF: { |
| 5142 | if (Record.size() != 2) { |
| 5143 | Error("incorrect encoding of typedef type"); |
| 5144 | return QualType(); |
| 5145 | } |
| 5146 | unsigned Idx = 0; |
| 5147 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
| 5148 | QualType Canonical = readType(*Loc.F, Record, Idx); |
| 5149 | if (!Canonical.isNull()) |
| 5150 | Canonical = Context.getCanonicalType(Canonical); |
| 5151 | return Context.getTypedefType(Decl, Canonical); |
| 5152 | } |
| 5153 | |
| 5154 | case TYPE_TYPEOF_EXPR: |
| 5155 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
| 5156 | |
| 5157 | case TYPE_TYPEOF: { |
| 5158 | if (Record.size() != 1) { |
| 5159 | Error("incorrect encoding of typeof(type) in AST file"); |
| 5160 | return QualType(); |
| 5161 | } |
| 5162 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 5163 | return Context.getTypeOfType(UnderlyingType); |
| 5164 | } |
| 5165 | |
| 5166 | case TYPE_DECLTYPE: { |
| 5167 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 5168 | return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType); |
| 5169 | } |
| 5170 | |
| 5171 | case TYPE_UNARY_TRANSFORM: { |
| 5172 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 5173 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 5174 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
| 5175 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
| 5176 | } |
| 5177 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 5178 | case TYPE_AUTO: { |
| 5179 | QualType Deduced = readType(*Loc.F, Record, Idx); |
| 5180 | bool IsDecltypeAuto = Record[Idx++]; |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 5181 | bool IsDependent = Deduced.isNull() ? Record[Idx++] : false; |
Manuel Klimek | 2fdbea2 | 2013-08-22 12:12:24 +0000 | [diff] [blame] | 5182 | return Context.getAutoType(Deduced, IsDecltypeAuto, IsDependent); |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 5183 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5184 | |
| 5185 | case TYPE_RECORD: { |
| 5186 | if (Record.size() != 2) { |
| 5187 | Error("incorrect encoding of record type"); |
| 5188 | return QualType(); |
| 5189 | } |
| 5190 | unsigned Idx = 0; |
| 5191 | bool IsDependent = Record[Idx++]; |
| 5192 | RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx); |
| 5193 | RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl()); |
| 5194 | QualType T = Context.getRecordType(RD); |
| 5195 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 5196 | return T; |
| 5197 | } |
| 5198 | |
| 5199 | case TYPE_ENUM: { |
| 5200 | if (Record.size() != 2) { |
| 5201 | Error("incorrect encoding of enum type"); |
| 5202 | return QualType(); |
| 5203 | } |
| 5204 | unsigned Idx = 0; |
| 5205 | bool IsDependent = Record[Idx++]; |
| 5206 | QualType T |
| 5207 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
| 5208 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 5209 | return T; |
| 5210 | } |
| 5211 | |
| 5212 | case TYPE_ATTRIBUTED: { |
| 5213 | if (Record.size() != 3) { |
| 5214 | Error("incorrect encoding of attributed type"); |
| 5215 | return QualType(); |
| 5216 | } |
| 5217 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 5218 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
| 5219 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 5220 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
| 5221 | } |
| 5222 | |
| 5223 | case TYPE_PAREN: { |
| 5224 | if (Record.size() != 1) { |
| 5225 | Error("incorrect encoding of paren type"); |
| 5226 | return QualType(); |
| 5227 | } |
| 5228 | QualType InnerType = readType(*Loc.F, Record, Idx); |
| 5229 | return Context.getParenType(InnerType); |
| 5230 | } |
| 5231 | |
| 5232 | case TYPE_PACK_EXPANSION: { |
| 5233 | if (Record.size() != 2) { |
| 5234 | Error("incorrect encoding of pack expansion type"); |
| 5235 | return QualType(); |
| 5236 | } |
| 5237 | QualType Pattern = readType(*Loc.F, Record, Idx); |
| 5238 | if (Pattern.isNull()) |
| 5239 | return QualType(); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5240 | Optional<unsigned> NumExpansions; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5241 | if (Record[1]) |
| 5242 | NumExpansions = Record[1] - 1; |
| 5243 | return Context.getPackExpansionType(Pattern, NumExpansions); |
| 5244 | } |
| 5245 | |
| 5246 | case TYPE_ELABORATED: { |
| 5247 | unsigned Idx = 0; |
| 5248 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 5249 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
| 5250 | QualType NamedType = readType(*Loc.F, Record, Idx); |
| 5251 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
| 5252 | } |
| 5253 | |
| 5254 | case TYPE_OBJC_INTERFACE: { |
| 5255 | unsigned Idx = 0; |
| 5256 | ObjCInterfaceDecl *ItfD |
| 5257 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
| 5258 | return Context.getObjCInterfaceType(ItfD->getCanonicalDecl()); |
| 5259 | } |
| 5260 | |
| 5261 | case TYPE_OBJC_OBJECT: { |
| 5262 | unsigned Idx = 0; |
| 5263 | QualType Base = readType(*Loc.F, Record, Idx); |
| 5264 | unsigned NumProtos = Record[Idx++]; |
| 5265 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 5266 | for (unsigned I = 0; I != NumProtos; ++I) |
| 5267 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
| 5268 | return Context.getObjCObjectType(Base, Protos.data(), NumProtos); |
| 5269 | } |
| 5270 | |
| 5271 | case TYPE_OBJC_OBJECT_POINTER: { |
| 5272 | unsigned Idx = 0; |
| 5273 | QualType Pointee = readType(*Loc.F, Record, Idx); |
| 5274 | return Context.getObjCObjectPointerType(Pointee); |
| 5275 | } |
| 5276 | |
| 5277 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
| 5278 | unsigned Idx = 0; |
| 5279 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 5280 | QualType Replacement = readType(*Loc.F, Record, Idx); |
Stephan Tolksdorf | e96f8b3 | 2014-03-15 10:23:27 +0000 | [diff] [blame] | 5281 | return Context.getSubstTemplateTypeParmType( |
| 5282 | cast<TemplateTypeParmType>(Parm), |
| 5283 | Context.getCanonicalType(Replacement)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5284 | } |
| 5285 | |
| 5286 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 5287 | unsigned Idx = 0; |
| 5288 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 5289 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 5290 | return Context.getSubstTemplateTypeParmPackType( |
| 5291 | cast<TemplateTypeParmType>(Parm), |
| 5292 | ArgPack); |
| 5293 | } |
| 5294 | |
| 5295 | case TYPE_INJECTED_CLASS_NAME: { |
| 5296 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
| 5297 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
| 5298 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
| 5299 | // for AST reading, too much interdependencies. |
Richard Smith | 6377f8f | 2014-10-21 21:15:18 +0000 | [diff] [blame] | 5300 | const Type *T = nullptr; |
| 5301 | for (auto *DI = D; DI; DI = DI->getPreviousDecl()) { |
| 5302 | if (const Type *Existing = DI->getTypeForDecl()) { |
| 5303 | T = Existing; |
| 5304 | break; |
| 5305 | } |
| 5306 | } |
| 5307 | if (!T) { |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 5308 | T = new (Context, TypeAlignment) InjectedClassNameType(D, TST); |
Richard Smith | 6377f8f | 2014-10-21 21:15:18 +0000 | [diff] [blame] | 5309 | for (auto *DI = D; DI; DI = DI->getPreviousDecl()) |
| 5310 | DI->setTypeForDecl(T); |
| 5311 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 5312 | return QualType(T, 0); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | case TYPE_TEMPLATE_TYPE_PARM: { |
| 5316 | unsigned Idx = 0; |
| 5317 | unsigned Depth = Record[Idx++]; |
| 5318 | unsigned Index = Record[Idx++]; |
| 5319 | bool Pack = Record[Idx++]; |
| 5320 | TemplateTypeParmDecl *D |
| 5321 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
| 5322 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
| 5323 | } |
| 5324 | |
| 5325 | case TYPE_DEPENDENT_NAME: { |
| 5326 | unsigned Idx = 0; |
| 5327 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 5328 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
| 5329 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
| 5330 | QualType Canon = readType(*Loc.F, Record, Idx); |
| 5331 | if (!Canon.isNull()) |
| 5332 | Canon = Context.getCanonicalType(Canon); |
| 5333 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
| 5334 | } |
| 5335 | |
| 5336 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
| 5337 | unsigned Idx = 0; |
| 5338 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 5339 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
| 5340 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
| 5341 | unsigned NumArgs = Record[Idx++]; |
| 5342 | SmallVector<TemplateArgument, 8> Args; |
| 5343 | Args.reserve(NumArgs); |
| 5344 | while (NumArgs--) |
| 5345 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
| 5346 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 5347 | Args.size(), Args.data()); |
| 5348 | } |
| 5349 | |
| 5350 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
| 5351 | unsigned Idx = 0; |
| 5352 | |
| 5353 | // ArrayType |
| 5354 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5355 | ArrayType::ArraySizeModifier ASM |
| 5356 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 5357 | unsigned IndexTypeQuals = Record[Idx++]; |
| 5358 | |
| 5359 | // DependentSizedArrayType |
| 5360 | Expr *NumElts = ReadExpr(*Loc.F); |
| 5361 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
| 5362 | |
| 5363 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 5364 | IndexTypeQuals, Brackets); |
| 5365 | } |
| 5366 | |
| 5367 | case TYPE_TEMPLATE_SPECIALIZATION: { |
| 5368 | unsigned Idx = 0; |
| 5369 | bool IsDependent = Record[Idx++]; |
| 5370 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
| 5371 | SmallVector<TemplateArgument, 8> Args; |
| 5372 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
| 5373 | QualType Underlying = readType(*Loc.F, Record, Idx); |
| 5374 | QualType T; |
| 5375 | if (Underlying.isNull()) |
| 5376 | T = Context.getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 5377 | Args.size()); |
| 5378 | else |
| 5379 | T = Context.getTemplateSpecializationType(Name, Args.data(), |
| 5380 | Args.size(), Underlying); |
| 5381 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 5382 | return T; |
| 5383 | } |
| 5384 | |
| 5385 | case TYPE_ATOMIC: { |
| 5386 | if (Record.size() != 1) { |
| 5387 | Error("Incorrect encoding of atomic type"); |
| 5388 | return QualType(); |
| 5389 | } |
| 5390 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 5391 | return Context.getAtomicType(ValueType); |
| 5392 | } |
| 5393 | } |
| 5394 | llvm_unreachable("Invalid TypeCode!"); |
| 5395 | } |
| 5396 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5397 | void ASTReader::readExceptionSpec(ModuleFile &ModuleFile, |
| 5398 | SmallVectorImpl<QualType> &Exceptions, |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 5399 | FunctionProtoType::ExceptionSpecInfo &ESI, |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5400 | const RecordData &Record, unsigned &Idx) { |
| 5401 | ExceptionSpecificationType EST = |
| 5402 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 5403 | ESI.Type = EST; |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5404 | if (EST == EST_Dynamic) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 5405 | for (unsigned I = 0, N = Record[Idx++]; I != N; ++I) |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5406 | Exceptions.push_back(readType(ModuleFile, Record, Idx)); |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 5407 | ESI.Exceptions = Exceptions; |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5408 | } else if (EST == EST_ComputedNoexcept) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 5409 | ESI.NoexceptExpr = ReadExpr(ModuleFile); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5410 | } else if (EST == EST_Uninstantiated) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 5411 | ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
| 5412 | ESI.SourceTemplate = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5413 | } else if (EST == EST_Unevaluated) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 5414 | ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5415 | } |
| 5416 | } |
| 5417 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5418 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
| 5419 | ASTReader &Reader; |
| 5420 | ModuleFile &F; |
| 5421 | const ASTReader::RecordData &Record; |
| 5422 | unsigned &Idx; |
| 5423 | |
| 5424 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 5425 | unsigned &I) { |
| 5426 | return Reader.ReadSourceLocation(F, R, I); |
| 5427 | } |
| 5428 | |
| 5429 | template<typename T> |
| 5430 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 5431 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 5432 | } |
| 5433 | |
| 5434 | public: |
| 5435 | TypeLocReader(ASTReader &Reader, ModuleFile &F, |
| 5436 | const ASTReader::RecordData &Record, unsigned &Idx) |
| 5437 | : Reader(Reader), F(F), Record(Record), Idx(Idx) |
| 5438 | { } |
| 5439 | |
| 5440 | // We want compile-time assurance that we've enumerated all of |
| 5441 | // these, so unfortunately we have to declare them first, then |
| 5442 | // define them out-of-line. |
| 5443 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 5444 | #define TYPELOC(CLASS, PARENT) \ |
| 5445 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
| 5446 | #include "clang/AST/TypeLocNodes.def" |
| 5447 | |
| 5448 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 5449 | void VisitArrayTypeLoc(ArrayTypeLoc); |
| 5450 | }; |
| 5451 | |
| 5452 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 5453 | // nothing to do |
| 5454 | } |
| 5455 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
| 5456 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
| 5457 | if (TL.needsExtraLocalData()) { |
| 5458 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 5459 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 5460 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 5461 | TL.setModeAttr(Record[Idx++]); |
| 5462 | } |
| 5463 | } |
| 5464 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 5465 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5466 | } |
| 5467 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 5468 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
| 5469 | } |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 5470 | void TypeLocReader::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 5471 | // nothing to do |
| 5472 | } |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 5473 | void TypeLocReader::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 5474 | // nothing to do |
| 5475 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5476 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 5477 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
| 5478 | } |
| 5479 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 5480 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
| 5481 | } |
| 5482 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 5483 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
| 5484 | } |
| 5485 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 5486 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
| 5487 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 5488 | } |
| 5489 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 5490 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 5491 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
| 5492 | if (Record[Idx++]) |
| 5493 | TL.setSizeExpr(Reader.ReadExpr(F)); |
| 5494 | else |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5495 | TL.setSizeExpr(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5496 | } |
| 5497 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 5498 | VisitArrayTypeLoc(TL); |
| 5499 | } |
| 5500 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 5501 | VisitArrayTypeLoc(TL); |
| 5502 | } |
| 5503 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 5504 | VisitArrayTypeLoc(TL); |
| 5505 | } |
| 5506 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 5507 | DependentSizedArrayTypeLoc TL) { |
| 5508 | VisitArrayTypeLoc(TL); |
| 5509 | } |
| 5510 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 5511 | DependentSizedExtVectorTypeLoc TL) { |
| 5512 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5513 | } |
| 5514 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 5515 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5516 | } |
| 5517 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 5518 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5519 | } |
| 5520 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
| 5521 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 5522 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 5523 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 5524 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 5525 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) { |
| 5526 | TL.setParam(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5527 | } |
| 5528 | } |
| 5529 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 5530 | VisitFunctionTypeLoc(TL); |
| 5531 | } |
| 5532 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 5533 | VisitFunctionTypeLoc(TL); |
| 5534 | } |
| 5535 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 5536 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5537 | } |
| 5538 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 5539 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5540 | } |
| 5541 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
| 5542 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 5543 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 5544 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 5545 | } |
| 5546 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
| 5547 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 5548 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 5549 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 5550 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 5551 | } |
| 5552 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 5553 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5554 | } |
| 5555 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 5556 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 5557 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 5558 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 5559 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 5560 | } |
| 5561 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 5562 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5563 | } |
| 5564 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 5565 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5566 | } |
| 5567 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 5568 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5569 | } |
| 5570 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 5571 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 5572 | if (TL.hasAttrOperand()) { |
| 5573 | SourceRange range; |
| 5574 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 5575 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 5576 | TL.setAttrOperandParensRange(range); |
| 5577 | } |
| 5578 | if (TL.hasAttrExprOperand()) { |
| 5579 | if (Record[Idx++]) |
| 5580 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 5581 | else |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5582 | TL.setAttrExprOperand(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5583 | } else if (TL.hasAttrEnumOperand()) |
| 5584 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 5585 | } |
| 5586 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 5587 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5588 | } |
| 5589 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 5590 | SubstTemplateTypeParmTypeLoc TL) { |
| 5591 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5592 | } |
| 5593 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 5594 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 5595 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5596 | } |
| 5597 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 5598 | TemplateSpecializationTypeLoc TL) { |
| 5599 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 5600 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 5601 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 5602 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
| 5603 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 5604 | TL.setArgLocInfo(i, |
| 5605 | Reader.GetTemplateArgumentLocInfo(F, |
| 5606 | TL.getTypePtr()->getArg(i).getKind(), |
| 5607 | Record, Idx)); |
| 5608 | } |
| 5609 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 5610 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 5611 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 5612 | } |
| 5613 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
| 5614 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 5615 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
| 5616 | } |
| 5617 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 5618 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5619 | } |
| 5620 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
| 5621 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 5622 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
| 5623 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5624 | } |
| 5625 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 5626 | DependentTemplateSpecializationTypeLoc TL) { |
| 5627 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 5628 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
| 5629 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 5630 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 5631 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 5632 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
| 5633 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 5634 | TL.setArgLocInfo(I, |
| 5635 | Reader.GetTemplateArgumentLocInfo(F, |
| 5636 | TL.getTypePtr()->getArg(I).getKind(), |
| 5637 | Record, Idx)); |
| 5638 | } |
| 5639 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 5640 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 5641 | } |
| 5642 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 5643 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 5644 | } |
| 5645 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 5646 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
| 5647 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 5648 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
| 5649 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 5650 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
| 5651 | } |
| 5652 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 5653 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
| 5654 | } |
| 5655 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 5656 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 5657 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 5658 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 5659 | } |
| 5660 | |
| 5661 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(ModuleFile &F, |
| 5662 | const RecordData &Record, |
| 5663 | unsigned &Idx) { |
| 5664 | QualType InfoTy = readType(F, Record, Idx); |
| 5665 | if (InfoTy.isNull()) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5666 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5667 | |
| 5668 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
| 5669 | TypeLocReader TLR(*this, F, Record, Idx); |
| 5670 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
| 5671 | TLR.Visit(TL); |
| 5672 | return TInfo; |
| 5673 | } |
| 5674 | |
| 5675 | QualType ASTReader::GetType(TypeID ID) { |
| 5676 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 5677 | unsigned Index = ID >> Qualifiers::FastWidth; |
| 5678 | |
| 5679 | if (Index < NUM_PREDEF_TYPE_IDS) { |
| 5680 | QualType T; |
| 5681 | switch ((PredefinedTypeIDs)Index) { |
| 5682 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 5683 | case PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; |
| 5684 | case PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; |
| 5685 | |
| 5686 | case PREDEF_TYPE_CHAR_U_ID: |
| 5687 | case PREDEF_TYPE_CHAR_S_ID: |
| 5688 | // FIXME: Check that the signedness of CharTy is correct! |
| 5689 | T = Context.CharTy; |
| 5690 | break; |
| 5691 | |
| 5692 | case PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; |
| 5693 | case PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; |
| 5694 | case PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; |
| 5695 | case PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; |
| 5696 | case PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; |
| 5697 | case PREDEF_TYPE_UINT128_ID: T = Context.UnsignedInt128Ty; break; |
| 5698 | case PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; |
| 5699 | case PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; |
| 5700 | case PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; |
| 5701 | case PREDEF_TYPE_INT_ID: T = Context.IntTy; break; |
| 5702 | case PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; |
| 5703 | case PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; |
| 5704 | case PREDEF_TYPE_INT128_ID: T = Context.Int128Ty; break; |
| 5705 | case PREDEF_TYPE_HALF_ID: T = Context.HalfTy; break; |
| 5706 | case PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; |
| 5707 | case PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; |
| 5708 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; |
| 5709 | case PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; |
| 5710 | case PREDEF_TYPE_BOUND_MEMBER: T = Context.BoundMemberTy; break; |
| 5711 | case PREDEF_TYPE_PSEUDO_OBJECT: T = Context.PseudoObjectTy; break; |
| 5712 | case PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; |
| 5713 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context.UnknownAnyTy; break; |
| 5714 | case PREDEF_TYPE_NULLPTR_ID: T = Context.NullPtrTy; break; |
| 5715 | case PREDEF_TYPE_CHAR16_ID: T = Context.Char16Ty; break; |
| 5716 | case PREDEF_TYPE_CHAR32_ID: T = Context.Char32Ty; break; |
| 5717 | case PREDEF_TYPE_OBJC_ID: T = Context.ObjCBuiltinIdTy; break; |
| 5718 | case PREDEF_TYPE_OBJC_CLASS: T = Context.ObjCBuiltinClassTy; break; |
| 5719 | case PREDEF_TYPE_OBJC_SEL: T = Context.ObjCBuiltinSelTy; break; |
Guy Benyei | d8a08ea | 2012-12-18 14:38:23 +0000 | [diff] [blame] | 5720 | case PREDEF_TYPE_IMAGE1D_ID: T = Context.OCLImage1dTy; break; |
| 5721 | case PREDEF_TYPE_IMAGE1D_ARR_ID: T = Context.OCLImage1dArrayTy; break; |
| 5722 | case PREDEF_TYPE_IMAGE1D_BUFF_ID: T = Context.OCLImage1dBufferTy; break; |
| 5723 | case PREDEF_TYPE_IMAGE2D_ID: T = Context.OCLImage2dTy; break; |
| 5724 | case PREDEF_TYPE_IMAGE2D_ARR_ID: T = Context.OCLImage2dArrayTy; break; |
| 5725 | case PREDEF_TYPE_IMAGE3D_ID: T = Context.OCLImage3dTy; break; |
Guy Benyei | 6105419 | 2013-02-07 10:55:47 +0000 | [diff] [blame] | 5726 | case PREDEF_TYPE_SAMPLER_ID: T = Context.OCLSamplerTy; break; |
Guy Benyei | 1b4fb3e | 2013-01-20 12:31:11 +0000 | [diff] [blame] | 5727 | case PREDEF_TYPE_EVENT_ID: T = Context.OCLEventTy; break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5728 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; |
| 5729 | |
| 5730 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
| 5731 | T = Context.getAutoRRefDeductType(); |
| 5732 | break; |
| 5733 | |
| 5734 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 5735 | T = Context.ARCUnbridgedCastTy; |
| 5736 | break; |
| 5737 | |
| 5738 | case PREDEF_TYPE_VA_LIST_TAG: |
| 5739 | T = Context.getVaListTagType(); |
| 5740 | break; |
| 5741 | |
| 5742 | case PREDEF_TYPE_BUILTIN_FN: |
| 5743 | T = Context.BuiltinFnTy; |
| 5744 | break; |
| 5745 | } |
| 5746 | |
| 5747 | assert(!T.isNull() && "Unknown predefined type"); |
| 5748 | return T.withFastQualifiers(FastQuals); |
| 5749 | } |
| 5750 | |
| 5751 | Index -= NUM_PREDEF_TYPE_IDS; |
| 5752 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
| 5753 | if (TypesLoaded[Index].isNull()) { |
| 5754 | TypesLoaded[Index] = readTypeRecord(Index); |
| 5755 | if (TypesLoaded[Index].isNull()) |
| 5756 | return QualType(); |
| 5757 | |
| 5758 | TypesLoaded[Index]->setFromAST(); |
| 5759 | if (DeserializationListener) |
| 5760 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
| 5761 | TypesLoaded[Index]); |
| 5762 | } |
| 5763 | |
| 5764 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
| 5765 | } |
| 5766 | |
| 5767 | QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) { |
| 5768 | return GetType(getGlobalTypeID(F, LocalID)); |
| 5769 | } |
| 5770 | |
| 5771 | serialization::TypeID |
| 5772 | ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const { |
| 5773 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 5774 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 5775 | |
| 5776 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 5777 | return LocalID; |
| 5778 | |
| 5779 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5780 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 5781 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 5782 | |
| 5783 | unsigned GlobalIndex = LocalIndex + I->second; |
| 5784 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 5785 | } |
| 5786 | |
| 5787 | TemplateArgumentLocInfo |
| 5788 | ASTReader::GetTemplateArgumentLocInfo(ModuleFile &F, |
| 5789 | TemplateArgument::ArgKind Kind, |
| 5790 | const RecordData &Record, |
| 5791 | unsigned &Index) { |
| 5792 | switch (Kind) { |
| 5793 | case TemplateArgument::Expression: |
| 5794 | return ReadExpr(F); |
| 5795 | case TemplateArgument::Type: |
| 5796 | return GetTypeSourceInfo(F, Record, Index); |
| 5797 | case TemplateArgument::Template: { |
| 5798 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 5799 | Index); |
| 5800 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
| 5801 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
| 5802 | SourceLocation()); |
| 5803 | } |
| 5804 | case TemplateArgument::TemplateExpansion: { |
| 5805 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 5806 | Index); |
| 5807 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
| 5808 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
| 5809 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
| 5810 | EllipsisLoc); |
| 5811 | } |
| 5812 | case TemplateArgument::Null: |
| 5813 | case TemplateArgument::Integral: |
| 5814 | case TemplateArgument::Declaration: |
| 5815 | case TemplateArgument::NullPtr: |
| 5816 | case TemplateArgument::Pack: |
| 5817 | // FIXME: Is this right? |
| 5818 | return TemplateArgumentLocInfo(); |
| 5819 | } |
| 5820 | llvm_unreachable("unexpected template argument loc"); |
| 5821 | } |
| 5822 | |
| 5823 | TemplateArgumentLoc |
| 5824 | ASTReader::ReadTemplateArgumentLoc(ModuleFile &F, |
| 5825 | const RecordData &Record, unsigned &Index) { |
| 5826 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
| 5827 | |
| 5828 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 5829 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 5830 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 5831 | } |
| 5832 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
| 5833 | Record, Index)); |
| 5834 | } |
| 5835 | |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5836 | const ASTTemplateArgumentListInfo* |
| 5837 | ASTReader::ReadASTTemplateArgumentListInfo(ModuleFile &F, |
| 5838 | const RecordData &Record, |
| 5839 | unsigned &Index) { |
| 5840 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Index); |
| 5841 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Index); |
| 5842 | unsigned NumArgsAsWritten = Record[Index++]; |
| 5843 | TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); |
| 5844 | for (unsigned i = 0; i != NumArgsAsWritten; ++i) |
| 5845 | TemplArgsInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Index)); |
| 5846 | return ASTTemplateArgumentListInfo::Create(getContext(), TemplArgsInfo); |
| 5847 | } |
| 5848 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5849 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
| 5850 | return GetDecl(ID); |
| 5851 | } |
| 5852 | |
Richard Smith | 5089542 | 2015-01-31 03:04:55 +0000 | [diff] [blame] | 5853 | template<typename TemplateSpecializationDecl> |
| 5854 | static void completeRedeclChainForTemplateSpecialization(Decl *D) { |
| 5855 | if (auto *TSD = dyn_cast<TemplateSpecializationDecl>(D)) |
| 5856 | TSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 5857 | } |
| 5858 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5859 | void ASTReader::CompleteRedeclChain(const Decl *D) { |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 5860 | if (NumCurrentElementsDeserializing) { |
| 5861 | // We arrange to not care about the complete redeclaration chain while we're |
| 5862 | // deserializing. Just remember that the AST has marked this one as complete |
| 5863 | // but that it's not actually complete yet, so we know we still need to |
| 5864 | // complete it later. |
| 5865 | PendingIncompleteDeclChains.push_back(const_cast<Decl*>(D)); |
| 5866 | return; |
| 5867 | } |
| 5868 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5869 | const DeclContext *DC = D->getDeclContext()->getRedeclContext(); |
| 5870 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5871 | // If this is a named declaration, complete it by looking it up |
| 5872 | // within its context. |
| 5873 | // |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 5874 | // FIXME: Merging a function definition should merge |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5875 | // all mergeable entities within it. |
| 5876 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC) || |
| 5877 | isa<CXXRecordDecl>(DC) || isa<EnumDecl>(DC)) { |
| 5878 | if (DeclarationName Name = cast<NamedDecl>(D)->getDeclName()) { |
| 5879 | auto *II = Name.getAsIdentifierInfo(); |
| 5880 | if (isa<TranslationUnitDecl>(DC) && II) { |
| 5881 | // Outside of C++, we don't have a lookup table for the TU, so update |
| 5882 | // the identifier instead. In C++, either way should work fine. |
| 5883 | if (II->isOutOfDate()) |
| 5884 | updateOutOfDateIdentifier(*II); |
| 5885 | } else |
| 5886 | DC->lookup(Name); |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 5887 | } else if (needsAnonymousDeclarationNumber(cast<NamedDecl>(D))) { |
| 5888 | // FIXME: It'd be nice to do something a bit more targeted here. |
| 5889 | D->getDeclContext()->decls_begin(); |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5890 | } |
| 5891 | } |
Richard Smith | 5089542 | 2015-01-31 03:04:55 +0000 | [diff] [blame] | 5892 | |
| 5893 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) |
| 5894 | CTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 5895 | if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) |
| 5896 | VTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 5897 | if (auto *FD = dyn_cast<FunctionDecl>(D)) { |
| 5898 | if (auto *Template = FD->getPrimaryTemplate()) |
| 5899 | Template->LoadLazySpecializations(); |
| 5900 | } |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5901 | } |
| 5902 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5903 | uint64_t ASTReader::ReadCXXCtorInitializersRef(ModuleFile &M, |
| 5904 | const RecordData &Record, |
| 5905 | unsigned &Idx) { |
| 5906 | if (Idx >= Record.size() || Record[Idx] > M.LocalNumCXXCtorInitializers) { |
| 5907 | Error("malformed AST file: missing C++ ctor initializers"); |
| 5908 | return 0; |
| 5909 | } |
| 5910 | |
| 5911 | unsigned LocalID = Record[Idx++]; |
| 5912 | return getGlobalBitOffset(M, M.CXXCtorInitializersOffsets[LocalID - 1]); |
| 5913 | } |
| 5914 | |
| 5915 | CXXCtorInitializer ** |
| 5916 | ASTReader::GetExternalCXXCtorInitializers(uint64_t Offset) { |
| 5917 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 5918 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
| 5919 | SavedStreamPosition SavedPosition(Cursor); |
| 5920 | Cursor.JumpToBit(Loc.Offset); |
| 5921 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 5922 | |
| 5923 | RecordData Record; |
| 5924 | unsigned Code = Cursor.ReadCode(); |
| 5925 | unsigned RecCode = Cursor.readRecord(Code, Record); |
| 5926 | if (RecCode != DECL_CXX_CTOR_INITIALIZERS) { |
| 5927 | Error("malformed AST file: missing C++ ctor initializers"); |
| 5928 | return nullptr; |
| 5929 | } |
| 5930 | |
| 5931 | unsigned Idx = 0; |
| 5932 | return ReadCXXCtorInitializers(*Loc.F, Record, Idx); |
| 5933 | } |
| 5934 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5935 | uint64_t ASTReader::readCXXBaseSpecifiers(ModuleFile &M, |
| 5936 | const RecordData &Record, |
| 5937 | unsigned &Idx) { |
| 5938 | if (Idx >= Record.size() || Record[Idx] > M.LocalNumCXXBaseSpecifiers) { |
| 5939 | Error("malformed AST file: missing C++ base specifier"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5940 | return 0; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5941 | } |
| 5942 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5943 | unsigned LocalID = Record[Idx++]; |
| 5944 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
| 5945 | } |
| 5946 | |
| 5947 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 5948 | RecordLocation Loc = getLocalBitOffset(Offset); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5949 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5950 | SavedStreamPosition SavedPosition(Cursor); |
| 5951 | Cursor.JumpToBit(Loc.Offset); |
| 5952 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 5953 | RecordData Record; |
| 5954 | unsigned Code = Cursor.ReadCode(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5955 | unsigned RecCode = Cursor.readRecord(Code, Record); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5956 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5957 | Error("malformed AST file: missing C++ base specifiers"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5958 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5959 | } |
| 5960 | |
| 5961 | unsigned Idx = 0; |
| 5962 | unsigned NumBases = Record[Idx++]; |
| 5963 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 5964 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 5965 | for (unsigned I = 0; I != NumBases; ++I) |
| 5966 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
| 5967 | return Bases; |
| 5968 | } |
| 5969 | |
| 5970 | serialization::DeclID |
| 5971 | ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const { |
| 5972 | if (LocalID < NUM_PREDEF_DECL_IDS) |
| 5973 | return LocalID; |
| 5974 | |
| 5975 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5976 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
| 5977 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 5978 | |
| 5979 | return LocalID + I->second; |
| 5980 | } |
| 5981 | |
| 5982 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
| 5983 | ModuleFile &M) const { |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 5984 | // Predefined decls aren't from any module. |
| 5985 | if (ID < NUM_PREDEF_DECL_IDS) |
| 5986 | return false; |
| 5987 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5988 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(ID); |
| 5989 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 5990 | return &M == I->second; |
| 5991 | } |
| 5992 | |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 5993 | ModuleFile *ASTReader::getOwningModuleFile(const Decl *D) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5994 | if (!D->isFromASTFile()) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5995 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5996 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID()); |
| 5997 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 5998 | return I->second; |
| 5999 | } |
| 6000 | |
| 6001 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 6002 | if (ID < NUM_PREDEF_DECL_IDS) |
| 6003 | return SourceLocation(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6004 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6005 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 6006 | |
| 6007 | if (Index > DeclsLoaded.size()) { |
| 6008 | Error("declaration ID out-of-range for AST file"); |
| 6009 | return SourceLocation(); |
| 6010 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6011 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6012 | if (Decl *D = DeclsLoaded[Index]) |
| 6013 | return D->getLocation(); |
| 6014 | |
| 6015 | unsigned RawLocation = 0; |
| 6016 | RecordLocation Rec = DeclCursorForID(ID, RawLocation); |
| 6017 | return ReadSourceLocation(*Rec.F, RawLocation); |
| 6018 | } |
| 6019 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6020 | static Decl *getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID) { |
| 6021 | switch (ID) { |
| 6022 | case PREDEF_DECL_NULL_ID: |
| 6023 | return nullptr; |
| 6024 | |
| 6025 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
| 6026 | return Context.getTranslationUnitDecl(); |
| 6027 | |
| 6028 | case PREDEF_DECL_OBJC_ID_ID: |
| 6029 | return Context.getObjCIdDecl(); |
| 6030 | |
| 6031 | case PREDEF_DECL_OBJC_SEL_ID: |
| 6032 | return Context.getObjCSelDecl(); |
| 6033 | |
| 6034 | case PREDEF_DECL_OBJC_CLASS_ID: |
| 6035 | return Context.getObjCClassDecl(); |
| 6036 | |
| 6037 | case PREDEF_DECL_OBJC_PROTOCOL_ID: |
| 6038 | return Context.getObjCProtocolDecl(); |
| 6039 | |
| 6040 | case PREDEF_DECL_INT_128_ID: |
| 6041 | return Context.getInt128Decl(); |
| 6042 | |
| 6043 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
| 6044 | return Context.getUInt128Decl(); |
| 6045 | |
| 6046 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
| 6047 | return Context.getObjCInstanceTypeDecl(); |
| 6048 | |
| 6049 | case PREDEF_DECL_BUILTIN_VA_LIST_ID: |
| 6050 | return Context.getBuiltinVaListDecl(); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 6051 | |
| 6052 | case PREDEF_DECL_EXTERN_C_CONTEXT_ID: |
| 6053 | return Context.getExternCContextDecl(); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6054 | } |
Yaron Keren | 322bdad | 2015-03-06 07:49:14 +0000 | [diff] [blame] | 6055 | llvm_unreachable("PredefinedDeclIDs unknown enum value"); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6056 | } |
| 6057 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6058 | Decl *ASTReader::GetExistingDecl(DeclID ID) { |
| 6059 | if (ID < NUM_PREDEF_DECL_IDS) { |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6060 | Decl *D = getPredefinedDecl(Context, (PredefinedDeclIDs)ID); |
| 6061 | if (D) { |
| 6062 | // Track that we have merged the declaration with ID \p ID into the |
| 6063 | // pre-existing predefined declaration \p D. |
| 6064 | auto &Merged = MergedDecls[D->getCanonicalDecl()]; |
| 6065 | if (Merged.empty()) |
| 6066 | Merged.push_back(ID); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6067 | } |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6068 | return D; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6069 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6070 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6071 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 6072 | |
| 6073 | if (Index >= DeclsLoaded.size()) { |
| 6074 | assert(0 && "declaration ID out-of-range for AST file"); |
| 6075 | Error("declaration ID out-of-range for AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6076 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6077 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6078 | |
| 6079 | return DeclsLoaded[Index]; |
| 6080 | } |
| 6081 | |
| 6082 | Decl *ASTReader::GetDecl(DeclID ID) { |
| 6083 | if (ID < NUM_PREDEF_DECL_IDS) |
| 6084 | return GetExistingDecl(ID); |
| 6085 | |
| 6086 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 6087 | |
| 6088 | if (Index >= DeclsLoaded.size()) { |
| 6089 | assert(0 && "declaration ID out-of-range for AST file"); |
| 6090 | Error("declaration ID out-of-range for AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6091 | return nullptr; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6092 | } |
| 6093 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6094 | if (!DeclsLoaded[Index]) { |
| 6095 | ReadDeclRecord(ID); |
| 6096 | if (DeserializationListener) |
| 6097 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 6098 | } |
| 6099 | |
| 6100 | return DeclsLoaded[Index]; |
| 6101 | } |
| 6102 | |
| 6103 | DeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
| 6104 | DeclID GlobalID) { |
| 6105 | if (GlobalID < NUM_PREDEF_DECL_IDS) |
| 6106 | return GlobalID; |
| 6107 | |
| 6108 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID); |
| 6109 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 6110 | ModuleFile *Owner = I->second; |
| 6111 | |
| 6112 | llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos |
| 6113 | = M.GlobalToLocalDeclIDs.find(Owner); |
| 6114 | if (Pos == M.GlobalToLocalDeclIDs.end()) |
| 6115 | return 0; |
| 6116 | |
| 6117 | return GlobalID - Owner->BaseDeclID + Pos->second; |
| 6118 | } |
| 6119 | |
| 6120 | serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, |
| 6121 | const RecordData &Record, |
| 6122 | unsigned &Idx) { |
| 6123 | if (Idx >= Record.size()) { |
| 6124 | Error("Corrupted AST file"); |
| 6125 | return 0; |
| 6126 | } |
| 6127 | |
| 6128 | return getGlobalDeclID(F, Record[Idx++]); |
| 6129 | } |
| 6130 | |
| 6131 | /// \brief Resolve the offset of a statement into a statement. |
| 6132 | /// |
| 6133 | /// This operation will read a new statement from the external |
| 6134 | /// source each time it is called, and is meant to be used via a |
| 6135 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
| 6136 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
| 6137 | // Switch case IDs are per Decl. |
| 6138 | ClearSwitchCaseIDs(); |
| 6139 | |
| 6140 | // Offset here is a global offset across the entire chain. |
| 6141 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 6142 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 6143 | return ReadStmtFromStream(*Loc.F); |
| 6144 | } |
| 6145 | |
| 6146 | namespace { |
| 6147 | class FindExternalLexicalDeclsVisitor { |
| 6148 | ASTReader &Reader; |
| 6149 | const DeclContext *DC; |
| 6150 | bool (*isKindWeWant)(Decl::Kind); |
| 6151 | |
| 6152 | SmallVectorImpl<Decl*> &Decls; |
| 6153 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 6154 | |
| 6155 | public: |
| 6156 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 6157 | bool (*isKindWeWant)(Decl::Kind), |
| 6158 | SmallVectorImpl<Decl*> &Decls) |
| 6159 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 6160 | { |
| 6161 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 6162 | PredefsVisited[I] = false; |
| 6163 | } |
| 6164 | |
| 6165 | static bool visit(ModuleFile &M, bool Preorder, void *UserData) { |
| 6166 | if (Preorder) |
| 6167 | return false; |
| 6168 | |
| 6169 | FindExternalLexicalDeclsVisitor *This |
| 6170 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 6171 | |
| 6172 | ModuleFile::DeclContextInfosMap::iterator Info |
| 6173 | = M.DeclContextInfos.find(This->DC); |
| 6174 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 6175 | return false; |
| 6176 | |
| 6177 | // Load all of the declaration IDs |
| 6178 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 6179 | *IDE = ID + Info->second.NumLexicalDecls; |
| 6180 | ID != IDE; ++ID) { |
| 6181 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 6182 | continue; |
| 6183 | |
| 6184 | // Don't add predefined declarations to the lexical context more |
| 6185 | // than once. |
| 6186 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 6187 | if (This->PredefsVisited[ID->second]) |
| 6188 | continue; |
| 6189 | |
| 6190 | This->PredefsVisited[ID->second] = true; |
| 6191 | } |
| 6192 | |
| 6193 | if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) { |
| 6194 | if (!This->DC->isDeclInLexicalTraversal(D)) |
| 6195 | This->Decls.push_back(D); |
| 6196 | } |
| 6197 | } |
| 6198 | |
| 6199 | return false; |
| 6200 | } |
| 6201 | }; |
| 6202 | } |
| 6203 | |
| 6204 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
| 6205 | bool (*isKindWeWant)(Decl::Kind), |
| 6206 | SmallVectorImpl<Decl*> &Decls) { |
| 6207 | // There might be lexical decls in multiple modules, for the TU at |
| 6208 | // least. Walk all of the modules in the order they were loaded. |
| 6209 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 6210 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
| 6211 | ++NumLexicalDeclContextsRead; |
| 6212 | return ELR_Success; |
| 6213 | } |
| 6214 | |
| 6215 | namespace { |
| 6216 | |
| 6217 | class DeclIDComp { |
| 6218 | ASTReader &Reader; |
| 6219 | ModuleFile &Mod; |
| 6220 | |
| 6221 | public: |
| 6222 | DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {} |
| 6223 | |
| 6224 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 6225 | SourceLocation LHS = getLocation(L); |
| 6226 | SourceLocation RHS = getLocation(R); |
| 6227 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 6228 | } |
| 6229 | |
| 6230 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 6231 | SourceLocation RHS = getLocation(R); |
| 6232 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 6233 | } |
| 6234 | |
| 6235 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 6236 | SourceLocation LHS = getLocation(L); |
| 6237 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 6238 | } |
| 6239 | |
| 6240 | SourceLocation getLocation(LocalDeclID ID) const { |
| 6241 | return Reader.getSourceManager().getFileLoc( |
| 6242 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 6243 | } |
| 6244 | }; |
| 6245 | |
| 6246 | } |
| 6247 | |
| 6248 | void ASTReader::FindFileRegionDecls(FileID File, |
| 6249 | unsigned Offset, unsigned Length, |
| 6250 | SmallVectorImpl<Decl *> &Decls) { |
| 6251 | SourceManager &SM = getSourceManager(); |
| 6252 | |
| 6253 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 6254 | if (I == FileDeclIDs.end()) |
| 6255 | return; |
| 6256 | |
| 6257 | FileDeclsInfo &DInfo = I->second; |
| 6258 | if (DInfo.Decls.empty()) |
| 6259 | return; |
| 6260 | |
| 6261 | SourceLocation |
| 6262 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 6263 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 6264 | |
| 6265 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 6266 | ArrayRef<serialization::LocalDeclID>::iterator |
| 6267 | BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 6268 | BeginLoc, DIDComp); |
| 6269 | if (BeginIt != DInfo.Decls.begin()) |
| 6270 | --BeginIt; |
| 6271 | |
| 6272 | // If we are pointing at a top-level decl inside an objc container, we need |
| 6273 | // to backtrack until we find it otherwise we will fail to report that the |
| 6274 | // region overlaps with an objc container. |
| 6275 | while (BeginIt != DInfo.Decls.begin() && |
| 6276 | GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt)) |
| 6277 | ->isTopLevelDeclInObjCContainer()) |
| 6278 | --BeginIt; |
| 6279 | |
| 6280 | ArrayRef<serialization::LocalDeclID>::iterator |
| 6281 | EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 6282 | EndLoc, DIDComp); |
| 6283 | if (EndIt != DInfo.Decls.end()) |
| 6284 | ++EndIt; |
| 6285 | |
| 6286 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 6287 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 6288 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 6289 | } |
| 6290 | |
| 6291 | namespace { |
| 6292 | /// \brief ModuleFile visitor used to perform name lookup into a |
| 6293 | /// declaration context. |
| 6294 | class DeclContextNameLookupVisitor { |
| 6295 | ASTReader &Reader; |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 6296 | ArrayRef<const DeclContext *> Contexts; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6297 | DeclarationName Name; |
| 6298 | SmallVectorImpl<NamedDecl *> &Decls; |
Richard Smith | 52874ec | 2015-02-13 20:17:14 +0000 | [diff] [blame] | 6299 | llvm::SmallPtrSetImpl<NamedDecl *> &DeclSet; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6300 | |
| 6301 | public: |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 6302 | DeclContextNameLookupVisitor(ASTReader &Reader, |
| 6303 | ArrayRef<const DeclContext *> Contexts, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6304 | DeclarationName Name, |
Richard Smith | 52874ec | 2015-02-13 20:17:14 +0000 | [diff] [blame] | 6305 | SmallVectorImpl<NamedDecl *> &Decls, |
| 6306 | llvm::SmallPtrSetImpl<NamedDecl *> &DeclSet) |
| 6307 | : Reader(Reader), Contexts(Contexts), Name(Name), Decls(Decls), |
| 6308 | DeclSet(DeclSet) { } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6309 | |
| 6310 | static bool visit(ModuleFile &M, void *UserData) { |
| 6311 | DeclContextNameLookupVisitor *This |
| 6312 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 6313 | |
| 6314 | // Check whether we have any visible declaration information for |
| 6315 | // this context in this module. |
| 6316 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 6317 | bool FoundInfo = false; |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 6318 | for (auto *DC : This->Contexts) { |
| 6319 | Info = M.DeclContextInfos.find(DC); |
| 6320 | if (Info != M.DeclContextInfos.end() && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6321 | Info->second.NameLookupTableData) { |
| 6322 | FoundInfo = true; |
| 6323 | break; |
| 6324 | } |
| 6325 | } |
| 6326 | |
| 6327 | if (!FoundInfo) |
| 6328 | return false; |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 6329 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6330 | // Look for this name within this module. |
Richard Smith | 52e3fba | 2014-03-11 07:17:35 +0000 | [diff] [blame] | 6331 | ASTDeclContextNameLookupTable *LookupTable = |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6332 | Info->second.NameLookupTableData; |
| 6333 | ASTDeclContextNameLookupTable::iterator Pos |
| 6334 | = LookupTable->find(This->Name); |
| 6335 | if (Pos == LookupTable->end()) |
| 6336 | return false; |
| 6337 | |
| 6338 | bool FoundAnything = false; |
| 6339 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 6340 | for (; Data.first != Data.second; ++Data.first) { |
| 6341 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 6342 | if (!ND) |
| 6343 | continue; |
| 6344 | |
| 6345 | if (ND->getDeclName() != This->Name) { |
| 6346 | // A name might be null because the decl's redeclarable part is |
| 6347 | // currently read before reading its name. The lookup is triggered by |
| 6348 | // building that decl (likely indirectly), and so it is later in the |
| 6349 | // sense of "already existing" and can be ignored here. |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 6350 | // FIXME: This should not happen; deserializing declarations should |
| 6351 | // not perform lookups since that can lead to deserialization cycles. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6352 | continue; |
| 6353 | } |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 6354 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6355 | // Record this declaration. |
| 6356 | FoundAnything = true; |
Richard Smith | 52874ec | 2015-02-13 20:17:14 +0000 | [diff] [blame] | 6357 | if (This->DeclSet.insert(ND).second) |
| 6358 | This->Decls.push_back(ND); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6359 | } |
| 6360 | |
| 6361 | return FoundAnything; |
| 6362 | } |
| 6363 | }; |
| 6364 | } |
| 6365 | |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 6366 | /// \brief Retrieve the "definitive" module file for the definition of the |
| 6367 | /// given declaration context, if there is one. |
| 6368 | /// |
| 6369 | /// The "definitive" module file is the only place where we need to look to |
| 6370 | /// find information about the declarations within the given declaration |
| 6371 | /// context. For example, C++ and Objective-C classes, C structs/unions, and |
| 6372 | /// Objective-C protocols, categories, and extensions are all defined in a |
| 6373 | /// single place in the source code, so they have definitive module files |
| 6374 | /// associated with them. C++ namespaces, on the other hand, can have |
| 6375 | /// definitions in multiple different module files. |
| 6376 | /// |
| 6377 | /// Note: this needs to be kept in sync with ASTWriter::AddedVisibleDecl's |
| 6378 | /// NDEBUG checking. |
| 6379 | static ModuleFile *getDefinitiveModuleFileFor(const DeclContext *DC, |
| 6380 | ASTReader &Reader) { |
Douglas Gregor | 7a6e200 | 2013-01-22 17:08:30 +0000 | [diff] [blame] | 6381 | if (const DeclContext *DefDC = getDefinitiveDeclContext(DC)) |
| 6382 | return Reader.getOwningModuleFile(cast<Decl>(DefDC)); |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 6383 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6384 | return nullptr; |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 6385 | } |
| 6386 | |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 6387 | bool |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6388 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
| 6389 | DeclarationName Name) { |
| 6390 | assert(DC->hasExternalVisibleStorage() && |
| 6391 | "DeclContext has no visible decls in storage"); |
| 6392 | if (!Name) |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 6393 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6394 | |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 6395 | Deserializing LookupResults(this); |
| 6396 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6397 | SmallVector<NamedDecl *, 64> Decls; |
Richard Smith | 52874ec | 2015-02-13 20:17:14 +0000 | [diff] [blame] | 6398 | llvm::SmallPtrSet<NamedDecl*, 64> DeclSet; |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 6399 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6400 | // Compute the declaration contexts we need to look into. Multiple such |
| 6401 | // declaration contexts occur when two declaration contexts from disjoint |
| 6402 | // modules get merged, e.g., when two namespaces with the same name are |
| 6403 | // independently defined in separate modules. |
| 6404 | SmallVector<const DeclContext *, 2> Contexts; |
| 6405 | Contexts.push_back(DC); |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 6406 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6407 | if (DC->isNamespace()) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6408 | auto Merged = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6409 | if (Merged != MergedDecls.end()) { |
| 6410 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 6411 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 6412 | } |
| 6413 | } |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 6414 | |
| 6415 | auto LookUpInContexts = [&](ArrayRef<const DeclContext*> Contexts) { |
Richard Smith | 52874ec | 2015-02-13 20:17:14 +0000 | [diff] [blame] | 6416 | DeclContextNameLookupVisitor Visitor(*this, Contexts, Name, Decls, DeclSet); |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 6417 | |
| 6418 | // If we can definitively determine which module file to look into, |
| 6419 | // only look there. Otherwise, look in all module files. |
| 6420 | ModuleFile *Definitive; |
| 6421 | if (Contexts.size() == 1 && |
| 6422 | (Definitive = getDefinitiveModuleFileFor(Contexts[0], *this))) { |
| 6423 | DeclContextNameLookupVisitor::visit(*Definitive, &Visitor); |
| 6424 | } else { |
| 6425 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
| 6426 | } |
| 6427 | }; |
| 6428 | |
| 6429 | LookUpInContexts(Contexts); |
| 6430 | |
| 6431 | // If this might be an implicit special member function, then also search |
| 6432 | // all merged definitions of the surrounding class. We need to search them |
| 6433 | // individually, because finding an entity in one of them doesn't imply that |
| 6434 | // we can't find a different entity in another one. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6435 | if (isa<CXXRecordDecl>(DC)) { |
Richard Smith | 0279375 | 2015-03-27 21:16:39 +0000 | [diff] [blame] | 6436 | auto Merged = MergedLookups.find(DC); |
| 6437 | if (Merged != MergedLookups.end()) { |
| 6438 | for (unsigned I = 0; I != Merged->second.size(); ++I) { |
| 6439 | const DeclContext *Context = Merged->second[I]; |
| 6440 | LookUpInContexts(Context); |
| 6441 | // We might have just added some more merged lookups. If so, our |
| 6442 | // iterator is now invalid, so grab a fresh one before continuing. |
| 6443 | Merged = MergedLookups.find(DC); |
Richard Smith | e061247 | 2014-11-21 05:16:13 +0000 | [diff] [blame] | 6444 | } |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 6445 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6446 | } |
| 6447 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6448 | ++NumVisibleDeclContextsRead; |
| 6449 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 6450 | return !Decls.empty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6451 | } |
| 6452 | |
| 6453 | namespace { |
| 6454 | /// \brief ModuleFile visitor used to retrieve all visible names in a |
| 6455 | /// declaration context. |
| 6456 | class DeclContextAllNamesVisitor { |
| 6457 | ASTReader &Reader; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 6458 | SmallVectorImpl<const DeclContext *> &Contexts; |
Craig Topper | 3598eb7 | 2013-07-05 04:43:31 +0000 | [diff] [blame] | 6459 | DeclsMap &Decls; |
Richard Smith | 52874ec | 2015-02-13 20:17:14 +0000 | [diff] [blame] | 6460 | llvm::SmallPtrSet<NamedDecl *, 256> DeclSet; |
Argyrios Kyrtzidis | 2810e9d | 2012-12-19 22:21:18 +0000 | [diff] [blame] | 6461 | bool VisitAll; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6462 | |
| 6463 | public: |
| 6464 | DeclContextAllNamesVisitor(ASTReader &Reader, |
| 6465 | SmallVectorImpl<const DeclContext *> &Contexts, |
Craig Topper | 3598eb7 | 2013-07-05 04:43:31 +0000 | [diff] [blame] | 6466 | DeclsMap &Decls, bool VisitAll) |
Argyrios Kyrtzidis | 2810e9d | 2012-12-19 22:21:18 +0000 | [diff] [blame] | 6467 | : Reader(Reader), Contexts(Contexts), Decls(Decls), VisitAll(VisitAll) { } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6468 | |
| 6469 | static bool visit(ModuleFile &M, void *UserData) { |
| 6470 | DeclContextAllNamesVisitor *This |
| 6471 | = static_cast<DeclContextAllNamesVisitor *>(UserData); |
| 6472 | |
| 6473 | // Check whether we have any visible declaration information for |
| 6474 | // this context in this module. |
| 6475 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 6476 | bool FoundInfo = false; |
| 6477 | for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) { |
| 6478 | Info = M.DeclContextInfos.find(This->Contexts[I]); |
| 6479 | if (Info != M.DeclContextInfos.end() && |
| 6480 | Info->second.NameLookupTableData) { |
| 6481 | FoundInfo = true; |
| 6482 | break; |
| 6483 | } |
| 6484 | } |
| 6485 | |
| 6486 | if (!FoundInfo) |
| 6487 | return false; |
| 6488 | |
Richard Smith | 52e3fba | 2014-03-11 07:17:35 +0000 | [diff] [blame] | 6489 | ASTDeclContextNameLookupTable *LookupTable = |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6490 | Info->second.NameLookupTableData; |
| 6491 | bool FoundAnything = false; |
| 6492 | for (ASTDeclContextNameLookupTable::data_iterator |
Douglas Gregor | 5e306b1 | 2013-01-23 22:38:11 +0000 | [diff] [blame] | 6493 | I = LookupTable->data_begin(), E = LookupTable->data_end(); |
| 6494 | I != E; |
| 6495 | ++I) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6496 | ASTDeclContextNameLookupTrait::data_type Data = *I; |
| 6497 | for (; Data.first != Data.second; ++Data.first) { |
| 6498 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, |
| 6499 | *Data.first); |
| 6500 | if (!ND) |
| 6501 | continue; |
| 6502 | |
| 6503 | // Record this declaration. |
| 6504 | FoundAnything = true; |
Richard Smith | 52874ec | 2015-02-13 20:17:14 +0000 | [diff] [blame] | 6505 | if (This->DeclSet.insert(ND).second) |
| 6506 | This->Decls[ND->getDeclName()].push_back(ND); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6507 | } |
| 6508 | } |
| 6509 | |
Argyrios Kyrtzidis | 2810e9d | 2012-12-19 22:21:18 +0000 | [diff] [blame] | 6510 | return FoundAnything && !This->VisitAll; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6511 | } |
| 6512 | }; |
| 6513 | } |
| 6514 | |
| 6515 | void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { |
| 6516 | if (!DC->hasExternalVisibleStorage()) |
| 6517 | return; |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 6518 | DeclsMap Decls; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6519 | |
| 6520 | // Compute the declaration contexts we need to look into. Multiple such |
| 6521 | // declaration contexts occur when two declaration contexts from disjoint |
| 6522 | // modules get merged, e.g., when two namespaces with the same name are |
| 6523 | // independently defined in separate modules. |
| 6524 | SmallVector<const DeclContext *, 2> Contexts; |
| 6525 | Contexts.push_back(DC); |
| 6526 | |
| 6527 | if (DC->isNamespace()) { |
| 6528 | MergedDeclsMap::iterator Merged |
| 6529 | = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
| 6530 | if (Merged != MergedDecls.end()) { |
| 6531 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 6532 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 6533 | } |
| 6534 | } |
| 6535 | |
Argyrios Kyrtzidis | 2810e9d | 2012-12-19 22:21:18 +0000 | [diff] [blame] | 6536 | DeclContextAllNamesVisitor Visitor(*this, Contexts, Decls, |
| 6537 | /*VisitAll=*/DC->isFileContext()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6538 | ModuleMgr.visit(&DeclContextAllNamesVisitor::visit, &Visitor); |
| 6539 | ++NumVisibleDeclContextsRead; |
| 6540 | |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 6541 | for (DeclsMap::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6542 | SetExternalVisibleDeclsForName(DC, I->first, I->second); |
| 6543 | } |
| 6544 | const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false); |
| 6545 | } |
| 6546 | |
| 6547 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 6548 | /// before receiving the implementation, and codegen depends on this. |
| 6549 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 6550 | /// implementation before passing the deserialized implementation decl. |
| 6551 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 6552 | ASTConsumer *Consumer) { |
| 6553 | assert(ImplD && Consumer); |
| 6554 | |
Aaron Ballman | aff18c0 | 2014-03-13 19:03:34 +0000 | [diff] [blame] | 6555 | for (auto *I : ImplD->methods()) |
| 6556 | Consumer->HandleInterestingDecl(DeclGroupRef(I)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6557 | |
| 6558 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 6559 | } |
| 6560 | |
| 6561 | void ASTReader::PassInterestingDeclsToConsumer() { |
| 6562 | assert(Consumer); |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 6563 | |
| 6564 | if (PassingDeclsToConsumer) |
| 6565 | return; |
| 6566 | |
| 6567 | // Guard variable to avoid recursively redoing the process of passing |
| 6568 | // decls to consumer. |
| 6569 | SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer, |
| 6570 | true); |
| 6571 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6572 | // Ensure that we've loaded all potentially-interesting declarations |
| 6573 | // that need to be eagerly loaded. |
| 6574 | for (auto ID : EagerlyDeserializedDecls) |
| 6575 | GetDecl(ID); |
| 6576 | EagerlyDeserializedDecls.clear(); |
| 6577 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6578 | while (!InterestingDecls.empty()) { |
| 6579 | Decl *D = InterestingDecls.front(); |
| 6580 | InterestingDecls.pop_front(); |
| 6581 | |
| 6582 | PassInterestingDeclToConsumer(D); |
| 6583 | } |
| 6584 | } |
| 6585 | |
| 6586 | void ASTReader::PassInterestingDeclToConsumer(Decl *D) { |
| 6587 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 6588 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 6589 | else |
| 6590 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
| 6591 | } |
| 6592 | |
| 6593 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
| 6594 | this->Consumer = Consumer; |
| 6595 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6596 | if (Consumer) |
| 6597 | PassInterestingDeclsToConsumer(); |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 6598 | |
| 6599 | if (DeserializationListener) |
| 6600 | DeserializationListener->ReaderInitialized(this); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6601 | } |
| 6602 | |
| 6603 | void ASTReader::PrintStats() { |
| 6604 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
| 6605 | |
| 6606 | unsigned NumTypesLoaded |
| 6607 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
| 6608 | QualType()); |
| 6609 | unsigned NumDeclsLoaded |
| 6610 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6611 | (Decl *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6612 | unsigned NumIdentifiersLoaded |
| 6613 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 6614 | IdentifiersLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6615 | (IdentifierInfo *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6616 | unsigned NumMacrosLoaded |
| 6617 | = MacrosLoaded.size() - std::count(MacrosLoaded.begin(), |
| 6618 | MacrosLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6619 | (MacroInfo *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6620 | unsigned NumSelectorsLoaded |
| 6621 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 6622 | SelectorsLoaded.end(), |
| 6623 | Selector()); |
| 6624 | |
| 6625 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
| 6626 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 6627 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 6628 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
| 6629 | if (!TypesLoaded.empty()) |
| 6630 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
| 6631 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 6632 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 6633 | if (!DeclsLoaded.empty()) |
| 6634 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
| 6635 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 6636 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
| 6637 | if (!IdentifiersLoaded.empty()) |
| 6638 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
| 6639 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 6640 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
| 6641 | if (!MacrosLoaded.empty()) |
| 6642 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 6643 | NumMacrosLoaded, (unsigned)MacrosLoaded.size(), |
| 6644 | ((float)NumMacrosLoaded/MacrosLoaded.size() * 100)); |
| 6645 | if (!SelectorsLoaded.empty()) |
| 6646 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
| 6647 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 6648 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
| 6649 | if (TotalNumStatements) |
| 6650 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 6651 | NumStatementsRead, TotalNumStatements, |
| 6652 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 6653 | if (TotalNumMacros) |
| 6654 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 6655 | NumMacrosRead, TotalNumMacros, |
| 6656 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 6657 | if (TotalLexicalDeclContexts) |
| 6658 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 6659 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 6660 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 6661 | * 100)); |
| 6662 | if (TotalVisibleDeclContexts) |
| 6663 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 6664 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 6665 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 6666 | * 100)); |
| 6667 | if (TotalNumMethodPoolEntries) { |
| 6668 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
| 6669 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 6670 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
| 6671 | * 100)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6672 | } |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 6673 | if (NumMethodPoolLookups) { |
| 6674 | std::fprintf(stderr, " %u/%u method pool lookups succeeded (%f%%)\n", |
| 6675 | NumMethodPoolHits, NumMethodPoolLookups, |
| 6676 | ((float)NumMethodPoolHits/NumMethodPoolLookups * 100.0)); |
| 6677 | } |
| 6678 | if (NumMethodPoolTableLookups) { |
| 6679 | std::fprintf(stderr, " %u/%u method pool table lookups succeeded (%f%%)\n", |
| 6680 | NumMethodPoolTableHits, NumMethodPoolTableLookups, |
| 6681 | ((float)NumMethodPoolTableHits/NumMethodPoolTableLookups |
| 6682 | * 100.0)); |
| 6683 | } |
| 6684 | |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 6685 | if (NumIdentifierLookupHits) { |
| 6686 | std::fprintf(stderr, |
| 6687 | " %u / %u identifier table lookups succeeded (%f%%)\n", |
| 6688 | NumIdentifierLookupHits, NumIdentifierLookups, |
| 6689 | (double)NumIdentifierLookupHits*100.0/NumIdentifierLookups); |
| 6690 | } |
| 6691 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 6692 | if (GlobalIndex) { |
| 6693 | std::fprintf(stderr, "\n"); |
| 6694 | GlobalIndex->printStats(); |
| 6695 | } |
| 6696 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6697 | std::fprintf(stderr, "\n"); |
| 6698 | dump(); |
| 6699 | std::fprintf(stderr, "\n"); |
| 6700 | } |
| 6701 | |
| 6702 | template<typename Key, typename ModuleFile, unsigned InitialCapacity> |
| 6703 | static void |
| 6704 | dumpModuleIDMap(StringRef Name, |
| 6705 | const ContinuousRangeMap<Key, ModuleFile *, |
| 6706 | InitialCapacity> &Map) { |
| 6707 | if (Map.begin() == Map.end()) |
| 6708 | return; |
| 6709 | |
| 6710 | typedef ContinuousRangeMap<Key, ModuleFile *, InitialCapacity> MapType; |
| 6711 | llvm::errs() << Name << ":\n"; |
| 6712 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 6713 | I != IEnd; ++I) { |
| 6714 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 6715 | << "\n"; |
| 6716 | } |
| 6717 | } |
| 6718 | |
| 6719 | void ASTReader::dump() { |
| 6720 | llvm::errs() << "*** PCH/ModuleFile Remappings:\n"; |
| 6721 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
| 6722 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
| 6723 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
| 6724 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
| 6725 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 6726 | dumpModuleIDMap("Global macro map", GlobalMacroMap); |
| 6727 | dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap); |
| 6728 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
| 6729 | dumpModuleIDMap("Global preprocessed entity map", |
| 6730 | GlobalPreprocessedEntityMap); |
| 6731 | |
| 6732 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 6733 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 6734 | MEnd = ModuleMgr.end(); |
| 6735 | M != MEnd; ++M) |
| 6736 | (*M)->dump(); |
| 6737 | } |
| 6738 | |
| 6739 | /// Return the amount of memory used by memory buffers, breaking down |
| 6740 | /// by heap-backed versus mmap'ed memory. |
| 6741 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
| 6742 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 6743 | E = ModuleMgr.end(); I != E; ++I) { |
| 6744 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
| 6745 | size_t bytes = buf->getBufferSize(); |
| 6746 | switch (buf->getBufferKind()) { |
| 6747 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 6748 | sizes.malloc_bytes += bytes; |
| 6749 | break; |
| 6750 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 6751 | sizes.mmap_bytes += bytes; |
| 6752 | break; |
| 6753 | } |
| 6754 | } |
| 6755 | } |
| 6756 | } |
| 6757 | |
| 6758 | void ASTReader::InitializeSema(Sema &S) { |
| 6759 | SemaObj = &S; |
| 6760 | S.addExternalSource(this); |
| 6761 | |
| 6762 | // Makes sure any declarations that were deserialized "too early" |
| 6763 | // still get added to the identifier's declaration chains. |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 6764 | for (uint64_t ID : PreloadedDeclIDs) { |
| 6765 | NamedDecl *D = cast<NamedDecl>(GetDecl(ID)); |
| 6766 | pushExternalDeclIntoScope(D, D->getDeclName()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6767 | } |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 6768 | PreloadedDeclIDs.clear(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6769 | |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 6770 | // FIXME: What happens if these are changed by a module import? |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6771 | if (!FPPragmaOptions.empty()) { |
| 6772 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 6773 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 6774 | } |
| 6775 | |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 6776 | // FIXME: What happens if these are changed by a module import? |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6777 | if (!OpenCLExtensions.empty()) { |
| 6778 | unsigned I = 0; |
| 6779 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 6780 | #include "clang/Basic/OpenCLExtensions.def" |
| 6781 | |
| 6782 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 6783 | } |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 6784 | |
| 6785 | UpdateSema(); |
| 6786 | } |
| 6787 | |
| 6788 | void ASTReader::UpdateSema() { |
| 6789 | assert(SemaObj && "no Sema to update"); |
| 6790 | |
| 6791 | // Load the offsets of the declarations that Sema references. |
| 6792 | // They will be lazily deserialized when needed. |
| 6793 | if (!SemaDeclRefs.empty()) { |
| 6794 | assert(SemaDeclRefs.size() % 2 == 0); |
| 6795 | for (unsigned I = 0; I != SemaDeclRefs.size(); I += 2) { |
| 6796 | if (!SemaObj->StdNamespace) |
| 6797 | SemaObj->StdNamespace = SemaDeclRefs[I]; |
| 6798 | if (!SemaObj->StdBadAlloc) |
| 6799 | SemaObj->StdBadAlloc = SemaDeclRefs[I+1]; |
| 6800 | } |
| 6801 | SemaDeclRefs.clear(); |
| 6802 | } |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 6803 | |
| 6804 | // Update the state of 'pragma clang optimize'. Use the same API as if we had |
| 6805 | // encountered the pragma in the source. |
| 6806 | if(OptimizeOffPragmaLocation.isValid()) |
| 6807 | SemaObj->ActOnPragmaOptimize(/* IsOn = */ false, OptimizeOffPragmaLocation); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6808 | } |
| 6809 | |
| 6810 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
| 6811 | // Note that we are loading an identifier. |
| 6812 | Deserializing AnIdentifier(this); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 6813 | StringRef Name(NameStart, NameEnd - NameStart); |
| 6814 | |
| 6815 | // If there is a global index, look there first to determine which modules |
| 6816 | // provably do not have any results for this identifier. |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 6817 | GlobalModuleIndex::HitSet Hits; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6818 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 6819 | if (!loadGlobalIndex()) { |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 6820 | if (GlobalIndex->lookupIdentifier(Name, Hits)) { |
| 6821 | HitsPtr = &Hits; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 6822 | } |
| 6823 | } |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 6824 | IdentifierLookupVisitor Visitor(Name, /*PriorGeneration=*/0, |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 6825 | NumIdentifierLookups, |
| 6826 | NumIdentifierLookupHits); |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 6827 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor, HitsPtr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6828 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
| 6829 | markIdentifierUpToDate(II); |
| 6830 | return II; |
| 6831 | } |
| 6832 | |
| 6833 | namespace clang { |
| 6834 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 6835 | /// identifiers stored within a set of AST files. |
| 6836 | class ASTIdentifierIterator : public IdentifierIterator { |
| 6837 | /// \brief The AST reader whose identifiers are being enumerated. |
| 6838 | const ASTReader &Reader; |
| 6839 | |
| 6840 | /// \brief The current index into the chain of AST files stored in |
| 6841 | /// the AST reader. |
| 6842 | unsigned Index; |
| 6843 | |
| 6844 | /// \brief The current position within the identifier lookup table |
| 6845 | /// of the current AST file. |
| 6846 | ASTIdentifierLookupTable::key_iterator Current; |
| 6847 | |
| 6848 | /// \brief The end position within the identifier lookup table of |
| 6849 | /// the current AST file. |
| 6850 | ASTIdentifierLookupTable::key_iterator End; |
| 6851 | |
| 6852 | public: |
| 6853 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 6854 | |
Craig Topper | 3e89dfe | 2014-03-13 02:13:41 +0000 | [diff] [blame] | 6855 | StringRef Next() override; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6856 | }; |
| 6857 | } |
| 6858 | |
| 6859 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 6860 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
| 6861 | ASTIdentifierLookupTable *IdTable |
| 6862 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
| 6863 | Current = IdTable->key_begin(); |
| 6864 | End = IdTable->key_end(); |
| 6865 | } |
| 6866 | |
| 6867 | StringRef ASTIdentifierIterator::Next() { |
| 6868 | while (Current == End) { |
| 6869 | // If we have exhausted all of our AST files, we're done. |
| 6870 | if (Index == 0) |
| 6871 | return StringRef(); |
| 6872 | |
| 6873 | --Index; |
| 6874 | ASTIdentifierLookupTable *IdTable |
| 6875 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 6876 | IdentifierLookupTable; |
| 6877 | Current = IdTable->key_begin(); |
| 6878 | End = IdTable->key_end(); |
| 6879 | } |
| 6880 | |
| 6881 | // We have any identifiers remaining in the current AST file; return |
| 6882 | // the next one. |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 6883 | StringRef Result = *Current; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6884 | ++Current; |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 6885 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6886 | } |
| 6887 | |
Argyrios Kyrtzidis | 9aca3c6 | 2013-04-17 22:10:55 +0000 | [diff] [blame] | 6888 | IdentifierIterator *ASTReader::getIdentifiers() { |
| 6889 | if (!loadGlobalIndex()) |
| 6890 | return GlobalIndex->createIdentifierIterator(); |
| 6891 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6892 | return new ASTIdentifierIterator(*this); |
| 6893 | } |
| 6894 | |
| 6895 | namespace clang { namespace serialization { |
| 6896 | class ReadMethodPoolVisitor { |
| 6897 | ASTReader &Reader; |
| 6898 | Selector Sel; |
| 6899 | unsigned PriorGeneration; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 6900 | unsigned InstanceBits; |
| 6901 | unsigned FactoryBits; |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 6902 | bool InstanceHasMoreThanOneDecl; |
| 6903 | bool FactoryHasMoreThanOneDecl; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 6904 | SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 6905 | SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6906 | |
| 6907 | public: |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 6908 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6909 | unsigned PriorGeneration) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 6910 | : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration), |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 6911 | InstanceBits(0), FactoryBits(0), InstanceHasMoreThanOneDecl(false), |
| 6912 | FactoryHasMoreThanOneDecl(false) {} |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 6913 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6914 | static bool visit(ModuleFile &M, void *UserData) { |
| 6915 | ReadMethodPoolVisitor *This |
| 6916 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 6917 | |
| 6918 | if (!M.SelectorLookupTable) |
| 6919 | return false; |
| 6920 | |
| 6921 | // If we've already searched this module file, skip it now. |
| 6922 | if (M.Generation <= This->PriorGeneration) |
| 6923 | return true; |
| 6924 | |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 6925 | ++This->Reader.NumMethodPoolTableLookups; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6926 | ASTSelectorLookupTable *PoolTable |
| 6927 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 6928 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 6929 | if (Pos == PoolTable->end()) |
| 6930 | return false; |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 6931 | |
| 6932 | ++This->Reader.NumMethodPoolTableHits; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6933 | ++This->Reader.NumSelectorsRead; |
| 6934 | // FIXME: Not quite happy with the statistics here. We probably should |
| 6935 | // disable this tracking when called via LoadSelector. |
| 6936 | // Also, should entries without methods count as misses? |
| 6937 | ++This->Reader.NumMethodPoolEntriesRead; |
| 6938 | ASTSelectorLookupTrait::data_type Data = *Pos; |
| 6939 | if (This->Reader.DeserializationListener) |
| 6940 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 6941 | This->Sel); |
| 6942 | |
| 6943 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 6944 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 6945 | This->InstanceBits = Data.InstanceBits; |
| 6946 | This->FactoryBits = Data.FactoryBits; |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 6947 | This->InstanceHasMoreThanOneDecl = Data.InstanceHasMoreThanOneDecl; |
| 6948 | This->FactoryHasMoreThanOneDecl = Data.FactoryHasMoreThanOneDecl; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6949 | return true; |
| 6950 | } |
| 6951 | |
| 6952 | /// \brief Retrieve the instance methods found by this visitor. |
| 6953 | ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { |
| 6954 | return InstanceMethods; |
| 6955 | } |
| 6956 | |
| 6957 | /// \brief Retrieve the instance methods found by this visitor. |
| 6958 | ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { |
| 6959 | return FactoryMethods; |
| 6960 | } |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 6961 | |
| 6962 | unsigned getInstanceBits() const { return InstanceBits; } |
| 6963 | unsigned getFactoryBits() const { return FactoryBits; } |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 6964 | bool instanceHasMoreThanOneDecl() const { |
| 6965 | return InstanceHasMoreThanOneDecl; |
| 6966 | } |
| 6967 | bool factoryHasMoreThanOneDecl() const { return FactoryHasMoreThanOneDecl; } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6968 | }; |
| 6969 | } } // end namespace clang::serialization |
| 6970 | |
| 6971 | /// \brief Add the given set of methods to the method list. |
| 6972 | static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, |
| 6973 | ObjCMethodList &List) { |
| 6974 | for (unsigned I = 0, N = Methods.size(); I != N; ++I) { |
| 6975 | S.addMethodToGlobalList(&List, Methods[I]); |
| 6976 | } |
| 6977 | } |
| 6978 | |
| 6979 | void ASTReader::ReadMethodPool(Selector Sel) { |
| 6980 | // Get the selector generation and update it to the current generation. |
| 6981 | unsigned &Generation = SelectorGeneration[Sel]; |
| 6982 | unsigned PriorGeneration = Generation; |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6983 | Generation = getGeneration(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6984 | |
| 6985 | // Search for methods defined with this selector. |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 6986 | ++NumMethodPoolLookups; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6987 | ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration); |
| 6988 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
| 6989 | |
| 6990 | if (Visitor.getInstanceMethods().empty() && |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 6991 | Visitor.getFactoryMethods().empty()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6992 | return; |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 6993 | |
| 6994 | ++NumMethodPoolHits; |
| 6995 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6996 | if (!getSema()) |
| 6997 | return; |
| 6998 | |
| 6999 | Sema &S = *getSema(); |
| 7000 | Sema::GlobalMethodPool::iterator Pos |
| 7001 | = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; |
Ben Langmuir | a0c32e9 | 2015-01-12 19:27:00 +0000 | [diff] [blame] | 7002 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7003 | Pos->second.first.setBits(Visitor.getInstanceBits()); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7004 | Pos->second.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl()); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7005 | Pos->second.second.setBits(Visitor.getFactoryBits()); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7006 | Pos->second.second.setHasMoreThanOneDecl(Visitor.factoryHasMoreThanOneDecl()); |
Ben Langmuir | a0c32e9 | 2015-01-12 19:27:00 +0000 | [diff] [blame] | 7007 | |
| 7008 | // Add methods to the global pool *after* setting hasMoreThanOneDecl, since |
| 7009 | // when building a module we keep every method individually and may need to |
| 7010 | // update hasMoreThanOneDecl as we add the methods. |
| 7011 | addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); |
| 7012 | addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7013 | } |
| 7014 | |
| 7015 | void ASTReader::ReadKnownNamespaces( |
| 7016 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
| 7017 | Namespaces.clear(); |
| 7018 | |
| 7019 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 7020 | if (NamespaceDecl *Namespace |
| 7021 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 7022 | Namespaces.push_back(Namespace); |
| 7023 | } |
| 7024 | } |
| 7025 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7026 | void ASTReader::ReadUndefinedButUsed( |
Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 7027 | llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7028 | for (unsigned Idx = 0, N = UndefinedButUsed.size(); Idx != N;) { |
| 7029 | NamedDecl *D = cast<NamedDecl>(GetDecl(UndefinedButUsed[Idx++])); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7030 | SourceLocation Loc = |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7031 | SourceLocation::getFromRawEncoding(UndefinedButUsed[Idx++]); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7032 | Undefined.insert(std::make_pair(D, Loc)); |
| 7033 | } |
| 7034 | } |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7035 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7036 | void ASTReader::ReadTentativeDefinitions( |
| 7037 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 7038 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 7039 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 7040 | if (Var) |
| 7041 | TentativeDefs.push_back(Var); |
| 7042 | } |
| 7043 | TentativeDefinitions.clear(); |
| 7044 | } |
| 7045 | |
| 7046 | void ASTReader::ReadUnusedFileScopedDecls( |
| 7047 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 7048 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 7049 | DeclaratorDecl *D |
| 7050 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 7051 | if (D) |
| 7052 | Decls.push_back(D); |
| 7053 | } |
| 7054 | UnusedFileScopedDecls.clear(); |
| 7055 | } |
| 7056 | |
| 7057 | void ASTReader::ReadDelegatingConstructors( |
| 7058 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 7059 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 7060 | CXXConstructorDecl *D |
| 7061 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 7062 | if (D) |
| 7063 | Decls.push_back(D); |
| 7064 | } |
| 7065 | DelegatingCtorDecls.clear(); |
| 7066 | } |
| 7067 | |
| 7068 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 7069 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 7070 | TypedefNameDecl *D |
| 7071 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 7072 | if (D) |
| 7073 | Decls.push_back(D); |
| 7074 | } |
| 7075 | ExtVectorDecls.clear(); |
| 7076 | } |
| 7077 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 7078 | void ASTReader::ReadUnusedLocalTypedefNameCandidates( |
| 7079 | llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) { |
| 7080 | for (unsigned I = 0, N = UnusedLocalTypedefNameCandidates.size(); I != N; |
| 7081 | ++I) { |
| 7082 | TypedefNameDecl *D = dyn_cast_or_null<TypedefNameDecl>( |
| 7083 | GetDecl(UnusedLocalTypedefNameCandidates[I])); |
| 7084 | if (D) |
| 7085 | Decls.insert(D); |
| 7086 | } |
| 7087 | UnusedLocalTypedefNameCandidates.clear(); |
| 7088 | } |
| 7089 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7090 | void ASTReader::ReadReferencedSelectors( |
| 7091 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 7092 | if (ReferencedSelectorsData.empty()) |
| 7093 | return; |
| 7094 | |
| 7095 | // If there are @selector references added them to its pool. This is for |
| 7096 | // implementation of -Wselector. |
| 7097 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 7098 | unsigned I = 0; |
| 7099 | while (I < DataSize) { |
| 7100 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 7101 | SourceLocation SelLoc |
| 7102 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 7103 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 7104 | } |
| 7105 | ReferencedSelectorsData.clear(); |
| 7106 | } |
| 7107 | |
| 7108 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 7109 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 7110 | if (WeakUndeclaredIdentifiers.empty()) |
| 7111 | return; |
| 7112 | |
| 7113 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 7114 | IdentifierInfo *WeakId |
| 7115 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 7116 | IdentifierInfo *AliasId |
| 7117 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 7118 | SourceLocation Loc |
| 7119 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 7120 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 7121 | WeakInfo WI(AliasId, Loc); |
| 7122 | WI.setUsed(Used); |
| 7123 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 7124 | } |
| 7125 | WeakUndeclaredIdentifiers.clear(); |
| 7126 | } |
| 7127 | |
| 7128 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 7129 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 7130 | ExternalVTableUse VT; |
| 7131 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 7132 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 7133 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 7134 | VTables.push_back(VT); |
| 7135 | } |
| 7136 | |
| 7137 | VTableUses.clear(); |
| 7138 | } |
| 7139 | |
| 7140 | void ASTReader::ReadPendingInstantiations( |
| 7141 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 7142 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 7143 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 7144 | SourceLocation Loc |
| 7145 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 7146 | |
| 7147 | Pending.push_back(std::make_pair(D, Loc)); |
| 7148 | } |
| 7149 | PendingInstantiations.clear(); |
| 7150 | } |
| 7151 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 7152 | void ASTReader::ReadLateParsedTemplates( |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 7153 | llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) { |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 7154 | for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N; |
| 7155 | /* In loop */) { |
| 7156 | FunctionDecl *FD = cast<FunctionDecl>(GetDecl(LateParsedTemplates[Idx++])); |
| 7157 | |
| 7158 | LateParsedTemplate *LT = new LateParsedTemplate; |
| 7159 | LT->D = GetDecl(LateParsedTemplates[Idx++]); |
| 7160 | |
| 7161 | ModuleFile *F = getOwningModuleFile(LT->D); |
| 7162 | assert(F && "No module"); |
| 7163 | |
| 7164 | unsigned TokN = LateParsedTemplates[Idx++]; |
| 7165 | LT->Toks.reserve(TokN); |
| 7166 | for (unsigned T = 0; T < TokN; ++T) |
| 7167 | LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx)); |
| 7168 | |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 7169 | LPTMap.insert(std::make_pair(FD, LT)); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 7170 | } |
| 7171 | |
| 7172 | LateParsedTemplates.clear(); |
| 7173 | } |
| 7174 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7175 | void ASTReader::LoadSelector(Selector Sel) { |
| 7176 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 7177 | ReadMethodPool(Sel); |
| 7178 | } |
| 7179 | |
| 7180 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
| 7181 | assert(ID && "Non-zero identifier ID required"); |
| 7182 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
| 7183 | IdentifiersLoaded[ID - 1] = II; |
| 7184 | if (DeserializationListener) |
| 7185 | DeserializationListener->IdentifierRead(ID, II); |
| 7186 | } |
| 7187 | |
| 7188 | /// \brief Set the globally-visible declarations associated with the given |
| 7189 | /// identifier. |
| 7190 | /// |
| 7191 | /// If the AST reader is currently in a state where the given declaration IDs |
| 7192 | /// cannot safely be resolved, they are queued until it is safe to resolve |
| 7193 | /// them. |
| 7194 | /// |
| 7195 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 7196 | /// declarations. |
| 7197 | /// |
| 7198 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 7199 | /// visible at global scope. |
| 7200 | /// |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 7201 | /// \param Decls if non-null, this vector will be populated with the set of |
| 7202 | /// deserialized declarations. These declarations will not be pushed into |
| 7203 | /// scope. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7204 | void |
| 7205 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
| 7206 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 7207 | SmallVectorImpl<Decl *> *Decls) { |
| 7208 | if (NumCurrentElementsDeserializing && !Decls) { |
| 7209 | PendingIdentifierInfos[II].append(DeclIDs.begin(), DeclIDs.end()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7210 | return; |
| 7211 | } |
| 7212 | |
| 7213 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7214 | if (!SemaObj) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7215 | // Queue this declaration so that it will be added to the |
| 7216 | // translation unit scope and identifier's declaration chain |
| 7217 | // once a Sema object is known. |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7218 | PreloadedDeclIDs.push_back(DeclIDs[I]); |
| 7219 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7220 | } |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7221 | |
| 7222 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 7223 | |
| 7224 | // If we're simply supposed to record the declarations, do so now. |
| 7225 | if (Decls) { |
| 7226 | Decls->push_back(D); |
| 7227 | continue; |
| 7228 | } |
| 7229 | |
| 7230 | // Introduce this declaration into the translation-unit scope |
| 7231 | // and add it to the declaration chain for this identifier, so |
| 7232 | // that (unqualified) name lookup will find it. |
| 7233 | pushExternalDeclIntoScope(D, II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7234 | } |
| 7235 | } |
| 7236 | |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 7237 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7238 | if (ID == 0) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7239 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7240 | |
| 7241 | if (IdentifiersLoaded.empty()) { |
| 7242 | Error("no identifier table in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7243 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7244 | } |
| 7245 | |
| 7246 | ID -= 1; |
| 7247 | if (!IdentifiersLoaded[ID]) { |
| 7248 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 7249 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
| 7250 | ModuleFile *M = I->second; |
| 7251 | unsigned Index = ID - M->BaseIdentifierID; |
| 7252 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
| 7253 | |
| 7254 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 7255 | // Extract that 16-bit length to avoid having to execute strlen(). |
| 7256 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 7257 | // unsigned integers. This is important to avoid integer overflow when |
| 7258 | // we cast them to 'unsigned'. |
| 7259 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
| 7260 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 7261 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 7262 | IdentifiersLoaded[ID] |
| 7263 | = &PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7264 | if (DeserializationListener) |
| 7265 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
| 7266 | } |
| 7267 | |
| 7268 | return IdentifiersLoaded[ID]; |
| 7269 | } |
| 7270 | |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 7271 | IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) { |
| 7272 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7273 | } |
| 7274 | |
| 7275 | IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { |
| 7276 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 7277 | return LocalID; |
| 7278 | |
| 7279 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 7280 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 7281 | assert(I != M.IdentifierRemap.end() |
| 7282 | && "Invalid index into identifier index remap"); |
| 7283 | |
| 7284 | return LocalID + I->second; |
| 7285 | } |
| 7286 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 7287 | MacroInfo *ASTReader::getMacro(MacroID ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7288 | if (ID == 0) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7289 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7290 | |
| 7291 | if (MacrosLoaded.empty()) { |
| 7292 | Error("no macro table in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7293 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7294 | } |
| 7295 | |
| 7296 | ID -= NUM_PREDEF_MACRO_IDS; |
| 7297 | if (!MacrosLoaded[ID]) { |
| 7298 | GlobalMacroMapType::iterator I |
| 7299 | = GlobalMacroMap.find(ID + NUM_PREDEF_MACRO_IDS); |
| 7300 | assert(I != GlobalMacroMap.end() && "Corrupted global macro map"); |
| 7301 | ModuleFile *M = I->second; |
| 7302 | unsigned Index = ID - M->BaseMacroID; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 7303 | MacrosLoaded[ID] = ReadMacroRecord(*M, M->MacroOffsets[Index]); |
| 7304 | |
| 7305 | if (DeserializationListener) |
| 7306 | DeserializationListener->MacroRead(ID + NUM_PREDEF_MACRO_IDS, |
| 7307 | MacrosLoaded[ID]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7308 | } |
| 7309 | |
| 7310 | return MacrosLoaded[ID]; |
| 7311 | } |
| 7312 | |
| 7313 | MacroID ASTReader::getGlobalMacroID(ModuleFile &M, unsigned LocalID) { |
| 7314 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 7315 | return LocalID; |
| 7316 | |
| 7317 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 7318 | = M.MacroRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 7319 | assert(I != M.MacroRemap.end() && "Invalid index into macro index remap"); |
| 7320 | |
| 7321 | return LocalID + I->second; |
| 7322 | } |
| 7323 | |
| 7324 | serialization::SubmoduleID |
| 7325 | ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) { |
| 7326 | if (LocalID < NUM_PREDEF_SUBMODULE_IDS) |
| 7327 | return LocalID; |
| 7328 | |
| 7329 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 7330 | = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS); |
| 7331 | assert(I != M.SubmoduleRemap.end() |
| 7332 | && "Invalid index into submodule index remap"); |
| 7333 | |
| 7334 | return LocalID + I->second; |
| 7335 | } |
| 7336 | |
| 7337 | Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { |
| 7338 | if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) { |
| 7339 | assert(GlobalID == 0 && "Unhandled global submodule ID"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7340 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7341 | } |
| 7342 | |
| 7343 | if (GlobalID > SubmodulesLoaded.size()) { |
| 7344 | Error("submodule ID out of range in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7345 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7346 | } |
| 7347 | |
| 7348 | return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; |
| 7349 | } |
Douglas Gregor | c147b0b | 2013-01-12 01:29:50 +0000 | [diff] [blame] | 7350 | |
| 7351 | Module *ASTReader::getModule(unsigned ID) { |
| 7352 | return getSubmodule(ID); |
| 7353 | } |
| 7354 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7355 | Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { |
| 7356 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 7357 | } |
| 7358 | |
| 7359 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
| 7360 | if (ID == 0) |
| 7361 | return Selector(); |
| 7362 | |
| 7363 | if (ID > SelectorsLoaded.size()) { |
| 7364 | Error("selector ID out of range in AST file"); |
| 7365 | return Selector(); |
| 7366 | } |
| 7367 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7368 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == nullptr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7369 | // Load this selector from the selector table. |
| 7370 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 7371 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
| 7372 | ModuleFile &M = *I->second; |
| 7373 | ASTSelectorLookupTrait Trait(*this, M); |
| 7374 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
| 7375 | SelectorsLoaded[ID - 1] = |
| 7376 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
| 7377 | if (DeserializationListener) |
| 7378 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 7379 | } |
| 7380 | |
| 7381 | return SelectorsLoaded[ID - 1]; |
| 7382 | } |
| 7383 | |
| 7384 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
| 7385 | return DecodeSelector(ID); |
| 7386 | } |
| 7387 | |
| 7388 | uint32_t ASTReader::GetNumExternalSelectors() { |
| 7389 | // ID 0 (the null selector) is considered an external selector. |
| 7390 | return getTotalNumSelectors() + 1; |
| 7391 | } |
| 7392 | |
| 7393 | serialization::SelectorID |
| 7394 | ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { |
| 7395 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 7396 | return LocalID; |
| 7397 | |
| 7398 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 7399 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 7400 | assert(I != M.SelectorRemap.end() |
| 7401 | && "Invalid index into selector index remap"); |
| 7402 | |
| 7403 | return LocalID + I->second; |
| 7404 | } |
| 7405 | |
| 7406 | DeclarationName |
| 7407 | ASTReader::ReadDeclarationName(ModuleFile &F, |
| 7408 | const RecordData &Record, unsigned &Idx) { |
| 7409 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 7410 | switch (Kind) { |
| 7411 | case DeclarationName::Identifier: |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 7412 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7413 | |
| 7414 | case DeclarationName::ObjCZeroArgSelector: |
| 7415 | case DeclarationName::ObjCOneArgSelector: |
| 7416 | case DeclarationName::ObjCMultiArgSelector: |
| 7417 | return DeclarationName(ReadSelector(F, Record, Idx)); |
| 7418 | |
| 7419 | case DeclarationName::CXXConstructorName: |
| 7420 | return Context.DeclarationNames.getCXXConstructorName( |
| 7421 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 7422 | |
| 7423 | case DeclarationName::CXXDestructorName: |
| 7424 | return Context.DeclarationNames.getCXXDestructorName( |
| 7425 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 7426 | |
| 7427 | case DeclarationName::CXXConversionFunctionName: |
| 7428 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 7429 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 7430 | |
| 7431 | case DeclarationName::CXXOperatorName: |
| 7432 | return Context.DeclarationNames.getCXXOperatorName( |
| 7433 | (OverloadedOperatorKind)Record[Idx++]); |
| 7434 | |
| 7435 | case DeclarationName::CXXLiteralOperatorName: |
| 7436 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
| 7437 | GetIdentifierInfo(F, Record, Idx)); |
| 7438 | |
| 7439 | case DeclarationName::CXXUsingDirective: |
| 7440 | return DeclarationName::getUsingDirectiveName(); |
| 7441 | } |
| 7442 | |
| 7443 | llvm_unreachable("Invalid NameKind!"); |
| 7444 | } |
| 7445 | |
| 7446 | void ASTReader::ReadDeclarationNameLoc(ModuleFile &F, |
| 7447 | DeclarationNameLoc &DNLoc, |
| 7448 | DeclarationName Name, |
| 7449 | const RecordData &Record, unsigned &Idx) { |
| 7450 | switch (Name.getNameKind()) { |
| 7451 | case DeclarationName::CXXConstructorName: |
| 7452 | case DeclarationName::CXXDestructorName: |
| 7453 | case DeclarationName::CXXConversionFunctionName: |
| 7454 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 7455 | break; |
| 7456 | |
| 7457 | case DeclarationName::CXXOperatorName: |
| 7458 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 7459 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 7460 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 7461 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 7462 | break; |
| 7463 | |
| 7464 | case DeclarationName::CXXLiteralOperatorName: |
| 7465 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 7466 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 7467 | break; |
| 7468 | |
| 7469 | case DeclarationName::Identifier: |
| 7470 | case DeclarationName::ObjCZeroArgSelector: |
| 7471 | case DeclarationName::ObjCOneArgSelector: |
| 7472 | case DeclarationName::ObjCMultiArgSelector: |
| 7473 | case DeclarationName::CXXUsingDirective: |
| 7474 | break; |
| 7475 | } |
| 7476 | } |
| 7477 | |
| 7478 | void ASTReader::ReadDeclarationNameInfo(ModuleFile &F, |
| 7479 | DeclarationNameInfo &NameInfo, |
| 7480 | const RecordData &Record, unsigned &Idx) { |
| 7481 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
| 7482 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 7483 | DeclarationNameLoc DNLoc; |
| 7484 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 7485 | NameInfo.setInfo(DNLoc); |
| 7486 | } |
| 7487 | |
| 7488 | void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, |
| 7489 | const RecordData &Record, unsigned &Idx) { |
| 7490 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
| 7491 | unsigned NumTPLists = Record[Idx++]; |
| 7492 | Info.NumTemplParamLists = NumTPLists; |
| 7493 | if (NumTPLists) { |
| 7494 | Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; |
| 7495 | for (unsigned i=0; i != NumTPLists; ++i) |
| 7496 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 7497 | } |
| 7498 | } |
| 7499 | |
| 7500 | TemplateName |
| 7501 | ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, |
| 7502 | unsigned &Idx) { |
| 7503 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
| 7504 | switch (Kind) { |
| 7505 | case TemplateName::Template: |
| 7506 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
| 7507 | |
| 7508 | case TemplateName::OverloadedTemplate: { |
| 7509 | unsigned size = Record[Idx++]; |
| 7510 | UnresolvedSet<8> Decls; |
| 7511 | while (size--) |
| 7512 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
| 7513 | |
| 7514 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 7515 | } |
| 7516 | |
| 7517 | case TemplateName::QualifiedTemplate: { |
| 7518 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
| 7519 | bool hasTemplKeyword = Record[Idx++]; |
| 7520 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
| 7521 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 7522 | } |
| 7523 | |
| 7524 | case TemplateName::DependentTemplate: { |
| 7525 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
| 7526 | if (Record[Idx++]) // isIdentifier |
| 7527 | return Context.getDependentTemplateName(NNS, |
| 7528 | GetIdentifierInfo(F, Record, |
| 7529 | Idx)); |
| 7530 | return Context.getDependentTemplateName(NNS, |
| 7531 | (OverloadedOperatorKind)Record[Idx++]); |
| 7532 | } |
| 7533 | |
| 7534 | case TemplateName::SubstTemplateTemplateParm: { |
| 7535 | TemplateTemplateParmDecl *param |
| 7536 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
| 7537 | if (!param) return TemplateName(); |
| 7538 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
| 7539 | return Context.getSubstTemplateTemplateParm(param, replacement); |
| 7540 | } |
| 7541 | |
| 7542 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 7543 | TemplateTemplateParmDecl *Param |
| 7544 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
| 7545 | if (!Param) |
| 7546 | return TemplateName(); |
| 7547 | |
| 7548 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 7549 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 7550 | return TemplateName(); |
| 7551 | |
| 7552 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 7553 | } |
| 7554 | } |
| 7555 | |
| 7556 | llvm_unreachable("Unhandled template name kind!"); |
| 7557 | } |
| 7558 | |
| 7559 | TemplateArgument |
| 7560 | ASTReader::ReadTemplateArgument(ModuleFile &F, |
| 7561 | const RecordData &Record, unsigned &Idx) { |
| 7562 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 7563 | switch (Kind) { |
| 7564 | case TemplateArgument::Null: |
| 7565 | return TemplateArgument(); |
| 7566 | case TemplateArgument::Type: |
| 7567 | return TemplateArgument(readType(F, Record, Idx)); |
| 7568 | case TemplateArgument::Declaration: { |
| 7569 | ValueDecl *D = ReadDeclAs<ValueDecl>(F, Record, Idx); |
David Blaikie | 0f62c8d | 2014-10-16 04:21:25 +0000 | [diff] [blame] | 7570 | return TemplateArgument(D, readType(F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7571 | } |
| 7572 | case TemplateArgument::NullPtr: |
| 7573 | return TemplateArgument(readType(F, Record, Idx), /*isNullPtr*/true); |
| 7574 | case TemplateArgument::Integral: { |
| 7575 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 7576 | QualType T = readType(F, Record, Idx); |
| 7577 | return TemplateArgument(Context, Value, T); |
| 7578 | } |
| 7579 | case TemplateArgument::Template: |
| 7580 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
| 7581 | case TemplateArgument::TemplateExpansion: { |
| 7582 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 7583 | Optional<unsigned> NumTemplateExpansions; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7584 | if (unsigned NumExpansions = Record[Idx++]) |
| 7585 | NumTemplateExpansions = NumExpansions - 1; |
| 7586 | return TemplateArgument(Name, NumTemplateExpansions); |
| 7587 | } |
| 7588 | case TemplateArgument::Expression: |
| 7589 | return TemplateArgument(ReadExpr(F)); |
| 7590 | case TemplateArgument::Pack: { |
| 7591 | unsigned NumArgs = Record[Idx++]; |
| 7592 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
| 7593 | for (unsigned I = 0; I != NumArgs; ++I) |
| 7594 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 7595 | return TemplateArgument(Args, NumArgs); |
| 7596 | } |
| 7597 | } |
| 7598 | |
| 7599 | llvm_unreachable("Unhandled template argument kind!"); |
| 7600 | } |
| 7601 | |
| 7602 | TemplateParameterList * |
| 7603 | ASTReader::ReadTemplateParameterList(ModuleFile &F, |
| 7604 | const RecordData &Record, unsigned &Idx) { |
| 7605 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 7606 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 7607 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 7608 | |
| 7609 | unsigned NumParams = Record[Idx++]; |
| 7610 | SmallVector<NamedDecl *, 16> Params; |
| 7611 | Params.reserve(NumParams); |
| 7612 | while (NumParams--) |
| 7613 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
| 7614 | |
| 7615 | TemplateParameterList* TemplateParams = |
| 7616 | TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, |
| 7617 | Params.data(), Params.size(), RAngleLoc); |
| 7618 | return TemplateParams; |
| 7619 | } |
| 7620 | |
| 7621 | void |
| 7622 | ASTReader:: |
Craig Topper | 5603df4 | 2013-07-05 19:34:19 +0000 | [diff] [blame] | 7623 | ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7624 | ModuleFile &F, const RecordData &Record, |
| 7625 | unsigned &Idx) { |
| 7626 | unsigned NumTemplateArgs = Record[Idx++]; |
| 7627 | TemplArgs.reserve(NumTemplateArgs); |
| 7628 | while (NumTemplateArgs--) |
| 7629 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
| 7630 | } |
| 7631 | |
| 7632 | /// \brief Read a UnresolvedSet structure. |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 7633 | void ASTReader::ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7634 | const RecordData &Record, unsigned &Idx) { |
| 7635 | unsigned NumDecls = Record[Idx++]; |
| 7636 | Set.reserve(Context, NumDecls); |
| 7637 | while (NumDecls--) { |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 7638 | DeclID ID = ReadDeclID(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7639 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 7640 | Set.addLazyDecl(Context, ID, AS); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7641 | } |
| 7642 | } |
| 7643 | |
| 7644 | CXXBaseSpecifier |
| 7645 | ASTReader::ReadCXXBaseSpecifier(ModuleFile &F, |
| 7646 | const RecordData &Record, unsigned &Idx) { |
| 7647 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 7648 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 7649 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
| 7650 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
| 7651 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 7652 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 7653 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
| 7654 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
| 7655 | EllipsisLoc); |
| 7656 | Result.setInheritConstructors(inheritConstructors); |
| 7657 | return Result; |
| 7658 | } |
| 7659 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 7660 | CXXCtorInitializer ** |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7661 | ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, |
| 7662 | unsigned &Idx) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7663 | unsigned NumInitializers = Record[Idx++]; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 7664 | assert(NumInitializers && "wrote ctor initializers but have no inits"); |
| 7665 | auto **CtorInitializers = new (Context) CXXCtorInitializer*[NumInitializers]; |
| 7666 | for (unsigned i = 0; i != NumInitializers; ++i) { |
| 7667 | TypeSourceInfo *TInfo = nullptr; |
| 7668 | bool IsBaseVirtual = false; |
| 7669 | FieldDecl *Member = nullptr; |
| 7670 | IndirectFieldDecl *IndirectMember = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7671 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 7672 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 7673 | switch (Type) { |
| 7674 | case CTOR_INITIALIZER_BASE: |
| 7675 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 7676 | IsBaseVirtual = Record[Idx++]; |
| 7677 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7678 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 7679 | case CTOR_INITIALIZER_DELEGATING: |
| 7680 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 7681 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7682 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 7683 | case CTOR_INITIALIZER_MEMBER: |
| 7684 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
| 7685 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7686 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 7687 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
| 7688 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
| 7689 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7690 | } |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 7691 | |
| 7692 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
| 7693 | Expr *Init = ReadExpr(F); |
| 7694 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 7695 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
| 7696 | bool IsWritten = Record[Idx++]; |
| 7697 | unsigned SourceOrderOrNumArrayIndices; |
| 7698 | SmallVector<VarDecl *, 8> Indices; |
| 7699 | if (IsWritten) { |
| 7700 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 7701 | } else { |
| 7702 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 7703 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 7704 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 7705 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
| 7706 | } |
| 7707 | |
| 7708 | CXXCtorInitializer *BOMInit; |
| 7709 | if (Type == CTOR_INITIALIZER_BASE) { |
| 7710 | BOMInit = new (Context) |
| 7711 | CXXCtorInitializer(Context, TInfo, IsBaseVirtual, LParenLoc, Init, |
| 7712 | RParenLoc, MemberOrEllipsisLoc); |
| 7713 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
| 7714 | BOMInit = new (Context) |
| 7715 | CXXCtorInitializer(Context, TInfo, LParenLoc, Init, RParenLoc); |
| 7716 | } else if (IsWritten) { |
| 7717 | if (Member) |
| 7718 | BOMInit = new (Context) CXXCtorInitializer( |
| 7719 | Context, Member, MemberOrEllipsisLoc, LParenLoc, Init, RParenLoc); |
| 7720 | else |
| 7721 | BOMInit = new (Context) |
| 7722 | CXXCtorInitializer(Context, IndirectMember, MemberOrEllipsisLoc, |
| 7723 | LParenLoc, Init, RParenLoc); |
| 7724 | } else { |
| 7725 | if (IndirectMember) { |
| 7726 | assert(Indices.empty() && "Indirect field improperly initialized"); |
| 7727 | BOMInit = new (Context) |
| 7728 | CXXCtorInitializer(Context, IndirectMember, MemberOrEllipsisLoc, |
| 7729 | LParenLoc, Init, RParenLoc); |
| 7730 | } else { |
| 7731 | BOMInit = CXXCtorInitializer::Create( |
| 7732 | Context, Member, MemberOrEllipsisLoc, LParenLoc, Init, RParenLoc, |
| 7733 | Indices.data(), Indices.size()); |
| 7734 | } |
| 7735 | } |
| 7736 | |
| 7737 | if (IsWritten) |
| 7738 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
| 7739 | CtorInitializers[i] = BOMInit; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7740 | } |
| 7741 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 7742 | return CtorInitializers; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7743 | } |
| 7744 | |
| 7745 | NestedNameSpecifier * |
| 7746 | ASTReader::ReadNestedNameSpecifier(ModuleFile &F, |
| 7747 | const RecordData &Record, unsigned &Idx) { |
| 7748 | unsigned N = Record[Idx++]; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7749 | NestedNameSpecifier *NNS = nullptr, *Prev = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7750 | for (unsigned I = 0; I != N; ++I) { |
| 7751 | NestedNameSpecifier::SpecifierKind Kind |
| 7752 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 7753 | switch (Kind) { |
| 7754 | case NestedNameSpecifier::Identifier: { |
| 7755 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
| 7756 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
| 7757 | break; |
| 7758 | } |
| 7759 | |
| 7760 | case NestedNameSpecifier::Namespace: { |
| 7761 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
| 7762 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
| 7763 | break; |
| 7764 | } |
| 7765 | |
| 7766 | case NestedNameSpecifier::NamespaceAlias: { |
| 7767 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
| 7768 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
| 7769 | break; |
| 7770 | } |
| 7771 | |
| 7772 | case NestedNameSpecifier::TypeSpec: |
| 7773 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7774 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
| 7775 | if (!T) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7776 | return nullptr; |
| 7777 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7778 | bool Template = Record[Idx++]; |
| 7779 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
| 7780 | break; |
| 7781 | } |
| 7782 | |
| 7783 | case NestedNameSpecifier::Global: { |
| 7784 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
| 7785 | // No associated value, and there can't be a prefix. |
| 7786 | break; |
| 7787 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7788 | |
| 7789 | case NestedNameSpecifier::Super: { |
| 7790 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx); |
| 7791 | NNS = NestedNameSpecifier::SuperSpecifier(Context, RD); |
| 7792 | break; |
| 7793 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7794 | } |
| 7795 | Prev = NNS; |
| 7796 | } |
| 7797 | return NNS; |
| 7798 | } |
| 7799 | |
| 7800 | NestedNameSpecifierLoc |
| 7801 | ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, |
| 7802 | unsigned &Idx) { |
| 7803 | unsigned N = Record[Idx++]; |
| 7804 | NestedNameSpecifierLocBuilder Builder; |
| 7805 | for (unsigned I = 0; I != N; ++I) { |
| 7806 | NestedNameSpecifier::SpecifierKind Kind |
| 7807 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 7808 | switch (Kind) { |
| 7809 | case NestedNameSpecifier::Identifier: { |
| 7810 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
| 7811 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 7812 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
| 7813 | break; |
| 7814 | } |
| 7815 | |
| 7816 | case NestedNameSpecifier::Namespace: { |
| 7817 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
| 7818 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 7819 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
| 7820 | break; |
| 7821 | } |
| 7822 | |
| 7823 | case NestedNameSpecifier::NamespaceAlias: { |
| 7824 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
| 7825 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 7826 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
| 7827 | break; |
| 7828 | } |
| 7829 | |
| 7830 | case NestedNameSpecifier::TypeSpec: |
| 7831 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7832 | bool Template = Record[Idx++]; |
| 7833 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 7834 | if (!T) |
| 7835 | return NestedNameSpecifierLoc(); |
| 7836 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 7837 | |
| 7838 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
| 7839 | Builder.Extend(Context, |
| 7840 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 7841 | T->getTypeLoc(), ColonColonLoc); |
| 7842 | break; |
| 7843 | } |
| 7844 | |
| 7845 | case NestedNameSpecifier::Global: { |
| 7846 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 7847 | Builder.MakeGlobal(Context, ColonColonLoc); |
| 7848 | break; |
| 7849 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7850 | |
| 7851 | case NestedNameSpecifier::Super: { |
| 7852 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx); |
| 7853 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 7854 | Builder.MakeSuper(Context, RD, Range.getBegin(), Range.getEnd()); |
| 7855 | break; |
| 7856 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7857 | } |
| 7858 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7859 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7860 | return Builder.getWithLocInContext(Context); |
| 7861 | } |
| 7862 | |
| 7863 | SourceRange |
| 7864 | ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, |
| 7865 | unsigned &Idx) { |
| 7866 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 7867 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
| 7868 | return SourceRange(beg, end); |
| 7869 | } |
| 7870 | |
| 7871 | /// \brief Read an integral value |
| 7872 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
| 7873 | unsigned BitWidth = Record[Idx++]; |
| 7874 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 7875 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 7876 | Idx += NumWords; |
| 7877 | return Result; |
| 7878 | } |
| 7879 | |
| 7880 | /// \brief Read a signed integral value |
| 7881 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
| 7882 | bool isUnsigned = Record[Idx++]; |
| 7883 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 7884 | } |
| 7885 | |
| 7886 | /// \brief Read a floating-point value |
Tim Northover | 178723a | 2013-01-22 09:46:51 +0000 | [diff] [blame] | 7887 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, |
| 7888 | const llvm::fltSemantics &Sem, |
| 7889 | unsigned &Idx) { |
| 7890 | return llvm::APFloat(Sem, ReadAPInt(Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7891 | } |
| 7892 | |
| 7893 | // \brief Read a string |
| 7894 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
| 7895 | unsigned Len = Record[Idx++]; |
| 7896 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
| 7897 | Idx += Len; |
| 7898 | return Result; |
| 7899 | } |
| 7900 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 7901 | std::string ASTReader::ReadPath(ModuleFile &F, const RecordData &Record, |
| 7902 | unsigned &Idx) { |
| 7903 | std::string Filename = ReadString(Record, Idx); |
| 7904 | ResolveImportedPath(F, Filename); |
| 7905 | return Filename; |
| 7906 | } |
| 7907 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7908 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 7909 | unsigned &Idx) { |
| 7910 | unsigned Major = Record[Idx++]; |
| 7911 | unsigned Minor = Record[Idx++]; |
| 7912 | unsigned Subminor = Record[Idx++]; |
| 7913 | if (Minor == 0) |
| 7914 | return VersionTuple(Major); |
| 7915 | if (Subminor == 0) |
| 7916 | return VersionTuple(Major, Minor - 1); |
| 7917 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 7918 | } |
| 7919 | |
| 7920 | CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, |
| 7921 | const RecordData &Record, |
| 7922 | unsigned &Idx) { |
| 7923 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
| 7924 | return CXXTemporary::Create(Context, Decl); |
| 7925 | } |
| 7926 | |
| 7927 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Argyrios Kyrtzidis | dc9fdaf | 2013-05-24 05:44:08 +0000 | [diff] [blame] | 7928 | return Diag(CurrentImportLoc, DiagID); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7929 | } |
| 7930 | |
| 7931 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
| 7932 | return Diags.Report(Loc, DiagID); |
| 7933 | } |
| 7934 | |
| 7935 | /// \brief Retrieve the identifier table associated with the |
| 7936 | /// preprocessor. |
| 7937 | IdentifierTable &ASTReader::getIdentifierTable() { |
| 7938 | return PP.getIdentifierTable(); |
| 7939 | } |
| 7940 | |
| 7941 | /// \brief Record that the given ID maps to the given switch-case |
| 7942 | /// statement. |
| 7943 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7944 | assert((*CurrSwitchCaseStmts)[ID] == nullptr && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7945 | "Already have a SwitchCase with this ID"); |
| 7946 | (*CurrSwitchCaseStmts)[ID] = SC; |
| 7947 | } |
| 7948 | |
| 7949 | /// \brief Retrieve the switch-case statement with the given ID. |
| 7950 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7951 | assert((*CurrSwitchCaseStmts)[ID] != nullptr && "No SwitchCase with this ID"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7952 | return (*CurrSwitchCaseStmts)[ID]; |
| 7953 | } |
| 7954 | |
| 7955 | void ASTReader::ClearSwitchCaseIDs() { |
| 7956 | CurrSwitchCaseStmts->clear(); |
| 7957 | } |
| 7958 | |
| 7959 | void ASTReader::ReadComments() { |
| 7960 | std::vector<RawComment *> Comments; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 7961 | for (SmallVectorImpl<std::pair<BitstreamCursor, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7962 | serialization::ModuleFile *> >::iterator |
| 7963 | I = CommentsCursors.begin(), |
| 7964 | E = CommentsCursors.end(); |
| 7965 | I != E; ++I) { |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 7966 | Comments.clear(); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 7967 | BitstreamCursor &Cursor = I->first; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7968 | serialization::ModuleFile &F = *I->second; |
| 7969 | SavedStreamPosition SavedPosition(Cursor); |
| 7970 | |
| 7971 | RecordData Record; |
| 7972 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 7973 | llvm::BitstreamEntry Entry = |
| 7974 | Cursor.advanceSkippingSubblocks(BitstreamCursor::AF_DontPopBlockAtEnd); |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 7975 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 7976 | switch (Entry.Kind) { |
| 7977 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 7978 | case llvm::BitstreamEntry::Error: |
| 7979 | Error("malformed block record in AST file"); |
| 7980 | return; |
| 7981 | case llvm::BitstreamEntry::EndBlock: |
| 7982 | goto NextCursor; |
| 7983 | case llvm::BitstreamEntry::Record: |
| 7984 | // The interesting case. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7985 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7986 | } |
| 7987 | |
| 7988 | // Read a record. |
| 7989 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 7990 | switch ((CommentRecordTypes)Cursor.readRecord(Entry.ID, Record)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7991 | case COMMENTS_RAW_COMMENT: { |
| 7992 | unsigned Idx = 0; |
| 7993 | SourceRange SR = ReadSourceRange(F, Record, Idx); |
| 7994 | RawComment::CommentKind Kind = |
| 7995 | (RawComment::CommentKind) Record[Idx++]; |
| 7996 | bool IsTrailingComment = Record[Idx++]; |
| 7997 | bool IsAlmostTrailingComment = Record[Idx++]; |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 7998 | Comments.push_back(new (Context) RawComment( |
| 7999 | SR, Kind, IsTrailingComment, IsAlmostTrailingComment, |
| 8000 | Context.getLangOpts().CommentOpts.ParseAllComments)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8001 | break; |
| 8002 | } |
| 8003 | } |
| 8004 | } |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 8005 | NextCursor: |
| 8006 | Context.Comments.addDeserializedComments(Comments); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8007 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8008 | } |
| 8009 | |
Argyrios Kyrtzidis | 1bde117 | 2014-11-18 05:24:18 +0000 | [diff] [blame] | 8010 | void ASTReader::getInputFiles(ModuleFile &F, |
| 8011 | SmallVectorImpl<serialization::InputFile> &Files) { |
| 8012 | for (unsigned I = 0, E = F.InputFilesLoaded.size(); I != E; ++I) { |
| 8013 | unsigned ID = I+1; |
| 8014 | Files.push_back(getInputFile(F, ID)); |
| 8015 | } |
| 8016 | } |
| 8017 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 8018 | std::string ASTReader::getOwningModuleNameForDiagnostic(const Decl *D) { |
| 8019 | // If we know the owning module, use it. |
| 8020 | if (Module *M = D->getOwningModule()) |
| 8021 | return M->getFullModuleName(); |
| 8022 | |
| 8023 | // Otherwise, use the name of the top-level module the decl is within. |
| 8024 | if (ModuleFile *M = getOwningModuleFile(D)) |
| 8025 | return M->ModuleName; |
| 8026 | |
| 8027 | // Not from a module. |
| 8028 | return ""; |
| 8029 | } |
| 8030 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8031 | void ASTReader::finishPendingActions() { |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 8032 | while (!PendingIdentifierInfos.empty() || |
| 8033 | !PendingIncompleteDeclChains.empty() || !PendingDeclChains.empty() || |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 8034 | !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() || |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8035 | !PendingUpdateRecords.empty()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8036 | // If any identifiers with corresponding top-level declarations have |
| 8037 | // been loaded, load those declarations now. |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 8038 | typedef llvm::DenseMap<IdentifierInfo *, SmallVector<Decl *, 2> > |
| 8039 | TopLevelDeclsMap; |
| 8040 | TopLevelDeclsMap TopLevelDecls; |
| 8041 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8042 | while (!PendingIdentifierInfos.empty()) { |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8043 | IdentifierInfo *II = PendingIdentifierInfos.back().first; |
Richard Smith | f0ae3c2d | 2014-03-28 17:31:23 +0000 | [diff] [blame] | 8044 | SmallVector<uint32_t, 4> DeclIDs = |
| 8045 | std::move(PendingIdentifierInfos.back().second); |
Douglas Gregor | cb15f08 | 2013-02-19 18:26:28 +0000 | [diff] [blame] | 8046 | PendingIdentifierInfos.pop_back(); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8047 | |
| 8048 | SetGloballyVisibleDecls(II, DeclIDs, &TopLevelDecls[II]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8049 | } |
Richard Smith | f0ae3c2d | 2014-03-28 17:31:23 +0000 | [diff] [blame] | 8050 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 8051 | // For each decl chain that we wanted to complete while deserializing, mark |
| 8052 | // it as "still needs to be completed". |
| 8053 | for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) { |
| 8054 | markIncompleteDeclChain(PendingIncompleteDeclChains[I]); |
| 8055 | } |
| 8056 | PendingIncompleteDeclChains.clear(); |
| 8057 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8058 | // Load pending declaration chains. |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 8059 | for (unsigned I = 0; I != PendingDeclChains.size(); ++I) { |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 8060 | PendingDeclChainsKnown.erase(PendingDeclChains[I]); |
Richard Smith | e687bf8 | 2015-03-16 20:54:07 +0000 | [diff] [blame] | 8061 | loadPendingDeclChain(PendingDeclChains[I]); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 8062 | } |
| 8063 | assert(PendingDeclChainsKnown.empty()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8064 | PendingDeclChains.clear(); |
| 8065 | |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8066 | // Make the most recent of the top-level declarations visible. |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 8067 | for (TopLevelDeclsMap::iterator TLD = TopLevelDecls.begin(), |
| 8068 | TLDEnd = TopLevelDecls.end(); TLD != TLDEnd; ++TLD) { |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8069 | IdentifierInfo *II = TLD->first; |
| 8070 | for (unsigned I = 0, N = TLD->second.size(); I != N; ++I) { |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 8071 | pushExternalDeclIntoScope(cast<NamedDecl>(TLD->second[I]), II); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8072 | } |
| 8073 | } |
| 8074 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8075 | // Load any pending macro definitions. |
| 8076 | for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8077 | IdentifierInfo *II = PendingMacroIDs.begin()[I].first; |
| 8078 | SmallVector<PendingMacroInfo, 2> GlobalIDs; |
| 8079 | GlobalIDs.swap(PendingMacroIDs.begin()[I].second); |
| 8080 | // Initialize the macro history from chained-PCHs ahead of module imports. |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 8081 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
Argyrios Kyrtzidis | 719736c | 2013-01-19 03:14:56 +0000 | [diff] [blame] | 8082 | ++IDIdx) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8083 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 8084 | if (Info.M->Kind != MK_ImplicitModule && |
| 8085 | Info.M->Kind != MK_ExplicitModule) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8086 | resolvePendingMacro(II, Info); |
| 8087 | } |
| 8088 | // Handle module imports. |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 8089 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8090 | ++IDIdx) { |
| 8091 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 8092 | if (Info.M->Kind == MK_ImplicitModule || |
| 8093 | Info.M->Kind == MK_ExplicitModule) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8094 | resolvePendingMacro(II, Info); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8095 | } |
| 8096 | } |
| 8097 | PendingMacroIDs.clear(); |
Argyrios Kyrtzidis | 83a6e3b | 2013-02-16 00:48:59 +0000 | [diff] [blame] | 8098 | |
| 8099 | // Wire up the DeclContexts for Decls that we delayed setting until |
| 8100 | // recursive loading is completed. |
| 8101 | while (!PendingDeclContextInfos.empty()) { |
| 8102 | PendingDeclContextInfo Info = PendingDeclContextInfos.front(); |
| 8103 | PendingDeclContextInfos.pop_front(); |
| 8104 | DeclContext *SemaDC = cast<DeclContext>(GetDecl(Info.SemaDC)); |
| 8105 | DeclContext *LexicalDC = cast<DeclContext>(GetDecl(Info.LexicalDC)); |
| 8106 | Info.D->setDeclContextsImpl(SemaDC, LexicalDC, getContext()); |
| 8107 | } |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 8108 | |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 8109 | // Perform any pending declaration updates. |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 8110 | while (!PendingUpdateRecords.empty()) { |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 8111 | auto Update = PendingUpdateRecords.pop_back_val(); |
| 8112 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 8113 | loadDeclUpdateRecords(Update.first, Update.second); |
| 8114 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8115 | } |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 8116 | |
| 8117 | // At this point, all update records for loaded decls are in place, so any |
| 8118 | // fake class definitions should have become real. |
| 8119 | assert(PendingFakeDefinitionData.empty() && |
| 8120 | "faked up a class definition but never saw the real one"); |
| 8121 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8122 | // If we deserialized any C++ or Objective-C class definitions, any |
| 8123 | // Objective-C protocol definitions, or any redeclarable templates, make sure |
| 8124 | // that all redeclarations point to the definitions. Note that this can only |
| 8125 | // happen now, after the redeclaration chains have been fully wired. |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 8126 | for (Decl *D : PendingDefinitions) { |
| 8127 | if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
Richard Smith | 5b21db8 | 2014-04-23 18:20:42 +0000 | [diff] [blame] | 8128 | if (const TagType *TagT = dyn_cast<TagType>(TD->getTypeForDecl())) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8129 | // Make sure that the TagType points at the definition. |
| 8130 | const_cast<TagType*>(TagT)->decl = TD; |
| 8131 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8132 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 8133 | if (auto RD = dyn_cast<CXXRecordDecl>(D)) { |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8134 | for (auto *R = getMostRecentExistingDecl(RD); R; |
| 8135 | R = R->getPreviousDecl()) { |
| 8136 | assert((R == D) == |
| 8137 | cast<CXXRecordDecl>(R)->isThisDeclarationADefinition() && |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 8138 | "declaration thinks it's the definition but it isn't"); |
Aaron Ballman | 86c9390 | 2014-03-06 23:45:36 +0000 | [diff] [blame] | 8139 | cast<CXXRecordDecl>(R)->DefinitionData = RD->DefinitionData; |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 8140 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8141 | } |
| 8142 | |
| 8143 | continue; |
| 8144 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8145 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 8146 | if (auto ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8147 | // Make sure that the ObjCInterfaceType points at the definition. |
| 8148 | const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl)) |
| 8149 | ->Decl = ID; |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8150 | |
| 8151 | for (auto *R = getMostRecentExistingDecl(ID); R; R = R->getPreviousDecl()) |
| 8152 | cast<ObjCInterfaceDecl>(R)->Data = ID->Data; |
| 8153 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8154 | continue; |
| 8155 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8156 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 8157 | if (auto PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8158 | for (auto *R = getMostRecentExistingDecl(PD); R; R = R->getPreviousDecl()) |
| 8159 | cast<ObjCProtocolDecl>(R)->Data = PD->Data; |
| 8160 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8161 | continue; |
| 8162 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8163 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 8164 | auto RTD = cast<RedeclarableTemplateDecl>(D)->getCanonicalDecl(); |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8165 | for (auto *R = getMostRecentExistingDecl(RTD); R; R = R->getPreviousDecl()) |
| 8166 | cast<RedeclarableTemplateDecl>(R)->Common = RTD->Common; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8167 | } |
| 8168 | PendingDefinitions.clear(); |
| 8169 | |
| 8170 | // Load the bodies of any functions or methods we've encountered. We do |
| 8171 | // this now (delayed) so that we can be sure that the declaration chains |
| 8172 | // have been fully wired up. |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8173 | // FIXME: There seems to be no point in delaying this, it does not depend |
| 8174 | // on the redecl chains having been wired up. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8175 | for (PendingBodiesMap::iterator PB = PendingBodies.begin(), |
| 8176 | PBEnd = PendingBodies.end(); |
| 8177 | PB != PBEnd; ++PB) { |
| 8178 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) { |
| 8179 | // FIXME: Check for =delete/=default? |
| 8180 | // FIXME: Complain about ODR violations here? |
| 8181 | if (!getContext().getLangOpts().Modules || !FD->hasBody()) |
| 8182 | FD->setLazyBody(PB->second); |
| 8183 | continue; |
| 8184 | } |
| 8185 | |
| 8186 | ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first); |
| 8187 | if (!getContext().getLangOpts().Modules || !MD->hasBody()) |
| 8188 | MD->setLazyBody(PB->second); |
| 8189 | } |
| 8190 | PendingBodies.clear(); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8191 | } |
| 8192 | |
| 8193 | void ASTReader::diagnoseOdrViolations() { |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 8194 | if (PendingOdrMergeFailures.empty() && PendingOdrMergeChecks.empty()) |
| 8195 | return; |
| 8196 | |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8197 | // Trigger the import of the full definition of each class that had any |
| 8198 | // odr-merging problems, so we can produce better diagnostics for them. |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 8199 | // These updates may in turn find and diagnose some ODR failures, so take |
| 8200 | // ownership of the set first. |
| 8201 | auto OdrMergeFailures = std::move(PendingOdrMergeFailures); |
| 8202 | PendingOdrMergeFailures.clear(); |
| 8203 | for (auto &Merge : OdrMergeFailures) { |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8204 | Merge.first->buildLookup(); |
| 8205 | Merge.first->decls_begin(); |
| 8206 | Merge.first->bases_begin(); |
| 8207 | Merge.first->vbases_begin(); |
| 8208 | for (auto *RD : Merge.second) { |
| 8209 | RD->decls_begin(); |
| 8210 | RD->bases_begin(); |
| 8211 | RD->vbases_begin(); |
| 8212 | } |
| 8213 | } |
| 8214 | |
| 8215 | // For each declaration from a merged context, check that the canonical |
| 8216 | // definition of that context also contains a declaration of the same |
| 8217 | // entity. |
| 8218 | // |
| 8219 | // Caution: this loop does things that might invalidate iterators into |
| 8220 | // PendingOdrMergeChecks. Don't turn this into a range-based for loop! |
| 8221 | while (!PendingOdrMergeChecks.empty()) { |
| 8222 | NamedDecl *D = PendingOdrMergeChecks.pop_back_val(); |
| 8223 | |
| 8224 | // FIXME: Skip over implicit declarations for now. This matters for things |
| 8225 | // like implicitly-declared special member functions. This isn't entirely |
| 8226 | // correct; we can end up with multiple unmerged declarations of the same |
| 8227 | // implicit entity. |
| 8228 | if (D->isImplicit()) |
| 8229 | continue; |
| 8230 | |
| 8231 | DeclContext *CanonDef = D->getDeclContext(); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8232 | |
| 8233 | bool Found = false; |
| 8234 | const Decl *DCanon = D->getCanonicalDecl(); |
| 8235 | |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 8236 | for (auto RI : D->redecls()) { |
| 8237 | if (RI->getLexicalDeclContext() == CanonDef) { |
| 8238 | Found = true; |
| 8239 | break; |
| 8240 | } |
| 8241 | } |
| 8242 | if (Found) |
| 8243 | continue; |
| 8244 | |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8245 | llvm::SmallVector<const NamedDecl*, 4> Candidates; |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 8246 | DeclContext::lookup_result R = CanonDef->lookup(D->getDeclName()); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8247 | for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); |
| 8248 | !Found && I != E; ++I) { |
| 8249 | for (auto RI : (*I)->redecls()) { |
| 8250 | if (RI->getLexicalDeclContext() == CanonDef) { |
| 8251 | // This declaration is present in the canonical definition. If it's |
| 8252 | // in the same redecl chain, it's the one we're looking for. |
| 8253 | if (RI->getCanonicalDecl() == DCanon) |
| 8254 | Found = true; |
| 8255 | else |
| 8256 | Candidates.push_back(cast<NamedDecl>(RI)); |
| 8257 | break; |
| 8258 | } |
| 8259 | } |
| 8260 | } |
| 8261 | |
| 8262 | if (!Found) { |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 8263 | // The AST doesn't like TagDecls becoming invalid after they've been |
| 8264 | // completed. We only really need to mark FieldDecls as invalid here. |
| 8265 | if (!isa<TagDecl>(D)) |
| 8266 | D->setInvalidDecl(); |
Richard Smith | 4ab3dbd | 2015-02-13 22:43:51 +0000 | [diff] [blame] | 8267 | |
| 8268 | // Ensure we don't accidentally recursively enter deserialization while |
| 8269 | // we're producing our diagnostic. |
| 8270 | Deserializing RecursionGuard(this); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8271 | |
| 8272 | std::string CanonDefModule = |
| 8273 | getOwningModuleNameForDiagnostic(cast<Decl>(CanonDef)); |
| 8274 | Diag(D->getLocation(), diag::err_module_odr_violation_missing_decl) |
| 8275 | << D << getOwningModuleNameForDiagnostic(D) |
| 8276 | << CanonDef << CanonDefModule.empty() << CanonDefModule; |
| 8277 | |
| 8278 | if (Candidates.empty()) |
| 8279 | Diag(cast<Decl>(CanonDef)->getLocation(), |
| 8280 | diag::note_module_odr_violation_no_possible_decls) << D; |
| 8281 | else { |
| 8282 | for (unsigned I = 0, N = Candidates.size(); I != N; ++I) |
| 8283 | Diag(Candidates[I]->getLocation(), |
| 8284 | diag::note_module_odr_violation_possible_decl) |
| 8285 | << Candidates[I]; |
| 8286 | } |
| 8287 | |
| 8288 | DiagnosedOdrMergeFailures.insert(CanonDef); |
| 8289 | } |
| 8290 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 8291 | |
Richard Smith | 4ab3dbd | 2015-02-13 22:43:51 +0000 | [diff] [blame] | 8292 | if (OdrMergeFailures.empty()) |
| 8293 | return; |
| 8294 | |
| 8295 | // Ensure we don't accidentally recursively enter deserialization while |
| 8296 | // we're producing our diagnostics. |
| 8297 | Deserializing RecursionGuard(this); |
| 8298 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 8299 | // Issue any pending ODR-failure diagnostics. |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 8300 | for (auto &Merge : OdrMergeFailures) { |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8301 | // If we've already pointed out a specific problem with this class, don't |
| 8302 | // bother issuing a general "something's different" diagnostic. |
David Blaikie | 82e95a3 | 2014-11-19 07:49:47 +0000 | [diff] [blame] | 8303 | if (!DiagnosedOdrMergeFailures.insert(Merge.first).second) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 8304 | continue; |
| 8305 | |
| 8306 | bool Diagnosed = false; |
| 8307 | for (auto *RD : Merge.second) { |
| 8308 | // Multiple different declarations got merged together; tell the user |
| 8309 | // where they came from. |
| 8310 | if (Merge.first != RD) { |
| 8311 | // FIXME: Walk the definition, figure out what's different, |
| 8312 | // and diagnose that. |
| 8313 | if (!Diagnosed) { |
| 8314 | std::string Module = getOwningModuleNameForDiagnostic(Merge.first); |
| 8315 | Diag(Merge.first->getLocation(), |
| 8316 | diag::err_module_odr_violation_different_definitions) |
| 8317 | << Merge.first << Module.empty() << Module; |
| 8318 | Diagnosed = true; |
| 8319 | } |
| 8320 | |
| 8321 | Diag(RD->getLocation(), |
| 8322 | diag::note_module_odr_violation_different_definitions) |
| 8323 | << getOwningModuleNameForDiagnostic(RD); |
| 8324 | } |
| 8325 | } |
| 8326 | |
| 8327 | if (!Diagnosed) { |
| 8328 | // All definitions are updates to the same declaration. This happens if a |
| 8329 | // module instantiates the declaration of a class template specialization |
| 8330 | // and two or more other modules instantiate its definition. |
| 8331 | // |
| 8332 | // FIXME: Indicate which modules had instantiations of this definition. |
| 8333 | // FIXME: How can this even happen? |
| 8334 | Diag(Merge.first->getLocation(), |
| 8335 | diag::err_module_odr_violation_different_instantiations) |
| 8336 | << Merge.first; |
| 8337 | } |
| 8338 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8339 | } |
| 8340 | |
| 8341 | void ASTReader::FinishedDeserializing() { |
| 8342 | assert(NumCurrentElementsDeserializing && |
| 8343 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 8344 | if (NumCurrentElementsDeserializing == 1) { |
| 8345 | // We decrease NumCurrentElementsDeserializing only after pending actions |
| 8346 | // are finished, to avoid recursively re-calling finishPendingActions(). |
| 8347 | finishPendingActions(); |
| 8348 | } |
| 8349 | --NumCurrentElementsDeserializing; |
| 8350 | |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8351 | if (NumCurrentElementsDeserializing == 0) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 8352 | // Propagate exception specification updates along redeclaration chains. |
Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 8353 | while (!PendingExceptionSpecUpdates.empty()) { |
| 8354 | auto Updates = std::move(PendingExceptionSpecUpdates); |
| 8355 | PendingExceptionSpecUpdates.clear(); |
| 8356 | for (auto Update : Updates) { |
| 8357 | auto *FPT = Update.second->getType()->castAs<FunctionProtoType>(); |
| 8358 | SemaObj->UpdateExceptionSpec(Update.second, |
| 8359 | FPT->getExtProtoInfo().ExceptionSpec); |
| 8360 | } |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 8361 | } |
| 8362 | |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8363 | diagnoseOdrViolations(); |
| 8364 | |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 8365 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 8366 | // decls to the consumer. |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8367 | if (Consumer) |
| 8368 | PassInterestingDeclsToConsumer(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8369 | } |
| 8370 | } |
| 8371 | |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 8372 | void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 8373 | if (IdentifierInfo *II = Name.getAsIdentifierInfo()) { |
| 8374 | // Remove any fake results before adding any real ones. |
| 8375 | auto It = PendingFakeLookupResults.find(II); |
| 8376 | if (It != PendingFakeLookupResults.end()) { |
| 8377 | for (auto *ND : PendingFakeLookupResults[II]) |
| 8378 | SemaObj->IdResolver.RemoveDecl(ND); |
Ben Langmuir | eb8bd2d | 2015-04-10 22:25:42 +0000 | [diff] [blame] | 8379 | // FIXME: this works around module+PCH performance issue. |
| 8380 | // Rather than erase the result from the map, which is O(n), just clear |
| 8381 | // the vector of NamedDecls. |
| 8382 | It->second.clear(); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 8383 | } |
| 8384 | } |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 8385 | |
| 8386 | if (SemaObj->IdResolver.tryAddTopLevelDecl(D, Name) && SemaObj->TUScope) { |
| 8387 | SemaObj->TUScope->AddDecl(D); |
| 8388 | } else if (SemaObj->TUScope) { |
| 8389 | // Adding the decl to IdResolver may have failed because it was already in |
| 8390 | // (even though it was not added in scope). If it is already in, make sure |
| 8391 | // it gets in the scope as well. |
| 8392 | if (std::find(SemaObj->IdResolver.begin(Name), |
| 8393 | SemaObj->IdResolver.end(), D) != SemaObj->IdResolver.end()) |
| 8394 | SemaObj->TUScope->AddDecl(D); |
| 8395 | } |
| 8396 | } |
| 8397 | |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 8398 | ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot, |
| 8399 | bool DisableValidation, bool AllowASTWithCompilerErrors, |
| 8400 | bool AllowConfigurationMismatch, bool ValidateSystemInputs, |
Ben Langmuir | 2cb4a78 | 2014-02-05 22:21:15 +0000 | [diff] [blame] | 8401 | bool UseGlobalIndex) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8402 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(nullptr), |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 8403 | OwnsDeserializationListener(false), SourceMgr(PP.getSourceManager()), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8404 | FileMgr(PP.getFileManager()), Diags(PP.getDiagnostics()), |
| 8405 | SemaObj(nullptr), PP(PP), Context(Context), Consumer(nullptr), |
| 8406 | ModuleMgr(PP.getFileManager()), isysroot(isysroot), |
| 8407 | DisableValidation(DisableValidation), |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 8408 | AllowASTWithCompilerErrors(AllowASTWithCompilerErrors), |
| 8409 | AllowConfigurationMismatch(AllowConfigurationMismatch), |
| 8410 | ValidateSystemInputs(ValidateSystemInputs), |
| 8411 | UseGlobalIndex(UseGlobalIndex), TriedLoadingGlobalIndex(false), |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 8412 | CurrSwitchCaseStmts(&SwitchCaseStmts), |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 8413 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), NumStatementsRead(0), |
| 8414 | TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), |
| 8415 | NumIdentifierLookups(0), NumIdentifierLookupHits(0), NumSelectorsRead(0), |
| 8416 | NumMethodPoolEntriesRead(0), NumMethodPoolLookups(0), |
| 8417 | NumMethodPoolHits(0), NumMethodPoolTableLookups(0), |
| 8418 | NumMethodPoolTableHits(0), TotalNumMethodPoolEntries(0), |
| 8419 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
| 8420 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 8421 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8422 | PassingDeclsToConsumer(false), ReadingKind(Read_None) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8423 | SourceMgr.setExternalSLocEntrySource(this); |
| 8424 | } |
| 8425 | |
| 8426 | ASTReader::~ASTReader() { |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 8427 | if (OwnsDeserializationListener) |
| 8428 | delete DeserializationListener; |
| 8429 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8430 | for (DeclContextVisibleUpdatesPending::iterator |
| 8431 | I = PendingVisibleUpdates.begin(), |
| 8432 | E = PendingVisibleUpdates.end(); |
| 8433 | I != E; ++I) { |
| 8434 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 8435 | F = I->second.end(); |
| 8436 | J != F; ++J) |
| 8437 | delete J->first; |
| 8438 | } |
| 8439 | } |