File indexing completed on 2026-05-10 08:37:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H
0014 #define LLVM_CLANG_SERIALIZATION_ASTREADER_H
0015
0016 #include "clang/AST/Type.h"
0017 #include "clang/Basic/Diagnostic.h"
0018 #include "clang/Basic/DiagnosticOptions.h"
0019 #include "clang/Basic/IdentifierTable.h"
0020 #include "clang/Basic/OpenCLOptions.h"
0021 #include "clang/Basic/SourceLocation.h"
0022 #include "clang/Basic/StackExhaustionHandler.h"
0023 #include "clang/Basic/Version.h"
0024 #include "clang/Lex/ExternalPreprocessorSource.h"
0025 #include "clang/Lex/HeaderSearch.h"
0026 #include "clang/Lex/PreprocessingRecord.h"
0027 #include "clang/Lex/PreprocessorOptions.h"
0028 #include "clang/Sema/ExternalSemaSource.h"
0029 #include "clang/Sema/IdentifierResolver.h"
0030 #include "clang/Sema/Sema.h"
0031 #include "clang/Serialization/ASTBitCodes.h"
0032 #include "clang/Serialization/ContinuousRangeMap.h"
0033 #include "clang/Serialization/ModuleFile.h"
0034 #include "clang/Serialization/ModuleFileExtension.h"
0035 #include "clang/Serialization/ModuleManager.h"
0036 #include "clang/Serialization/SourceLocationEncoding.h"
0037 #include "llvm/ADT/ArrayRef.h"
0038 #include "llvm/ADT/DenseMap.h"
0039 #include "llvm/ADT/DenseSet.h"
0040 #include "llvm/ADT/IntrusiveRefCntPtr.h"
0041 #include "llvm/ADT/MapVector.h"
0042 #include "llvm/ADT/PagedVector.h"
0043 #include "llvm/ADT/STLExtras.h"
0044 #include "llvm/ADT/SetVector.h"
0045 #include "llvm/ADT/SmallPtrSet.h"
0046 #include "llvm/ADT/SmallVector.h"
0047 #include "llvm/ADT/StringMap.h"
0048 #include "llvm/ADT/StringRef.h"
0049 #include "llvm/ADT/iterator.h"
0050 #include "llvm/ADT/iterator_range.h"
0051 #include "llvm/Bitstream/BitstreamReader.h"
0052 #include "llvm/Support/MemoryBuffer.h"
0053 #include "llvm/Support/SaveAndRestore.h"
0054 #include "llvm/Support/Timer.h"
0055 #include "llvm/Support/VersionTuple.h"
0056 #include <cassert>
0057 #include <cstddef>
0058 #include <cstdint>
0059 #include <ctime>
0060 #include <deque>
0061 #include <memory>
0062 #include <optional>
0063 #include <set>
0064 #include <string>
0065 #include <utility>
0066 #include <vector>
0067
0068 namespace clang {
0069
0070 class ASTConsumer;
0071 class ASTContext;
0072 class ASTDeserializationListener;
0073 class ASTReader;
0074 class ASTRecordReader;
0075 class CXXTemporary;
0076 class Decl;
0077 class DeclarationName;
0078 class DeclaratorDecl;
0079 class DeclContext;
0080 class EnumDecl;
0081 class Expr;
0082 class FieldDecl;
0083 class FileEntry;
0084 class FileManager;
0085 class FileSystemOptions;
0086 class FunctionDecl;
0087 class GlobalModuleIndex;
0088 struct HeaderFileInfo;
0089 class HeaderSearchOptions;
0090 class LangOptions;
0091 class MacroInfo;
0092 class InMemoryModuleCache;
0093 class NamedDecl;
0094 class NamespaceDecl;
0095 class ObjCCategoryDecl;
0096 class ObjCInterfaceDecl;
0097 class PCHContainerReader;
0098 class Preprocessor;
0099 class PreprocessorOptions;
0100 class Sema;
0101 class SourceManager;
0102 class Stmt;
0103 class SwitchCase;
0104 class TargetOptions;
0105 class Token;
0106 class TypedefNameDecl;
0107 class ValueDecl;
0108 class VarDecl;
0109
0110
0111
0112
0113
0114
0115
0116 class ASTReaderListener {
0117 public:
0118 virtual ~ASTReaderListener();
0119
0120
0121
0122
0123
0124 virtual bool ReadFullVersionInformation(StringRef FullVersion) {
0125 return FullVersion != getClangFullRepositoryVersion();
0126 }
0127
0128 virtual void ReadModuleName(StringRef ModuleName) {}
0129 virtual void ReadModuleMapFile(StringRef ModuleMapPath) {}
0130
0131
0132
0133
0134 virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
0135 StringRef ModuleFilename, bool Complain,
0136 bool AllowCompatibleDifferences) {
0137 return false;
0138 }
0139
0140
0141
0142
0143
0144 virtual bool ReadTargetOptions(const TargetOptions &TargetOpts,
0145 StringRef ModuleFilename, bool Complain,
0146 bool AllowCompatibleDifferences) {
0147 return false;
0148 }
0149
0150
0151
0152
0153
0154 virtual bool
0155 ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
0156 StringRef ModuleFilename, bool Complain) {
0157 return false;
0158 }
0159
0160
0161
0162
0163
0164 virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
0165 bool Complain) {
0166 return false;
0167 }
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177 virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
0178 StringRef ModuleFilename,
0179 StringRef SpecificModuleCachePath,
0180 bool Complain) {
0181 return false;
0182 }
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193 virtual bool ReadHeaderSearchPaths(const HeaderSearchOptions &HSOpts,
0194 bool Complain) {
0195 return false;
0196 }
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206 virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
0207 StringRef ModuleFilename,
0208 bool ReadMacros, bool Complain,
0209 std::string &SuggestedPredefines) {
0210 return false;
0211 }
0212
0213
0214 virtual void ReadCounter(const serialization::ModuleFile &M,
0215 unsigned Value) {}
0216
0217
0218 virtual void visitModuleFile(StringRef Filename,
0219 serialization::ModuleKind Kind) {}
0220
0221
0222
0223 virtual bool needsInputFileVisitation() { return false; }
0224
0225
0226
0227 virtual bool needsSystemInputFileVisitation() { return false; }
0228
0229
0230
0231
0232
0233
0234
0235 virtual bool visitInputFile(StringRef Filename, bool isSystem,
0236 bool isOverridden, bool isExplicitModule) {
0237 return true;
0238 }
0239
0240
0241
0242 virtual bool needsImportVisitation() const { return false; }
0243
0244
0245
0246 virtual void visitImport(StringRef ModuleName, StringRef Filename) {}
0247
0248
0249 virtual void readModuleFileExtension(
0250 const ModuleFileExtensionMetadata &Metadata) {}
0251 };
0252
0253
0254 class ChainedASTReaderListener : public ASTReaderListener {
0255 std::unique_ptr<ASTReaderListener> First;
0256 std::unique_ptr<ASTReaderListener> Second;
0257
0258 public:
0259
0260 ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First,
0261 std::unique_ptr<ASTReaderListener> Second)
0262 : First(std::move(First)), Second(std::move(Second)) {}
0263
0264 std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); }
0265 std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); }
0266
0267 bool ReadFullVersionInformation(StringRef FullVersion) override;
0268 void ReadModuleName(StringRef ModuleName) override;
0269 void ReadModuleMapFile(StringRef ModuleMapPath) override;
0270 bool ReadLanguageOptions(const LangOptions &LangOpts,
0271 StringRef ModuleFilename, bool Complain,
0272 bool AllowCompatibleDifferences) override;
0273 bool ReadTargetOptions(const TargetOptions &TargetOpts,
0274 StringRef ModuleFilename, bool Complain,
0275 bool AllowCompatibleDifferences) override;
0276 bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
0277 StringRef ModuleFilename, bool Complain) override;
0278 bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
0279 bool Complain) override;
0280
0281 bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
0282 StringRef ModuleFilename,
0283 StringRef SpecificModuleCachePath,
0284 bool Complain) override;
0285 bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
0286 StringRef ModuleFilename, bool ReadMacros,
0287 bool Complain,
0288 std::string &SuggestedPredefines) override;
0289
0290 void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
0291 bool needsInputFileVisitation() override;
0292 bool needsSystemInputFileVisitation() override;
0293 void visitModuleFile(StringRef Filename,
0294 serialization::ModuleKind Kind) override;
0295 bool visitInputFile(StringRef Filename, bool isSystem,
0296 bool isOverridden, bool isExplicitModule) override;
0297 void readModuleFileExtension(
0298 const ModuleFileExtensionMetadata &Metadata) override;
0299 };
0300
0301
0302
0303 class PCHValidator : public ASTReaderListener {
0304 Preprocessor &PP;
0305 ASTReader &Reader;
0306
0307 public:
0308 PCHValidator(Preprocessor &PP, ASTReader &Reader)
0309 : PP(PP), Reader(Reader) {}
0310
0311 bool ReadLanguageOptions(const LangOptions &LangOpts,
0312 StringRef ModuleFilename, bool Complain,
0313 bool AllowCompatibleDifferences) override;
0314 bool ReadTargetOptions(const TargetOptions &TargetOpts,
0315 StringRef ModuleFilename, bool Complain,
0316 bool AllowCompatibleDifferences) override;
0317 bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
0318 StringRef ModuleFilename, bool Complain) override;
0319 bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
0320 StringRef ModuleFilename, bool ReadMacros,
0321 bool Complain,
0322 std::string &SuggestedPredefines) override;
0323 bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
0324 StringRef ModuleFilename,
0325 StringRef SpecificModuleCachePath,
0326 bool Complain) override;
0327 void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
0328 };
0329
0330
0331
0332
0333
0334 class SimpleASTReaderListener : public ASTReaderListener {
0335 Preprocessor &PP;
0336
0337 public:
0338 SimpleASTReaderListener(Preprocessor &PP) : PP(PP) {}
0339
0340 bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
0341 StringRef ModuleFilename, bool ReadMacros,
0342 bool Complain,
0343 std::string &SuggestedPredefines) override;
0344 };
0345
0346 namespace serialization {
0347
0348 class ReadMethodPoolVisitor;
0349
0350 namespace reader {
0351
0352 class ASTIdentifierLookupTrait;
0353
0354
0355 struct DeclContextLookupTable;
0356 struct ModuleLocalLookupTable;
0357
0358
0359 struct LazySpecializationInfoLookupTable;
0360
0361 }
0362
0363 }
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377 class ASTReader
0378 : public ExternalPreprocessorSource,
0379 public ExternalPreprocessingRecordSource,
0380 public ExternalHeaderFileInfoSource,
0381 public ExternalSemaSource,
0382 public IdentifierInfoLookup,
0383 public ExternalSLocEntrySource
0384 {
0385 public:
0386
0387 friend class ASTDeclMerger;
0388 friend class ASTDeclReader;
0389 friend class ASTIdentifierIterator;
0390 friend class ASTRecordReader;
0391 friend class ASTUnit;
0392 friend class ASTWriter;
0393 friend class PCHValidator;
0394 friend class serialization::reader::ASTIdentifierLookupTrait;
0395 friend class serialization::ReadMethodPoolVisitor;
0396 friend class TypeLocReader;
0397 friend class LocalDeclID;
0398
0399 using RecordData = SmallVector<uint64_t, 64>;
0400 using RecordDataImpl = SmallVectorImpl<uint64_t>;
0401
0402
0403
0404 enum ASTReadResult {
0405
0406
0407 Success,
0408
0409
0410 Failure,
0411
0412
0413 Missing,
0414
0415
0416
0417 OutOfDate,
0418
0419
0420 VersionMismatch,
0421
0422
0423
0424 ConfigurationMismatch,
0425
0426
0427 HadErrors
0428 };
0429
0430 using ModuleFile = serialization::ModuleFile;
0431 using ModuleKind = serialization::ModuleKind;
0432 using ModuleManager = serialization::ModuleManager;
0433 using ModuleIterator = ModuleManager::ModuleIterator;
0434 using ModuleConstIterator = ModuleManager::ModuleConstIterator;
0435 using ModuleReverseIterator = ModuleManager::ModuleReverseIterator;
0436
0437 private:
0438 using LocSeq = SourceLocationSequence;
0439
0440
0441 std::unique_ptr<ASTReaderListener> Listener;
0442
0443
0444 ASTDeserializationListener *DeserializationListener = nullptr;
0445
0446 bool OwnsDeserializationListener = false;
0447
0448 SourceManager &SourceMgr;
0449 FileManager &FileMgr;
0450 const PCHContainerReader &PCHContainerRdr;
0451 DiagnosticsEngine &Diags;
0452
0453
0454 StackExhaustionHandler StackHandler;
0455
0456
0457
0458 Sema *SemaObj = nullptr;
0459
0460
0461 Preprocessor &PP;
0462
0463
0464 ASTContext *ContextObj = nullptr;
0465
0466
0467 ASTConsumer *Consumer = nullptr;
0468
0469
0470 ModuleManager ModuleMgr;
0471
0472
0473
0474
0475 IdentifierResolver DummyIdResolver;
0476
0477
0478 llvm::StringMap<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
0479
0480
0481 std::unique_ptr<llvm::Timer> ReadTimer;
0482
0483
0484
0485 SourceLocation CurrentImportLoc;
0486
0487
0488 std::optional<ModuleKind> CurrentDeserializingModuleKind;
0489
0490
0491 std::unique_ptr<GlobalModuleIndex> GlobalIndex;
0492
0493
0494
0495 ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
0496
0497
0498 ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
0499
0500 using GlobalSLocOffsetMapType =
0501 ContinuousRangeMap<unsigned, ModuleFile *, 64>;
0502
0503
0504
0505 GlobalSLocOffsetMapType GlobalSLocOffsetMap;
0506
0507
0508
0509
0510
0511 llvm::PagedVector<QualType> TypesLoaded;
0512
0513
0514
0515
0516
0517 llvm::PagedVector<Decl *> DeclsLoaded;
0518
0519 using FileOffset = std::pair<ModuleFile *, uint64_t>;
0520 using FileOffsetsTy = SmallVector<FileOffset, 2>;
0521 using DeclUpdateOffsetsMap = llvm::DenseMap<GlobalDeclID, FileOffsetsTy>;
0522
0523
0524
0525 DeclUpdateOffsetsMap DeclUpdateOffsets;
0526
0527 struct LookupBlockOffsets {
0528 uint64_t LexicalOffset;
0529 uint64_t VisibleOffset;
0530 uint64_t ModuleLocalOffset;
0531 uint64_t TULocalOffset;
0532 };
0533
0534 using DelayedNamespaceOffsetMapTy =
0535 llvm::DenseMap<GlobalDeclID, LookupBlockOffsets>;
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545 DelayedNamespaceOffsetMapTy DelayedNamespaceOffsetMap;
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561 llvm::DenseMap<GlobalDeclID, SmallVector<GlobalDeclID, 4>> RelatedDeclsMap;
0562
0563 struct PendingUpdateRecord {
0564 Decl *D;
0565 GlobalDeclID ID;
0566
0567
0568 bool JustLoaded;
0569
0570 PendingUpdateRecord(GlobalDeclID ID, Decl *D, bool JustLoaded)
0571 : D(D), ID(ID), JustLoaded(JustLoaded) {}
0572 };
0573
0574
0575
0576 llvm::SmallVector<PendingUpdateRecord, 16> PendingUpdateRecords;
0577
0578 enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded };
0579
0580
0581
0582 llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData;
0583
0584
0585
0586
0587
0588 llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates;
0589
0590
0591
0592
0593 llvm::SmallMapVector<FunctionDecl *, QualType, 4> PendingDeducedTypeUpdates;
0594
0595
0596
0597 llvm::SmallVector<FunctionDecl *, 4> PendingUndeducedFunctionDecls;
0598
0599
0600
0601 llvm::DenseMap<std::pair<DeclContext *, IdentifierInfo *>, NamedDecl *>
0602 ImportedTypedefNamesForLinkage;
0603
0604
0605
0606 llvm::DenseMap<Decl*, llvm::SmallVector<NamedDecl*, 2>>
0607 AnonymousDeclarationsForMerging;
0608
0609
0610 llvm::DenseMap<std::pair<const Decl *, unsigned>, NamedDecl *>
0611 LambdaDeclarationsForMerging;
0612
0613
0614
0615 using LETemporaryKey = std::pair<Decl *, unsigned>;
0616
0617
0618 llvm::DenseMap<LETemporaryKey, LifetimeExtendedTemporaryDecl *>
0619 LETemporaryForMerging;
0620
0621 struct FileDeclsInfo {
0622 ModuleFile *Mod = nullptr;
0623 ArrayRef<serialization::unaligned_decl_id_t> Decls;
0624
0625 FileDeclsInfo() = default;
0626 FileDeclsInfo(ModuleFile *Mod,
0627 ArrayRef<serialization::unaligned_decl_id_t> Decls)
0628 : Mod(Mod), Decls(Decls) {}
0629 };
0630
0631
0632 llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
0633
0634
0635
0636 using LexicalContents = ArrayRef<serialization::unaligned_decl_id_t>;
0637
0638
0639 llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
0640 LexicalDecls;
0641
0642
0643 std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls;
0644
0645
0646 llvm::DenseMap<const DeclContext *,
0647 serialization::reader::DeclContextLookupTable> Lookups;
0648 llvm::DenseMap<const DeclContext *,
0649 serialization::reader::ModuleLocalLookupTable>
0650 ModuleLocalLookups;
0651 llvm::DenseMap<const DeclContext *,
0652 serialization::reader::DeclContextLookupTable>
0653 TULocalLookups;
0654
0655 using SpecLookupTableTy =
0656 llvm::DenseMap<const Decl *,
0657 serialization::reader::LazySpecializationInfoLookupTable>;
0658
0659 SpecLookupTableTy SpecializationsLookups;
0660
0661 SpecLookupTableTy PartialSpecializationsLookups;
0662
0663 bool LoadExternalSpecializationsImpl(SpecLookupTableTy &SpecLookups,
0664 const Decl *D);
0665 bool LoadExternalSpecializationsImpl(SpecLookupTableTy &SpecLookups,
0666 const Decl *D,
0667 ArrayRef<TemplateArgument> TemplateArgs);
0668
0669
0670
0671
0672
0673 struct UpdateData {
0674 ModuleFile *Mod;
0675 const unsigned char *Data;
0676 };
0677 using DeclContextVisibleUpdates = SmallVector<UpdateData, 1>;
0678
0679
0680
0681 llvm::DenseMap<GlobalDeclID, DeclContextVisibleUpdates> PendingVisibleUpdates;
0682 llvm::DenseMap<GlobalDeclID, DeclContextVisibleUpdates>
0683 PendingModuleLocalVisibleUpdates;
0684 llvm::DenseMap<GlobalDeclID, DeclContextVisibleUpdates> TULocalUpdates;
0685
0686 using SpecializationsUpdate = SmallVector<UpdateData, 1>;
0687 using SpecializationsUpdateMap =
0688 llvm::DenseMap<GlobalDeclID, SpecializationsUpdate>;
0689 SpecializationsUpdateMap PendingSpecializationsUpdates;
0690 SpecializationsUpdateMap PendingPartialSpecializationsUpdates;
0691
0692
0693
0694 llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
0695
0696 using PendingBodiesMap =
0697 llvm::MapVector<Decl *, uint64_t,
0698 llvm::SmallDenseMap<Decl *, unsigned, 4>,
0699 SmallVector<std::pair<Decl *, uint64_t>, 4>>;
0700
0701
0702 PendingBodiesMap PendingBodies;
0703
0704
0705
0706 llvm::SetVector<NamedDecl *> PendingMergedDefinitionsToDeduplicate;
0707
0708
0709
0710
0711 llvm::SmallVector<std::pair<Decl *, Decl *>>
0712 PendingWarningForDuplicatedDefsInModuleUnits;
0713
0714
0715 bool ReadLexicalDeclContextStorage(ModuleFile &M,
0716 llvm::BitstreamCursor &Cursor,
0717 uint64_t Offset, DeclContext *DC);
0718
0719 enum class VisibleDeclContextStorageKind {
0720 GenerallyVisible,
0721 ModuleLocalVisible,
0722 TULocalVisible,
0723 };
0724
0725
0726 bool ReadVisibleDeclContextStorage(ModuleFile &M,
0727 llvm::BitstreamCursor &Cursor,
0728 uint64_t Offset, GlobalDeclID ID,
0729 VisibleDeclContextStorageKind VisibleKind);
0730
0731 bool ReadSpecializations(ModuleFile &M, llvm::BitstreamCursor &Cursor,
0732 uint64_t Offset, Decl *D, bool IsPartial);
0733 void AddSpecializations(const Decl *D, const unsigned char *Data,
0734 ModuleFile &M, bool IsPartial);
0735
0736
0737
0738
0739
0740
0741
0742 std::vector<IdentifierInfo *> IdentifiersLoaded;
0743
0744
0745
0746
0747
0748
0749
0750 std::vector<MacroInfo *> MacrosLoaded;
0751
0752 using LoadedMacroInfo =
0753 std::pair<IdentifierInfo *, serialization::SubmoduleID>;
0754
0755
0756
0757
0758 llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;
0759
0760 using GlobalMacroMapType =
0761 ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>;
0762
0763
0764
0765
0766 GlobalMacroMapType GlobalMacroMap;
0767
0768
0769
0770
0771
0772 SmallVector<Module *, 2> SubmodulesLoaded;
0773
0774 using GlobalSubmoduleMapType =
0775 ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>;
0776
0777
0778
0779
0780 GlobalSubmoduleMapType GlobalSubmoduleMap;
0781
0782
0783 using HiddenNames = SmallVector<Decl *, 2>;
0784 using HiddenNamesMapType = llvm::DenseMap<Module *, HiddenNames>;
0785
0786
0787
0788 HiddenNamesMapType HiddenNamesMap;
0789
0790
0791 struct UnresolvedModuleRef {
0792
0793 ModuleFile *File;
0794
0795
0796 Module *Mod;
0797
0798
0799 enum { Import, Export, Conflict, Affecting } Kind;
0800
0801
0802 unsigned ID;
0803
0804
0805 LLVM_PREFERRED_TYPE(bool)
0806 unsigned IsWildcard : 1;
0807
0808
0809 StringRef String;
0810 };
0811
0812
0813
0814 SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs;
0815
0816
0817
0818
0819
0820
0821 SmallVector<Selector, 16> SelectorsLoaded;
0822
0823 using GlobalSelectorMapType =
0824 ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>;
0825
0826
0827
0828 GlobalSelectorMapType GlobalSelectorMap;
0829
0830
0831
0832 llvm::DenseMap<Selector, unsigned> SelectorGeneration;
0833
0834
0835
0836 llvm::DenseMap<Selector, bool> SelectorOutOfDate;
0837
0838 struct PendingMacroInfo {
0839 ModuleFile *M;
0840
0841 uint32_t MacroDirectivesOffset;
0842
0843 PendingMacroInfo(ModuleFile *M, uint32_t MacroDirectivesOffset)
0844 : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
0845 };
0846
0847 using PendingMacroIDsMap =
0848 llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2>>;
0849
0850
0851
0852 PendingMacroIDsMap PendingMacroIDs;
0853
0854 using GlobalPreprocessedEntityMapType =
0855 ContinuousRangeMap<unsigned, ModuleFile *, 4>;
0856
0857
0858
0859
0860 GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
0861
0862 using GlobalSkippedRangeMapType =
0863 ContinuousRangeMap<unsigned, ModuleFile *, 4>;
0864
0865
0866
0867 GlobalSkippedRangeMapType GlobalSkippedRangeMap;
0868
0869
0870
0871
0872
0873
0874
0875
0876
0877
0878
0879 SmallVector<GlobalDeclID, 16> EagerlyDeserializedDecls;
0880
0881
0882
0883
0884 SmallVector<GlobalDeclID, 16> VTablesToEmit;
0885
0886
0887
0888
0889
0890
0891 SmallVector<GlobalDeclID, 16> TentativeDefinitions;
0892
0893
0894
0895
0896
0897
0898 struct VTableUse {
0899 GlobalDeclID ID;
0900 SourceLocation::UIntTy RawLoc;
0901 bool Used;
0902 };
0903 SmallVector<VTableUse> VTableUses;
0904
0905
0906
0907
0908
0909
0910
0911 struct PendingInstantiation {
0912 GlobalDeclID ID;
0913 SourceLocation::UIntTy RawLoc;
0914 };
0915 SmallVector<PendingInstantiation, 64> PendingInstantiations;
0916
0917
0918
0919
0920
0921
0922
0923
0924
0925 SmallVector<GlobalDeclID, 16> UnusedFileScopedDecls;
0926
0927
0928
0929 SmallVector<GlobalDeclID, 4> DelegatingCtorDecls;
0930
0931
0932
0933 SmallVector<serialization::SelectorID, 64> ReferencedSelectorsData;
0934
0935
0936
0937 SmallVector<serialization::IdentifierID, 64> WeakUndeclaredIdentifiers;
0938
0939
0940
0941
0942 SmallVector<GlobalDeclID, 4> ExtVectorDecls;
0943
0944
0945
0946
0947
0948
0949
0950
0951
0952
0953 SmallVector<GlobalDeclID, 16> UnusedLocalTypedefNameCandidates;
0954
0955
0956
0957 unsigned ForceHostDeviceDepth = 0;
0958
0959
0960
0961
0962 SmallVector<GlobalDeclID, 4> SemaDeclRefs;
0963
0964
0965
0966
0967 SmallVector<serialization::TypeID, 16> SpecialTypes;
0968
0969
0970
0971
0972
0973 SmallVector<GlobalDeclID, 2> CUDASpecialDeclRefs;
0974
0975
0976 SmallVector<uint64_t, 1> FPPragmaOptions;
0977
0978
0979 SourceLocation OptimizeOffPragmaLocation;
0980
0981
0982 int PragmaMSStructState = -1;
0983
0984
0985 int PragmaMSPointersToMembersState = -1;
0986 SourceLocation PointersToMembersPragmaLocation;
0987
0988
0989 std::optional<FPOptionsOverride> FpPragmaCurrentValue;
0990 SourceLocation FpPragmaCurrentLocation;
0991 struct FpPragmaStackEntry {
0992 FPOptionsOverride Value;
0993 SourceLocation Location;
0994 SourceLocation PushLocation;
0995 StringRef SlotLabel;
0996 };
0997 llvm::SmallVector<FpPragmaStackEntry, 2> FpPragmaStack;
0998 llvm::SmallVector<std::string, 2> FpPragmaStrings;
0999
1000
1001 std::optional<Sema::AlignPackInfo> PragmaAlignPackCurrentValue;
1002 SourceLocation PragmaAlignPackCurrentLocation;
1003 struct PragmaAlignPackStackEntry {
1004 Sema::AlignPackInfo Value;
1005 SourceLocation Location;
1006 SourceLocation PushLocation;
1007 StringRef SlotLabel;
1008 };
1009 llvm::SmallVector<PragmaAlignPackStackEntry, 2> PragmaAlignPackStack;
1010 llvm::SmallVector<std::string, 2> PragmaAlignPackStrings;
1011
1012
1013 OpenCLOptions OpenCLExtensions;
1014
1015
1016 llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap;
1017
1018
1019 llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap;
1020
1021
1022 SmallVector<GlobalDeclID, 4> KnownNamespaces;
1023
1024
1025
1026 struct UndefinedButUsedDecl {
1027 GlobalDeclID ID;
1028 SourceLocation::UIntTy RawLoc;
1029 };
1030 SmallVector<UndefinedButUsedDecl, 8> UndefinedButUsed;
1031
1032
1033 SmallVector<uint64_t, 8> DelayedDeleteExprs;
1034
1035
1036 SmallVector<std::pair<ModuleFile *, SmallVector<uint64_t, 1>>, 4>
1037 LateParsedTemplates;
1038
1039
1040
1041
1042 llvm::SmallSetVector<GlobalDeclID, 4> DeclsToCheckForDeferredDiags;
1043
1044
1045 SmallVector<GlobalDeclID> DeclsWithEffectsToVerify;
1046
1047 private:
1048 struct ImportedSubmodule {
1049 serialization::SubmoduleID ID;
1050 SourceLocation ImportLoc;
1051
1052 ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc)
1053 : ID(ID), ImportLoc(ImportLoc) {}
1054 };
1055
1056
1057
1058
1059
1060 SmallVector<ImportedSubmodule, 2> PendingImportedModules;
1061
1062
1063
1064 SmallVector<ImportedSubmodule, 2> PendingImportedModulesSema;
1065
1066
1067
1068
1069 std::string isysroot;
1070
1071
1072
1073 DisableValidationForModuleKind DisableValidationKind;
1074
1075
1076 bool AllowASTWithCompilerErrors;
1077
1078
1079
1080 bool AllowConfigurationMismatch;
1081
1082
1083 bool ValidateSystemInputs;
1084
1085
1086 bool ValidateASTInputFilesContent;
1087
1088
1089 bool UseGlobalIndex;
1090
1091
1092 bool TriedLoadingGlobalIndex = false;
1093
1094
1095 bool ProcessingUpdateRecords = false;
1096
1097 using SwitchCaseMapTy = llvm::DenseMap<unsigned, SwitchCase *>;
1098
1099
1100
1101
1102
1103 SwitchCaseMapTy SwitchCaseStmts;
1104
1105 SwitchCaseMapTy *CurrSwitchCaseStmts;
1106
1107
1108
1109 unsigned NumSLocEntriesRead = 0;
1110
1111
1112 unsigned TotalNumSLocEntries = 0;
1113
1114
1115
1116 unsigned NumStatementsRead = 0;
1117
1118
1119
1120 unsigned TotalNumStatements = 0;
1121
1122
1123 unsigned NumMacrosRead = 0;
1124
1125
1126 unsigned TotalNumMacros = 0;
1127
1128
1129 unsigned NumIdentifierLookups = 0;
1130
1131
1132 unsigned NumIdentifierLookupHits = 0;
1133
1134
1135 unsigned NumSelectorsRead = 0;
1136
1137
1138 unsigned NumMethodPoolEntriesRead = 0;
1139
1140
1141
1142 unsigned NumMethodPoolLookups = 0;
1143
1144
1145
1146 unsigned NumMethodPoolHits = 0;
1147
1148
1149
1150 unsigned NumMethodPoolTableLookups = 0;
1151
1152
1153
1154 unsigned NumMethodPoolTableHits = 0;
1155
1156
1157 unsigned TotalNumMethodPoolEntries = 0;
1158
1159
1160 unsigned NumLexicalDeclContextsRead = 0, TotalLexicalDeclContexts = 0;
1161
1162
1163 unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0;
1164
1165
1166 unsigned NumModuleLocalVisibleDeclContexts = 0,
1167 TotalModuleLocalVisibleDeclContexts = 0;
1168
1169
1170 unsigned NumTULocalVisibleDeclContexts = 0,
1171 TotalTULocalVisibleDeclContexts = 0;
1172
1173
1174 uint64_t TotalModulesSizeInBits = 0;
1175
1176
1177 unsigned NumCurrentElementsDeserializing = 0;
1178
1179
1180
1181
1182
1183 bool PassingDeclsToConsumer = false;
1184
1185
1186
1187
1188
1189
1190 llvm::MapVector<IdentifierInfo *, SmallVector<GlobalDeclID, 4>>
1191 PendingIdentifierInfos;
1192
1193
1194
1195 llvm::SmallMapVector<const IdentifierInfo *, SmallVector<NamedDecl *, 2>, 16>
1196 PendingFakeLookupResults;
1197
1198
1199
1200 llvm::DenseMap<const IdentifierInfo *, unsigned> IdentifierGeneration;
1201
1202
1203
1204
1205
1206
1207
1208 std::deque<Decl *> PotentiallyInterestingDecls;
1209
1210
1211
1212
1213 SmallVector<std::pair<FunctionDecl *, serialization::TypeID>, 16>
1214 PendingDeducedFunctionTypes;
1215
1216
1217
1218
1219 SmallVector<std::pair<VarDecl *, serialization::TypeID>, 16>
1220 PendingDeducedVarTypes;
1221
1222
1223
1224
1225 SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains;
1226
1227
1228
1229 SmallVector<Decl *, 16> PendingIncompleteDeclChains;
1230
1231
1232
1233 struct PendingDeclContextInfo {
1234 Decl *D;
1235 GlobalDeclID SemaDC;
1236 GlobalDeclID LexicalDC;
1237 };
1238
1239
1240
1241
1242
1243
1244 std::deque<PendingDeclContextInfo> PendingDeclContextInfos;
1245
1246 template <typename DeclTy>
1247 using DuplicateObjCDecls = std::pair<DeclTy *, DeclTy *>;
1248
1249
1250
1251
1252
1253 llvm::SmallMapVector<DuplicateObjCDecls<ObjCCategoryDecl>,
1254 llvm::SmallVector<DuplicateObjCDecls<ObjCIvarDecl>, 4>,
1255 2>
1256 PendingObjCExtensionIvarRedeclarations;
1257
1258
1259
1260
1261 SmallVector<std::pair<CXXRecordDecl*, Decl*>, 4> PendingAddedClassMembers;
1262
1263
1264
1265
1266
1267
1268
1269 llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
1270
1271 using DataPointers =
1272 std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
1273 using ObjCInterfaceDataPointers =
1274 std::pair<ObjCInterfaceDecl *,
1275 struct ObjCInterfaceDecl::DefinitionData *>;
1276 using ObjCProtocolDataPointers =
1277 std::pair<ObjCProtocolDecl *, struct ObjCProtocolDecl::DefinitionData *>;
1278
1279
1280 llvm::SmallDenseMap<CXXRecordDecl *, llvm::SmallVector<DataPointers, 2>, 2>
1281 PendingOdrMergeFailures;
1282
1283
1284 llvm::SmallDenseMap<RecordDecl *, llvm::SmallVector<RecordDecl *, 2>, 2>
1285 PendingRecordOdrMergeFailures;
1286
1287
1288 llvm::SmallDenseMap<FunctionDecl *, llvm::SmallVector<FunctionDecl *, 2>, 2>
1289 PendingFunctionOdrMergeFailures;
1290
1291
1292 llvm::SmallDenseMap<EnumDecl *, llvm::SmallVector<EnumDecl *, 2>, 2>
1293 PendingEnumOdrMergeFailures;
1294
1295
1296 llvm::SmallDenseMap<ObjCInterfaceDecl *,
1297 llvm::SmallVector<ObjCInterfaceDataPointers, 2>, 2>
1298 PendingObjCInterfaceOdrMergeFailures;
1299
1300
1301 llvm::SmallDenseMap<ObjCProtocolDecl *,
1302 llvm::SmallVector<ObjCProtocolDataPointers, 2>, 2>
1303 PendingObjCProtocolOdrMergeFailures;
1304
1305
1306 llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures;
1307
1308
1309
1310 llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
1311
1312
1313
1314
1315 SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
1316
1317 using KeyDeclsMap = llvm::DenseMap<Decl *, SmallVector<GlobalDeclID, 2>>;
1318
1319
1320
1321
1322
1323
1324 KeyDeclsMap KeyDecls;
1325
1326
1327
1328
1329 llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts;
1330
1331
1332
1333 llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions;
1334
1335
1336
1337 llvm::DenseMap<RecordDecl *, RecordDecl *> RecordDefinitions;
1338
1339
1340 SmallVector<Stmt *, 16> StmtStack;
1341
1342
1343 enum ReadingKind {
1344 Read_None, Read_Decl, Read_Type, Read_Stmt
1345 };
1346
1347
1348 ReadingKind ReadingKind = Read_None;
1349
1350
1351 class ReadingKindTracker {
1352 ASTReader &Reader;
1353 enum ReadingKind PrevKind;
1354
1355 public:
1356 ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
1357 : Reader(reader), PrevKind(Reader.ReadingKind) {
1358 Reader.ReadingKind = newKind;
1359 }
1360
1361 ReadingKindTracker(const ReadingKindTracker &) = delete;
1362 ReadingKindTracker &operator=(const ReadingKindTracker &) = delete;
1363 ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
1364 };
1365
1366
1367 class ProcessingUpdatesRAIIObj {
1368 ASTReader &Reader;
1369 bool PrevState;
1370
1371 public:
1372 ProcessingUpdatesRAIIObj(ASTReader &reader)
1373 : Reader(reader), PrevState(Reader.ProcessingUpdateRecords) {
1374 Reader.ProcessingUpdateRecords = true;
1375 }
1376
1377 ProcessingUpdatesRAIIObj(const ProcessingUpdatesRAIIObj &) = delete;
1378 ProcessingUpdatesRAIIObj &
1379 operator=(const ProcessingUpdatesRAIIObj &) = delete;
1380 ~ProcessingUpdatesRAIIObj() { Reader.ProcessingUpdateRecords = PrevState; }
1381 };
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391 std::string SuggestedPredefines;
1392
1393 llvm::DenseMap<const Decl *, bool> DefinitionSource;
1394
1395 bool shouldDisableValidationForFile(const serialization::ModuleFile &M) const;
1396
1397
1398 Stmt *ReadStmtFromStream(ModuleFile &F);
1399
1400
1401 serialization::InputFileInfo getInputFileInfo(ModuleFile &F, unsigned ID);
1402
1403
1404
1405 serialization::InputFile getInputFile(ModuleFile &F, unsigned ID,
1406 bool Complain = true);
1407
1408
1409 SmallString<0> PathBuf;
1410
1411
1412 class TemporarilyOwnedStringRef {
1413 StringRef String;
1414 llvm::SaveAndRestore<SmallString<0>> UnderlyingBuffer;
1415
1416 public:
1417 TemporarilyOwnedStringRef(StringRef S, SmallString<0> &UnderlyingBuffer)
1418 : String(S), UnderlyingBuffer(UnderlyingBuffer, {}) {}
1419
1420
1421 const StringRef *operator->() const & { return &String; }
1422 const StringRef &operator*() const & { return String; }
1423
1424
1425 const StringRef *operator->() && = delete;
1426 const StringRef &operator*() && = delete;
1427 };
1428
1429 public:
1430
1431 SmallString<0> &getPathBuf() { return PathBuf; }
1432
1433
1434
1435 static TemporarilyOwnedStringRef
1436 ResolveImportedPath(SmallString<0> &Buf, StringRef Path, ModuleFile &ModF);
1437
1438
1439 static TemporarilyOwnedStringRef
1440 ResolveImportedPath(SmallString<0> &Buf, StringRef Path, StringRef Prefix);
1441
1442
1443 static std::string ResolveImportedPathAndAllocate(SmallString<0> &Buf,
1444 StringRef Path,
1445 ModuleFile &ModF);
1446
1447 static std::string ResolveImportedPathAndAllocate(SmallString<0> &Buf,
1448 StringRef Path,
1449 StringRef Prefix);
1450
1451
1452
1453
1454 Decl *getKeyDeclaration(Decl *D) {
1455 D = D->getCanonicalDecl();
1456 if (D->isFromASTFile())
1457 return D;
1458
1459 auto I = KeyDecls.find(D);
1460 if (I == KeyDecls.end() || I->second.empty())
1461 return D;
1462 return GetExistingDecl(I->second[0]);
1463 }
1464 const Decl *getKeyDeclaration(const Decl *D) {
1465 return getKeyDeclaration(const_cast<Decl*>(D));
1466 }
1467
1468
1469 template <typename Fn>
1470 void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1471 D = D->getCanonicalDecl();
1472 if (D->isFromASTFile())
1473 Visit(D);
1474
1475 auto It = KeyDecls.find(const_cast<Decl*>(D));
1476 if (It != KeyDecls.end())
1477 for (auto ID : It->second)
1478 Visit(GetExistingDecl(ID));
1479 }
1480
1481
1482 const serialization::reader::DeclContextLookupTable *
1483 getLoadedLookupTables(DeclContext *Primary) const;
1484
1485 const serialization::reader::ModuleLocalLookupTable *
1486 getModuleLocalLookupTables(DeclContext *Primary) const;
1487
1488 const serialization::reader::DeclContextLookupTable *
1489 getTULocalLookupTables(DeclContext *Primary) const;
1490
1491
1492
1493 serialization::reader::LazySpecializationInfoLookupTable *
1494 getLoadedSpecializationsLookupTables(const Decl *D, bool IsPartial);
1495
1496
1497 bool haveUnloadedSpecializations(const Decl *D) const;
1498
1499 private:
1500 struct ImportedModule {
1501 ModuleFile *Mod;
1502 ModuleFile *ImportedBy;
1503 SourceLocation ImportLoc;
1504
1505 ImportedModule(ModuleFile *Mod,
1506 ModuleFile *ImportedBy,
1507 SourceLocation ImportLoc)
1508 : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) {}
1509 };
1510
1511 ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
1512 SourceLocation ImportLoc, ModuleFile *ImportedBy,
1513 SmallVectorImpl<ImportedModule> &Loaded,
1514 off_t ExpectedSize, time_t ExpectedModTime,
1515 ASTFileSignature ExpectedSignature,
1516 unsigned ClientLoadCapabilities);
1517 ASTReadResult ReadControlBlock(ModuleFile &F,
1518 SmallVectorImpl<ImportedModule> &Loaded,
1519 const ModuleFile *ImportedBy,
1520 unsigned ClientLoadCapabilities);
1521 static ASTReadResult
1522 ReadOptionsBlock(llvm::BitstreamCursor &Stream, StringRef Filename,
1523 unsigned ClientLoadCapabilities,
1524 bool AllowCompatibleConfigurationMismatch,
1525 ASTReaderListener &Listener,
1526 std::string &SuggestedPredefines);
1527
1528
1529
1530
1531
1532 ASTReadResult readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy,
1533 unsigned ClientLoadCapabilities);
1534
1535 static ASTReadResult readUnhashedControlBlockImpl(
1536 ModuleFile *F, llvm::StringRef StreamData, StringRef Filename,
1537 unsigned ClientLoadCapabilities,
1538 bool AllowCompatibleConfigurationMismatch, ASTReaderListener *Listener,
1539 bool ValidateDiagnosticOptions);
1540
1541 llvm::Error ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities);
1542 llvm::Error ReadExtensionBlock(ModuleFile &F);
1543 void ReadModuleOffsetMap(ModuleFile &F) const;
1544 void ParseLineTable(ModuleFile &F, const RecordData &Record);
1545 llvm::Error ReadSourceManagerBlock(ModuleFile &F);
1546 SourceLocation getImportLocation(ModuleFile *F);
1547 ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
1548 const ModuleFile *ImportedBy,
1549 unsigned ClientLoadCapabilities);
1550 llvm::Error ReadSubmoduleBlock(ModuleFile &F,
1551 unsigned ClientLoadCapabilities);
1552 static bool ParseLanguageOptions(const RecordData &Record,
1553 StringRef ModuleFilename, bool Complain,
1554 ASTReaderListener &Listener,
1555 bool AllowCompatibleDifferences);
1556 static bool ParseTargetOptions(const RecordData &Record,
1557 StringRef ModuleFilename, bool Complain,
1558 ASTReaderListener &Listener,
1559 bool AllowCompatibleDifferences);
1560 static bool ParseDiagnosticOptions(const RecordData &Record,
1561 StringRef ModuleFilename, bool Complain,
1562 ASTReaderListener &Listener);
1563 static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
1564 ASTReaderListener &Listener);
1565 static bool ParseHeaderSearchOptions(const RecordData &Record,
1566 StringRef ModuleFilename, bool Complain,
1567 ASTReaderListener &Listener);
1568 static bool ParseHeaderSearchPaths(const RecordData &Record, bool Complain,
1569 ASTReaderListener &Listener);
1570 static bool ParsePreprocessorOptions(const RecordData &Record,
1571 StringRef ModuleFilename, bool Complain,
1572 ASTReaderListener &Listener,
1573 std::string &SuggestedPredefines);
1574
1575 struct RecordLocation {
1576 ModuleFile *F;
1577 uint64_t Offset;
1578
1579 RecordLocation(ModuleFile *M, uint64_t O) : F(M), Offset(O) {}
1580 };
1581
1582 QualType readTypeRecord(serialization::TypeID ID);
1583 RecordLocation TypeCursorForIndex(serialization::TypeID ID);
1584 void LoadedDecl(unsigned Index, Decl *D);
1585 Decl *ReadDeclRecord(GlobalDeclID ID);
1586 void markIncompleteDeclChain(Decl *D);
1587
1588
1589
1590
1591 Decl *getMostRecentExistingDecl(Decl *D);
1592
1593 RecordLocation DeclCursorForID(GlobalDeclID ID, SourceLocation &Location);
1594 void loadDeclUpdateRecords(PendingUpdateRecord &Record);
1595 void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
1596 void loadObjCCategories(GlobalDeclID ID, ObjCInterfaceDecl *D,
1597 unsigned PreviousGeneration = 0);
1598
1599 RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
1600 uint64_t getGlobalBitOffset(ModuleFile &M, uint64_t LocalOffset);
1601
1602
1603
1604 serialization::PreprocessedEntityID
1605 findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const;
1606
1607
1608
1609
1610
1611
1612
1613 serialization::PreprocessedEntityID
1614 findNextPreprocessedEntity(
1615 GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
1616
1617
1618
1619 std::pair<ModuleFile *, unsigned>
1620 getModulePreprocessedEntity(unsigned GlobalIndex);
1621
1622
1623
1624 llvm::iterator_range<PreprocessingRecord::iterator>
1625 getModulePreprocessedEntities(ModuleFile &Mod) const;
1626
1627 bool canRecoverFromOutOfDate(StringRef ModuleFileName,
1628 unsigned ClientLoadCapabilities);
1629
1630 public:
1631 class ModuleDeclIterator
1632 : public llvm::iterator_adaptor_base<
1633 ModuleDeclIterator, const serialization::unaligned_decl_id_t *,
1634 std::random_access_iterator_tag, const Decl *, ptrdiff_t,
1635 const Decl *, const Decl *> {
1636 ASTReader *Reader = nullptr;
1637 ModuleFile *Mod = nullptr;
1638
1639 public:
1640 ModuleDeclIterator() : iterator_adaptor_base(nullptr) {}
1641
1642 ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod,
1643 const serialization::unaligned_decl_id_t *Pos)
1644 : iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {}
1645
1646 value_type operator*() const {
1647 LocalDeclID ID = LocalDeclID::get(*Reader, *Mod, *I);
1648 return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, ID));
1649 }
1650
1651 value_type operator->() const { return **this; }
1652
1653 bool operator==(const ModuleDeclIterator &RHS) const {
1654 assert(Reader == RHS.Reader && Mod == RHS.Mod);
1655 return I == RHS.I;
1656 }
1657 };
1658
1659 llvm::iterator_range<ModuleDeclIterator>
1660 getModuleFileLevelDecls(ModuleFile &Mod);
1661
1662 private:
1663 bool isConsumerInterestedIn(Decl *D);
1664 void PassInterestingDeclsToConsumer();
1665 void PassInterestingDeclToConsumer(Decl *D);
1666 void PassVTableToConsumer(CXXRecordDecl *RD);
1667
1668 void finishPendingActions();
1669 void diagnoseOdrViolations();
1670
1671 void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
1672
1673 void addPendingDeclContextInfo(Decl *D, GlobalDeclID SemaDC,
1674 GlobalDeclID LexicalDC) {
1675 assert(D);
1676 PendingDeclContextInfo Info = { D, SemaDC, LexicalDC };
1677 PendingDeclContextInfos.push_back(Info);
1678 }
1679
1680
1681
1682
1683
1684 void Error(StringRef Msg) const;
1685 void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
1686 StringRef Arg2 = StringRef(), StringRef Arg3 = StringRef()) const;
1687 void Error(llvm::Error &&Err) const;
1688
1689
1690 unsigned translateGlobalDeclIDToIndex(GlobalDeclID ID) const;
1691
1692
1693
1694 std::pair<ModuleFile *, unsigned>
1695 translateIdentifierIDToIndex(serialization::IdentifierID ID) const;
1696
1697
1698
1699 std::pair<ModuleFile *, unsigned>
1700 translateTypeIDToIndex(serialization::TypeID ID) const;
1701
1702
1703 Decl *getPredefinedDecl(PredefinedDeclIDs ID);
1704
1705 public:
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745 ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1746 ASTContext *Context, const PCHContainerReader &PCHContainerRdr,
1747 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
1748 StringRef isysroot = "",
1749 DisableValidationForModuleKind DisableValidationKind =
1750 DisableValidationForModuleKind::None,
1751 bool AllowASTWithCompilerErrors = false,
1752 bool AllowConfigurationMismatch = false,
1753 bool ValidateSystemInputs = false,
1754 bool ValidateASTInputFilesContent = false,
1755 bool UseGlobalIndex = true,
1756 std::unique_ptr<llvm::Timer> ReadTimer = {});
1757 ASTReader(const ASTReader &) = delete;
1758 ASTReader &operator=(const ASTReader &) = delete;
1759 ~ASTReader() override;
1760
1761 SourceManager &getSourceManager() const { return SourceMgr; }
1762 FileManager &getFileManager() const { return FileMgr; }
1763 DiagnosticsEngine &getDiags() const { return Diags; }
1764
1765
1766
1767
1768
1769
1770 enum LoadFailureCapabilities {
1771
1772 ARR_None = 0,
1773
1774
1775
1776 ARR_Missing = 0x1,
1777
1778
1779
1780 ARR_OutOfDate = 0x2,
1781
1782
1783
1784 ARR_VersionMismatch = 0x4,
1785
1786
1787
1788
1789 ARR_ConfigurationMismatch = 0x8,
1790
1791
1792
1793 ARR_TreatModuleWithErrorsAsOutOfDate = 0x10
1794 };
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817 ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
1818 SourceLocation ImportLoc,
1819 unsigned ClientLoadCapabilities,
1820 ModuleFile **NewLoadedModuleFile = nullptr);
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831 void makeModuleVisible(Module *Mod,
1832 Module::NameVisibilityKind NameVisibility,
1833 SourceLocation ImportLoc);
1834
1835
1836 void makeNamesVisible(const HiddenNames &Names, Module *Owner);
1837
1838
1839
1840 void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef);
1841
1842
1843 std::unique_ptr<ASTReaderListener> takeListener() {
1844 return std::move(Listener);
1845 }
1846
1847
1848 void setListener(std::unique_ptr<ASTReaderListener> Listener) {
1849 this->Listener = std::move(Listener);
1850 }
1851
1852
1853
1854
1855 void addListener(std::unique_ptr<ASTReaderListener> L) {
1856 if (Listener)
1857 L = std::make_unique<ChainedASTReaderListener>(std::move(L),
1858 std::move(Listener));
1859 Listener = std::move(L);
1860 }
1861
1862
1863 class ListenerScope {
1864 ASTReader &Reader;
1865 bool Chained = false;
1866
1867 public:
1868 ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L)
1869 : Reader(Reader) {
1870 auto Old = Reader.takeListener();
1871 if (Old) {
1872 Chained = true;
1873 L = std::make_unique<ChainedASTReaderListener>(std::move(L),
1874 std::move(Old));
1875 }
1876 Reader.setListener(std::move(L));
1877 }
1878
1879 ~ListenerScope() {
1880 auto New = Reader.takeListener();
1881 if (Chained)
1882 Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get())
1883 ->takeSecond());
1884 }
1885 };
1886
1887
1888 void setDeserializationListener(ASTDeserializationListener *Listener,
1889 bool TakeOwnership = false);
1890
1891
1892 ASTDeserializationListener *getDeserializationListener() {
1893 return DeserializationListener;
1894 }
1895
1896
1897 bool hasGlobalIndex() const { return (bool)GlobalIndex; }
1898
1899
1900 GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); }
1901
1902
1903 void resetForReload() { TriedLoadingGlobalIndex = false; }
1904
1905
1906
1907
1908 bool loadGlobalIndex();
1909
1910
1911
1912 bool isGlobalIndexUnavailable() const;
1913
1914
1915 void InitializeContext();
1916
1917
1918 void UpdateSema();
1919
1920
1921 void addInMemoryBuffer(StringRef &FileName,
1922 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
1923 ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer));
1924 }
1925
1926
1927
1928
1929
1930
1931 void finalizeForWriting();
1932
1933
1934 ModuleManager &getModuleManager() { return ModuleMgr; }
1935 const ModuleManager &getModuleManager() const { return ModuleMgr; }
1936
1937
1938 Preprocessor &getPreprocessor() const { return PP; }
1939
1940
1941
1942 StringRef getOriginalSourceFile() {
1943 return ModuleMgr.getPrimaryModule().OriginalSourceFileName;
1944 }
1945
1946
1947
1948 static std::string
1949 getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr,
1950 const PCHContainerReader &PCHContainerRdr,
1951 DiagnosticsEngine &Diags);
1952
1953
1954
1955
1956 static bool readASTFileControlBlock(
1957 StringRef Filename, FileManager &FileMgr,
1958 const InMemoryModuleCache &ModuleCache,
1959 const PCHContainerReader &PCHContainerRdr, bool FindModuleFileExtensions,
1960 ASTReaderListener &Listener, bool ValidateDiagnosticOptions,
1961 unsigned ClientLoadCapabilities = ARR_ConfigurationMismatch |
1962 ARR_OutOfDate);
1963
1964
1965
1966 static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr,
1967 const InMemoryModuleCache &ModuleCache,
1968 const PCHContainerReader &PCHContainerRdr,
1969 const LangOptions &LangOpts,
1970 const TargetOptions &TargetOpts,
1971 const PreprocessorOptions &PPOpts,
1972 StringRef ExistingModuleCachePath,
1973 bool RequireStrictOptionMatches = false);
1974
1975
1976
1977
1978 const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
1979
1980
1981
1982
1983
1984 PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override;
1985
1986
1987
1988 std::pair<unsigned, unsigned>
1989 findPreprocessedEntitiesInRange(SourceRange Range) override;
1990
1991
1992
1993 std::optional<bool> isPreprocessedEntityInFileID(unsigned Index,
1994 FileID FID) override;
1995
1996
1997 SourceRange ReadSkippedRange(unsigned Index) override;
1998
1999
2000 HeaderFileInfo GetHeaderFileInfo(FileEntryRef FE) override;
2001
2002 void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
2003
2004
2005 unsigned getTotalNumSLocs() const {
2006 return TotalNumSLocEntries;
2007 }
2008
2009
2010 unsigned getTotalNumIdentifiers() const {
2011 return static_cast<unsigned>(IdentifiersLoaded.size());
2012 }
2013
2014
2015 unsigned getTotalNumMacros() const {
2016 return static_cast<unsigned>(MacrosLoaded.size());
2017 }
2018
2019
2020 unsigned getTotalNumTypes() const {
2021 return static_cast<unsigned>(TypesLoaded.size());
2022 }
2023
2024
2025 unsigned getTotalNumDecls() const {
2026 return static_cast<unsigned>(DeclsLoaded.size());
2027 }
2028
2029
2030 unsigned getTotalNumSubmodules() const {
2031 return static_cast<unsigned>(SubmodulesLoaded.size());
2032 }
2033
2034
2035 unsigned getTotalNumSelectors() const {
2036 return static_cast<unsigned>(SelectorsLoaded.size());
2037 }
2038
2039
2040
2041 unsigned getTotalNumPreprocessedEntities() const {
2042 unsigned Result = 0;
2043 for (const auto &M : ModuleMgr)
2044 Result += M.NumPreprocessedEntities;
2045 return Result;
2046 }
2047
2048
2049
2050 QualType GetType(serialization::TypeID ID);
2051
2052
2053 QualType getLocalType(ModuleFile &F, serialization::LocalTypeID LocalID);
2054
2055
2056 serialization::TypeID
2057 getGlobalTypeID(ModuleFile &F, serialization::LocalTypeID LocalID) const;
2058
2059
2060
2061 QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
2062 if (Idx >= Record.size())
2063 return {};
2064
2065 return getLocalType(F, Record[Idx++]);
2066 }
2067
2068
2069
2070 GlobalDeclID getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const;
2071
2072
2073 bool isDeclIDFromModule(GlobalDeclID ID, ModuleFile &M) const;
2074
2075
2076
2077 ModuleFile *getOwningModuleFile(const Decl *D) const;
2078 ModuleFile *getOwningModuleFile(GlobalDeclID ID) const;
2079
2080
2081 SourceLocation getSourceLocationForDeclID(GlobalDeclID ID);
2082
2083
2084
2085 Decl *GetDecl(GlobalDeclID ID);
2086 Decl *GetExternalDecl(GlobalDeclID ID) override;
2087
2088
2089
2090 Decl *GetExistingDecl(GlobalDeclID ID);
2091
2092
2093 Decl *GetLocalDecl(ModuleFile &F, LocalDeclID LocalID) {
2094 return GetDecl(getGlobalDeclID(F, LocalID));
2095 }
2096
2097
2098
2099
2100 template <typename T> T *GetLocalDeclAs(ModuleFile &F, LocalDeclID LocalID) {
2101 return cast_or_null<T>(GetLocalDecl(F, LocalID));
2102 }
2103
2104
2105
2106
2107
2108
2109 LocalDeclID mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
2110 GlobalDeclID GlobalID);
2111
2112
2113
2114
2115
2116 GlobalDeclID ReadDeclID(ModuleFile &F, const RecordDataImpl &Record,
2117 unsigned &Idx);
2118
2119
2120
2121 Decl *ReadDecl(ModuleFile &F, const RecordDataImpl &R, unsigned &I) {
2122 return GetDecl(ReadDeclID(F, R, I));
2123 }
2124
2125
2126
2127
2128
2129
2130 template <typename T>
2131 T *ReadDeclAs(ModuleFile &F, const RecordDataImpl &R, unsigned &I) {
2132 return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
2133 }
2134
2135
2136
2137
2138 void CompleteRedeclChain(const Decl *D) override;
2139
2140 CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
2141
2142
2143
2144
2145
2146
2147 Stmt *GetExternalDeclStmt(uint64_t Offset) override;
2148
2149
2150
2151
2152 static llvm::Error ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor,
2153 unsigned BlockID,
2154 uint64_t *StartOfBlockOffset = nullptr);
2155
2156 bool LoadExternalSpecializations(const Decl *D, bool OnlyPartial) override;
2157
2158 bool
2159 LoadExternalSpecializations(const Decl *D,
2160 ArrayRef<TemplateArgument> TemplateArgs) override;
2161
2162
2163
2164
2165 bool FindExternalVisibleDeclsByName(const DeclContext *DC,
2166 DeclarationName Name,
2167 const DeclContext *OriginalDC) override;
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182 void
2183 FindExternalLexicalDecls(const DeclContext *DC,
2184 llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
2185 SmallVectorImpl<Decl *> &Decls) override;
2186
2187
2188
2189
2190 void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
2191 SmallVectorImpl<Decl *> &Decls) override;
2192
2193
2194
2195
2196 void StartedDeserializing() override;
2197
2198
2199
2200 void FinishedDeserializing() override;
2201
2202
2203
2204
2205
2206
2207 void StartTranslationUnit(ASTConsumer *Consumer) override;
2208
2209
2210 void PrintStats() override;
2211
2212
2213 void dump();
2214
2215
2216
2217 void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
2218
2219
2220
2221
2222 void InitializeSema(Sema &S) override;
2223
2224
2225 void ForgetSema() override { SemaObj = nullptr; }
2226
2227
2228
2229
2230
2231
2232
2233 IdentifierInfo *get(StringRef Name) override;
2234
2235
2236
2237 IdentifierIterator *getIdentifiers() override;
2238
2239
2240
2241 void ReadMethodPool(Selector Sel) override;
2242
2243
2244
2245 void updateOutOfDateSelector(Selector Sel) override;
2246
2247
2248
2249 void ReadKnownNamespaces(
2250 SmallVectorImpl<NamespaceDecl *> &Namespaces) override;
2251
2252 void ReadUndefinedButUsed(
2253 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
2254
2255 void ReadMismatchingDeleteExpressions(llvm::MapVector<
2256 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
2257 Exprs) override;
2258
2259 void ReadTentativeDefinitions(
2260 SmallVectorImpl<VarDecl *> &TentativeDefs) override;
2261
2262 void ReadUnusedFileScopedDecls(
2263 SmallVectorImpl<const DeclaratorDecl *> &Decls) override;
2264
2265 void ReadDelegatingConstructors(
2266 SmallVectorImpl<CXXConstructorDecl *> &Decls) override;
2267
2268 void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override;
2269
2270 void ReadUnusedLocalTypedefNameCandidates(
2271 llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
2272
2273 void ReadDeclsToCheckForDeferredDiags(
2274 llvm::SmallSetVector<Decl *, 4> &Decls) override;
2275
2276 void ReadReferencedSelectors(
2277 SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) override;
2278
2279 void ReadWeakUndeclaredIdentifiers(
2280 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WeakIDs) override;
2281
2282 void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
2283
2284 void ReadPendingInstantiations(
2285 SmallVectorImpl<std::pair<ValueDecl *,
2286 SourceLocation>> &Pending) override;
2287
2288 void ReadLateParsedTemplates(
2289 llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
2290 &LPTMap) override;
2291
2292 void AssignedLambdaNumbering(CXXRecordDecl *Lambda) override;
2293
2294
2295 void LoadSelector(Selector Sel);
2296
2297 void SetIdentifierInfo(serialization::IdentifierID ID, IdentifierInfo *II);
2298 void SetGloballyVisibleDecls(IdentifierInfo *II,
2299 const SmallVectorImpl<GlobalDeclID> &DeclIDs,
2300 SmallVectorImpl<Decl *> *Decls = nullptr);
2301
2302
2303 DiagnosticBuilder Diag(unsigned DiagID) const;
2304
2305
2306 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const;
2307
2308 void runWithSufficientStackSpace(SourceLocation Loc,
2309 llvm::function_ref<void()> Fn);
2310
2311 IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
2312
2313 IdentifierInfo *readIdentifier(ModuleFile &M, const RecordData &Record,
2314 unsigned &Idx) {
2315 return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
2316 }
2317
2318 IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) override {
2319
2320 Deserializing AnIdentifier(this);
2321
2322 return DecodeIdentifierInfo(ID);
2323 }
2324
2325 IdentifierInfo *getLocalIdentifier(ModuleFile &M, uint64_t LocalID);
2326
2327 serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
2328 uint64_t LocalID);
2329
2330 void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);
2331
2332
2333 MacroInfo *getMacro(serialization::MacroID ID);
2334
2335
2336
2337 serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID);
2338
2339
2340 bool ReadSLocEntry(int ID) override;
2341
2342 int getSLocEntryID(SourceLocation::UIntTy SLocOffset) override;
2343
2344
2345 llvm::Expected<SourceLocation::UIntTy> readSLocOffset(ModuleFile *F,
2346 unsigned Index);
2347
2348
2349
2350 std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override;
2351
2352
2353
2354 serialization::SubmoduleID getGlobalSubmoduleID(ModuleFile &M,
2355 unsigned LocalID) const;
2356
2357
2358
2359 Module *getSubmodule(serialization::SubmoduleID GlobalID);
2360
2361
2362
2363
2364 Module *getModule(unsigned ID) override;
2365
2366
2367
2368 ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID) const;
2369
2370
2371 unsigned getModuleFileID(ModuleFile *M);
2372
2373
2374 std::optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override;
2375
2376 ExtKind hasExternalDefinitions(const Decl *D) override;
2377
2378
2379
2380 Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
2381
2382 Selector DecodeSelector(serialization::SelectorID Idx);
2383
2384 Selector GetExternalSelector(serialization::SelectorID ID) override;
2385 uint32_t GetNumExternalSelectors() override;
2386
2387 Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
2388 return getLocalSelector(M, Record[Idx++]);
2389 }
2390
2391
2392
2393 serialization::SelectorID getGlobalSelectorID(ModuleFile &M,
2394 unsigned LocalID) const;
2395
2396
2397 CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
2398
2399
2400 Sema::AlignPackInfo ReadAlignPackInfo(uint32_t Raw) const {
2401 return Sema::AlignPackInfo::getFromRawEncoding(Raw);
2402 }
2403
2404 using RawLocEncoding = SourceLocationEncoding::RawLocEncoding;
2405
2406
2407
2408 std::pair<SourceLocation, unsigned>
2409 ReadUntranslatedSourceLocation(RawLocEncoding Raw,
2410 LocSeq *Seq = nullptr) const {
2411 return SourceLocationEncoding::decode(Raw, Seq);
2412 }
2413
2414
2415 SourceLocation ReadSourceLocation(ModuleFile &MF, RawLocEncoding Raw,
2416 LocSeq *Seq = nullptr) const {
2417 if (!MF.ModuleOffsetMap.empty())
2418 ReadModuleOffsetMap(MF);
2419
2420 auto [Loc, ModuleFileIndex] = ReadUntranslatedSourceLocation(Raw, Seq);
2421 ModuleFile *OwningModuleFile =
2422 ModuleFileIndex == 0 ? &MF : MF.TransitiveImports[ModuleFileIndex - 1];
2423
2424 assert(!SourceMgr.isLoadedSourceLocation(Loc) &&
2425 "Run out source location space");
2426
2427 return TranslateSourceLocation(*OwningModuleFile, Loc);
2428 }
2429
2430
2431
2432 SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile,
2433 SourceLocation Loc) const {
2434 if (Loc.isInvalid())
2435 return Loc;
2436
2437
2438
2439
2440
2441
2442
2443 return Loc.getLocWithOffset(ModuleFile.SLocEntryBaseOffset - 2);
2444 }
2445
2446
2447 SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
2448 const RecordDataImpl &Record, unsigned &Idx,
2449 LocSeq *Seq = nullptr) {
2450 return ReadSourceLocation(ModuleFile, Record[Idx++], Seq);
2451 }
2452
2453
2454 FileID ReadFileID(ModuleFile &F, const RecordDataImpl &Record,
2455 unsigned &Idx) const {
2456 return TranslateFileID(F, FileID::get(Record[Idx++]));
2457 }
2458
2459
2460 FileID TranslateFileID(ModuleFile &F, FileID FID) const {
2461 assert(FID.ID >= 0 && "Reading non-local FileID.");
2462 if (FID.isInvalid())
2463 return FID;
2464 return FileID::get(F.SLocEntryBaseID + FID.ID - 1);
2465 }
2466
2467
2468 SourceRange ReadSourceRange(ModuleFile &F, const RecordData &Record,
2469 unsigned &Idx, LocSeq *Seq = nullptr);
2470
2471 static llvm::BitVector ReadBitVector(const RecordData &Record,
2472 const StringRef Blob);
2473
2474
2475 static std::string ReadString(const RecordDataImpl &Record, unsigned &Idx);
2476 static StringRef ReadStringBlob(const RecordDataImpl &Record, unsigned &Idx,
2477 StringRef &Blob);
2478
2479
2480 std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx);
2481
2482
2483 std::string ReadPath(StringRef BaseDirectory, const RecordData &Record,
2484 unsigned &Idx);
2485 std::string ReadPathBlob(StringRef BaseDirectory, const RecordData &Record,
2486 unsigned &Idx, StringRef &Blob);
2487
2488
2489 static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
2490
2491 CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
2492 unsigned &Idx);
2493
2494
2495 Stmt *ReadStmt(ModuleFile &F);
2496
2497
2498 Expr *ReadExpr(ModuleFile &F);
2499
2500
2501 Stmt *ReadSubStmt() {
2502 assert(ReadingKind == Read_Stmt &&
2503 "Should be called only during statement reading!");
2504
2505
2506 assert(!StmtStack.empty() && "Read too many sub-statements!");
2507 return StmtStack.pop_back_val();
2508 }
2509
2510
2511 Expr *ReadSubExpr();
2512
2513
2514 Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx);
2515
2516
2517 MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset);
2518
2519
2520
2521 serialization::PreprocessedEntityID
2522 getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
2523
2524
2525
2526
2527
2528
2529
2530 void addPendingMacro(IdentifierInfo *II, ModuleFile *M,
2531 uint32_t MacroDirectivesOffset);
2532
2533
2534 void ReadDefinedMacros() override;
2535
2536
2537 void updateOutOfDateIdentifier(const IdentifierInfo &II) override;
2538
2539
2540 void markIdentifierUpToDate(const IdentifierInfo *II);
2541
2542
2543 void completeVisibleDeclsMap(const DeclContext *DC) override;
2544
2545
2546 ASTContext &getContext() {
2547 assert(ContextObj && "requested AST context when not loading AST");
2548 return *ContextObj;
2549 }
2550
2551
2552
2553 SmallVector<GlobalDeclID, 16> PreloadedDeclIDs;
2554
2555
2556
2557
2558 Sema *getSema() { return SemaObj; }
2559
2560
2561
2562
2563 IdentifierResolver &getIdResolver();
2564
2565
2566
2567 IdentifierTable &getIdentifierTable();
2568
2569
2570
2571 void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
2572
2573
2574 SwitchCase *getSwitchCaseWithID(unsigned ID);
2575
2576 void ClearSwitchCaseIDs();
2577
2578
2579 SmallVector<std::pair<llvm::BitstreamCursor,
2580 serialization::ModuleFile *>, 8> CommentsCursors;
2581
2582
2583 void ReadComments() override;
2584
2585
2586 void visitInputFileInfos(
2587 serialization::ModuleFile &MF, bool IncludeSystem,
2588 llvm::function_ref<void(const serialization::InputFileInfo &IFI,
2589 bool IsSystem)>
2590 Visitor);
2591
2592
2593 void visitInputFiles(serialization::ModuleFile &MF,
2594 bool IncludeSystem, bool Complain,
2595 llvm::function_ref<void(const serialization::InputFile &IF,
2596 bool isSystem)> Visitor);
2597
2598
2599
2600 void visitTopLevelModuleMaps(serialization::ModuleFile &MF,
2601 llvm::function_ref<void(FileEntryRef)> Visitor);
2602
2603 bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; }
2604 };
2605
2606
2607
2608 class BitsUnpacker {
2609 constexpr static uint32_t BitsIndexUpbound = 32;
2610
2611 public:
2612 BitsUnpacker(uint32_t V) { updateValue(V); }
2613 BitsUnpacker(const BitsUnpacker &) = delete;
2614 BitsUnpacker(BitsUnpacker &&) = delete;
2615 BitsUnpacker operator=(const BitsUnpacker &) = delete;
2616 BitsUnpacker operator=(BitsUnpacker &&) = delete;
2617 ~BitsUnpacker() = default;
2618
2619 void updateValue(uint32_t V) {
2620 Value = V;
2621 CurrentBitsIndex = 0;
2622 }
2623
2624 void advance(uint32_t BitsWidth) { CurrentBitsIndex += BitsWidth; }
2625
2626 bool getNextBit() {
2627 assert(isValid());
2628 return Value & (1 << CurrentBitsIndex++);
2629 }
2630
2631 uint32_t getNextBits(uint32_t Width) {
2632 assert(isValid());
2633 assert(Width < BitsIndexUpbound);
2634 uint32_t Ret = (Value >> CurrentBitsIndex) & ((1 << Width) - 1);
2635 CurrentBitsIndex += Width;
2636 return Ret;
2637 }
2638
2639 bool canGetNextNBits(uint32_t Width) const {
2640 return CurrentBitsIndex + Width < BitsIndexUpbound;
2641 }
2642
2643 private:
2644 bool isValid() const { return CurrentBitsIndex < BitsIndexUpbound; }
2645
2646 uint32_t Value;
2647 uint32_t CurrentBitsIndex = ~0;
2648 };
2649
2650 inline bool shouldSkipCheckingODR(const Decl *D) {
2651 return D->getASTContext().getLangOpts().SkipODRCheckInGMF &&
2652 (D->isFromGlobalModule() || D->isFromHeaderUnit());
2653 }
2654
2655
2656
2657 std::optional<unsigned> getPrimaryModuleHash(const Module *M);
2658
2659 }
2660
2661 #endif