13#ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H
14#define LLVM_CLANG_SERIALIZATION_ASTREADER_H
36#include "llvm/ADT/ArrayRef.h"
37#include "llvm/ADT/DenseMap.h"
38#include "llvm/ADT/DenseSet.h"
39#include "llvm/ADT/IntrusiveRefCntPtr.h"
40#include "llvm/ADT/MapVector.h"
41#include "llvm/ADT/PagedVector.h"
42#include "llvm/ADT/STLExtras.h"
43#include "llvm/ADT/SetVector.h"
44#include "llvm/ADT/SmallPtrSet.h"
45#include "llvm/ADT/SmallVector.h"
46#include "llvm/ADT/StringMap.h"
47#include "llvm/ADT/StringRef.h"
48#include "llvm/ADT/iterator.h"
49#include "llvm/ADT/iterator_range.h"
50#include "llvm/Bitstream/BitstreamReader.h"
51#include "llvm/Support/MemoryBuffer.h"
52#include "llvm/Support/Timer.h"
53#include "llvm/Support/VersionTuple.h"
70class ASTDeserializationListener;
83class FileSystemOptions;
85class GlobalModuleIndex;
87class HeaderSearchOptions;
90class InMemoryModuleCache;
93class ObjCCategoryDecl;
94class ObjCInterfaceDecl;
95class PCHContainerReader;
97class PreprocessorOptions;
104class TypedefNameDecl;
134 bool AllowCompatibleDifferences) {
143 bool AllowCompatibleDifferences) {
175 StringRef SpecificModuleCachePath,
203 bool ReadMacros,
bool Complain,
204 std::string &SuggestedPredefines) {
231 bool isOverridden,
bool isExplicitModule) {
250 std::unique_ptr<ASTReaderListener> First;
251 std::unique_ptr<ASTReaderListener> Second;
256 std::unique_ptr<ASTReaderListener> Second)
260 std::unique_ptr<ASTReaderListener>
takeSecond() {
return std::move(Second); }
266 bool AllowCompatibleDifferences)
override;
268 bool AllowCompatibleDifferences)
override;
270 bool Complain)
override;
272 bool Complain)
override;
275 StringRef SpecificModuleCachePath,
276 bool Complain)
override;
278 bool ReadMacros,
bool Complain,
279 std::string &SuggestedPredefines)
override;
287 bool isOverridden,
bool isExplicitModule)
override;
300 : PP(PP), Reader(Reader) {}
303 bool AllowCompatibleDifferences)
override;
305 bool AllowCompatibleDifferences)
override;
307 bool Complain)
override;
309 bool ReadMacros,
bool Complain,
310 std::string &SuggestedPredefines)
override;
312 StringRef SpecificModuleCachePath,
313 bool Complain)
override;
328 bool ReadMacros,
bool Complain,
329 std::string &SuggestedPredefines)
override;
332namespace serialization {
334class ReadMethodPoolVisitor;
421 std::unique_ptr<ASTReaderListener> Listener;
426 bool OwnsDeserializationListener =
false;
435 Sema *SemaObj =
nullptr;
455 llvm::StringMap<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
458 std::unique_ptr<llvm::Timer> ReadTimer;
465 std::optional<ModuleKind> CurrentDeserializingModuleKind;
468 std::unique_ptr<GlobalModuleIndex> GlobalIndex;
488 llvm::PagedVector<QualType> TypesLoaded;
502 llvm::PagedVector<Decl *> DeclsLoaded;
511 using FileOffset = std::pair<ModuleFile *, uint64_t>;
513 using DeclUpdateOffsetsMap =
514 llvm::DenseMap<serialization::DeclID, FileOffsetsTy>;
518 DeclUpdateOffsetsMap DeclUpdateOffsets;
520 using DelayedNamespaceOffsetMapTy = llvm::DenseMap<
522 std::pair< uint64_t, uint64_t>>;
532 DelayedNamespaceOffsetMapTy DelayedNamespaceOffsetMap;
534 struct PendingUpdateRecord {
543 : D(D), ID(ID), JustLoaded(JustLoaded) {}
550 enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded };
554 llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData;
560 llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates;
565 llvm::SmallMapVector<FunctionDecl *, QualType, 4> PendingDeducedTypeUpdates;
573 llvm::DenseMap<std::pair<DeclContext *, IdentifierInfo *>, NamedDecl *>
574 ImportedTypedefNamesForLinkage;
578 llvm::DenseMap<Decl*, llvm::SmallVector<NamedDecl*, 2>>
579 AnonymousDeclarationsForMerging;
582 llvm::DenseMap<std::pair<const Decl *, unsigned>, NamedDecl *>
583 LambdaDeclarationsForMerging;
587 using LETemporaryKey = std::pair<Decl *, unsigned>;
590 llvm::DenseMap<LETemporaryKey, LifetimeExtendedTemporaryDecl *>
591 LETemporaryForMerging;
593 struct FileDeclsInfo {
595 ArrayRef<serialization::LocalDeclID> Decls;
597 FileDeclsInfo() =
default;
598 FileDeclsInfo(
ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
599 : Mod(Mod), Decls(Decls) {}
603 llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
607 using LexicalContents = ArrayRef<llvm::support::unaligned_uint32_t>;
610 llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
614 std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls;
617 llvm::DenseMap<
const DeclContext *,
618 serialization::reader::DeclContextLookupTable> Lookups;
624 struct PendingVisibleUpdate {
626 const unsigned char *
Data;
628 using DeclContextVisibleUpdates = SmallVector<PendingVisibleUpdate, 1>;
632 llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
633 PendingVisibleUpdates;
639 using PendingBodiesMap =
641 llvm::SmallDenseMap<Decl *, unsigned, 4>,
642 SmallVector<std::pair<Decl *, uint64_t>, 4>>;
645 PendingBodiesMap PendingBodies;
649 llvm::SetVector<NamedDecl *> PendingMergedDefinitionsToDeduplicate;
652 bool ReadLexicalDeclContextStorage(
ModuleFile &M,
653 llvm::BitstreamCursor &Cursor,
654 uint64_t Offset, DeclContext *DC);
657 bool ReadVisibleDeclContextStorage(
ModuleFile &M,
658 llvm::BitstreamCursor &Cursor,
667 std::vector<IdentifierInfo *> IdentifiersLoaded;
669 using GlobalIdentifierMapType =
670 ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>;
675 GlobalIdentifierMapType GlobalIdentifierMap;
683 std::vector<MacroInfo *> MacrosLoaded;
685 using LoadedMacroInfo =
686 std::pair<IdentifierInfo *, serialization::SubmoduleID>;
693 using GlobalMacroMapType =
694 ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>;
699 GlobalMacroMapType GlobalMacroMap;
705 SmallVector<Module *, 2> SubmodulesLoaded;
707 using GlobalSubmoduleMapType =
708 ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>;
713 GlobalSubmoduleMapType GlobalSubmoduleMap;
716 using HiddenNames = SmallVector<Decl *, 2>;
717 using HiddenNamesMapType = llvm::DenseMap<Module *, HiddenNames>;
721 HiddenNamesMapType HiddenNamesMap;
724 struct UnresolvedModuleRef {
732 enum {
Import, Export, Conflict, Affecting }
Kind;
738 LLVM_PREFERRED_TYPE(
bool)
739 unsigned IsWildcard : 1;
747 SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs;
754 SmallVector<Selector, 16> SelectorsLoaded;
756 using GlobalSelectorMapType =
757 ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>;
761 GlobalSelectorMapType GlobalSelectorMap;
765 llvm::DenseMap<Selector, unsigned> SelectorGeneration;
769 llvm::DenseMap<Selector, bool> SelectorOutOfDate;
771 struct PendingMacroInfo {
774 uint32_t MacroDirectivesOffset;
776 PendingMacroInfo(
ModuleFile *M, uint32_t MacroDirectivesOffset)
777 : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
780 using PendingMacroIDsMap =
781 llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2>>;
785 PendingMacroIDsMap PendingMacroIDs;
787 using GlobalPreprocessedEntityMapType =
788 ContinuousRangeMap<unsigned, ModuleFile *, 4>;
793 GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
795 using GlobalSkippedRangeMapType =
796 ContinuousRangeMap<unsigned, ModuleFile *, 4>;
800 GlobalSkippedRangeMapType GlobalSkippedRangeMap;
812 SmallVector<serialization::DeclID, 16> EagerlyDeserializedDecls;
819 SmallVector<serialization::DeclID, 16> TentativeDefinitions;
826 SmallVector<serialization::DeclID, 64> VTableUses;
834 SmallVector<serialization::DeclID, 64> PendingInstantiations;
844 SmallVector<serialization::DeclID, 16> UnusedFileScopedDecls;
848 SmallVector<serialization::DeclID, 4> DelegatingCtorDecls;
852 SmallVector<serialization::SelectorID, 64> ReferencedSelectorsData;
856 SmallVector<serialization::IdentifierID, 64> WeakUndeclaredIdentifiers;
861 SmallVector<serialization::DeclID, 4> ExtVectorDecls;
872 SmallVector<serialization::DeclID, 16> UnusedLocalTypedefNameCandidates;
876 unsigned ForceHostDeviceDepth = 0;
881 SmallVector<serialization::DeclID, 4> SemaDeclRefs;
886 SmallVector<serialization::TypeID, 16> SpecialTypes;
892 SmallVector<serialization::DeclID, 2> CUDASpecialDeclRefs;
895 SmallVector<uint64_t, 1> FPPragmaOptions;
898 SourceLocation OptimizeOffPragmaLocation;
901 int PragmaMSStructState = -1;
904 int PragmaMSPointersToMembersState = -1;
905 SourceLocation PointersToMembersPragmaLocation;
908 std::optional<FPOptionsOverride> FpPragmaCurrentValue;
909 SourceLocation FpPragmaCurrentLocation;
910 struct FpPragmaStackEntry {
911 FPOptionsOverride
Value;
912 SourceLocation Location;
913 SourceLocation PushLocation;
920 std::optional<Sema::AlignPackInfo> PragmaAlignPackCurrentValue;
921 SourceLocation PragmaAlignPackCurrentLocation;
922 struct PragmaAlignPackStackEntry {
923 Sema::AlignPackInfo
Value;
924 SourceLocation Location;
925 SourceLocation PushLocation;
932 OpenCLOptions OpenCLExtensions;
935 llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap;
938 llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap;
941 SmallVector<serialization::DeclID, 4> KnownNamespaces;
945 SmallVector<serialization::DeclID, 8> UndefinedButUsed;
948 SmallVector<uint64_t, 8> DelayedDeleteExprs;
951 SmallVector<std::pair<ModuleFile *, SmallVector<uint64_t, 1>>, 4>
960 struct ImportedSubmodule {
962 SourceLocation ImportLoc;
965 :
ID(
ID), ImportLoc(ImportLoc) {}
972 SmallVector<ImportedSubmodule, 2> PendingImportedModules;
976 SmallVector<ImportedSubmodule, 2> PendingImportedModulesSema;
981 std::string isysroot;
988 bool AllowASTWithCompilerErrors;
992 bool AllowConfigurationMismatch;
995 bool ValidateSystemInputs;
998 bool ValidateASTInputFilesContent;
1001 bool UseGlobalIndex;
1004 bool TriedLoadingGlobalIndex =
false;
1007 bool ProcessingUpdateRecords =
false;
1009 using SwitchCaseMapTy = llvm::DenseMap<unsigned, SwitchCase *>;
1015 SwitchCaseMapTy SwitchCaseStmts;
1017 SwitchCaseMapTy *CurrSwitchCaseStmts;
1021 unsigned NumSLocEntriesRead = 0;
1024 unsigned TotalNumSLocEntries = 0;
1028 unsigned NumStatementsRead = 0;
1032 unsigned TotalNumStatements = 0;
1035 unsigned NumMacrosRead = 0;
1038 unsigned TotalNumMacros = 0;
1041 unsigned NumIdentifierLookups = 0;
1044 unsigned NumIdentifierLookupHits = 0;
1047 unsigned NumSelectorsRead = 0;
1050 unsigned NumMethodPoolEntriesRead = 0;
1054 unsigned NumMethodPoolLookups = 0;
1058 unsigned NumMethodPoolHits = 0;
1062 unsigned NumMethodPoolTableLookups = 0;
1066 unsigned NumMethodPoolTableHits = 0;
1069 unsigned TotalNumMethodPoolEntries = 0;
1072 unsigned NumLexicalDeclContextsRead = 0, TotalLexicalDeclContexts = 0;
1075 unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0;
1078 uint64_t TotalModulesSizeInBits = 0;
1081 unsigned NumCurrentElementsDeserializing = 0;
1087 bool PassingDeclsToConsumer =
false;
1094 llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4>>
1095 PendingIdentifierInfos;
1099 llvm::SmallMapVector<const IdentifierInfo *, SmallVector<NamedDecl *, 2>, 16>
1100 PendingFakeLookupResults;
1104 llvm::DenseMap<const IdentifierInfo *, unsigned> IdentifierGeneration;
1112 std::deque<Decl *> PotentiallyInterestingDecls;
1117 SmallVector<std::pair<FunctionDecl *, serialization::TypeID>, 16>
1118 PendingDeducedFunctionTypes;
1123 SmallVector<std::pair<VarDecl *, serialization::TypeID>, 16>
1124 PendingDeducedVarTypes;
1129 SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains;
1133 SmallVector<Decl *, 16> PendingIncompleteDeclChains;
1137 struct PendingDeclContextInfo {
1148 std::deque<PendingDeclContextInfo> PendingDeclContextInfos;
1150 template <
typename DeclTy>
1151 using DuplicateObjCDecls = std::pair<DeclTy *, DeclTy *>;
1157 llvm::SmallMapVector<DuplicateObjCDecls<ObjCCategoryDecl>,
1160 PendingObjCExtensionIvarRedeclarations;
1165 SmallVector<std::pair<CXXRecordDecl*, Decl*>, 4> PendingAddedClassMembers;
1175 using DataPointers =
1176 std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
1177 using ObjCInterfaceDataPointers =
1178 std::pair<ObjCInterfaceDecl *,
1179 struct ObjCInterfaceDecl::DefinitionData *>;
1180 using ObjCProtocolDataPointers =
1181 std::pair<ObjCProtocolDecl *, struct ObjCProtocolDecl::DefinitionData *>;
1184 llvm::SmallDenseMap<CXXRecordDecl *, llvm::SmallVector<DataPointers, 2>, 2>
1185 PendingOdrMergeFailures;
1188 llvm::SmallDenseMap<RecordDecl *, llvm::SmallVector<RecordDecl *, 2>, 2>
1189 PendingRecordOdrMergeFailures;
1192 llvm::SmallDenseMap<FunctionDecl *, llvm::SmallVector<FunctionDecl *, 2>, 2>
1193 PendingFunctionOdrMergeFailures;
1196 llvm::SmallDenseMap<EnumDecl *, llvm::SmallVector<EnumDecl *, 2>, 2>
1197 PendingEnumOdrMergeFailures;
1200 llvm::SmallDenseMap<ObjCInterfaceDecl *,
1202 PendingObjCInterfaceOdrMergeFailures;
1205 llvm::SmallDenseMap<ObjCProtocolDecl *,
1207 PendingObjCProtocolOdrMergeFailures;
1219 SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
1222 llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2>>;
1229 KeyDeclsMap KeyDecls;
1234 llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts;
1238 llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions;
1242 llvm::DenseMap<RecordDecl *, RecordDecl *> RecordDefinitions;
1245 SmallVector<Stmt *, 16> StmtStack;
1249 Read_None, Read_Decl, Read_Type, Read_Stmt
1253 ReadingKind ReadingKind = Read_None;
1256 class ReadingKindTracker {
1258 enum ReadingKind PrevKind;
1261 ReadingKindTracker(
enum ReadingKind newKind, ASTReader &reader)
1262 : Reader(reader), PrevKind(Reader.ReadingKind) {
1263 Reader.ReadingKind = newKind;
1266 ReadingKindTracker(
const ReadingKindTracker &) =
delete;
1267 ReadingKindTracker &operator=(
const ReadingKindTracker &) =
delete;
1268 ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
1272 class ProcessingUpdatesRAIIObj {
1277 ProcessingUpdatesRAIIObj(ASTReader &reader)
1278 : Reader(reader), PrevState(Reader.ProcessingUpdateRecords) {
1279 Reader.ProcessingUpdateRecords =
true;
1282 ProcessingUpdatesRAIIObj(
const ProcessingUpdatesRAIIObj &) =
delete;
1283 ProcessingUpdatesRAIIObj &
1284 operator=(
const ProcessingUpdatesRAIIObj &) =
delete;
1285 ~ProcessingUpdatesRAIIObj() { Reader.ProcessingUpdateRecords = PrevState; }
1296 std::string SuggestedPredefines;
1298 llvm::DenseMap<const Decl *, bool> DefinitionSource;
1300 bool shouldDisableValidationForFile(
const serialization::ModuleFile &M)
const;
1306 serialization::InputFileInfo getInputFileInfo(
ModuleFile &F,
unsigned ID);
1310 serialization::InputFile getInputFile(
ModuleFile &F,
unsigned ID,
1311 bool Complain =
true);
1325 auto I = KeyDecls.find(D);
1326 if (I == KeyDecls.end() || I->second.empty())
1335 template <
typename Fn>
1341 auto It = KeyDecls.find(
const_cast<Decl*
>(D));
1342 if (It != KeyDecls.end())
1343 for (
auto ID : It->second)
1352 struct ImportedModule {
1360 : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) {}
1364 SourceLocation ImportLoc,
ModuleFile *ImportedBy,
1365 SmallVectorImpl<ImportedModule> &Loaded,
1366 off_t ExpectedSize, time_t ExpectedModTime,
1367 ASTFileSignature ExpectedSignature,
1368 unsigned ClientLoadCapabilities);
1370 SmallVectorImpl<ImportedModule> &Loaded,
1372 unsigned ClientLoadCapabilities);
1374 llvm::BitstreamCursor &Stream,
unsigned ClientLoadCapabilities,
1375 bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener,
1376 std::string &SuggestedPredefines);
1383 unsigned ClientLoadCapabilities);
1386 readUnhashedControlBlockImpl(
ModuleFile *F, llvm::StringRef StreamData,
1387 unsigned ClientLoadCapabilities,
1388 bool AllowCompatibleConfigurationMismatch,
1389 ASTReaderListener *Listener,
1390 bool ValidateDiagnosticOptions);
1392 llvm::Error ReadASTBlock(
ModuleFile &F,
unsigned ClientLoadCapabilities);
1393 llvm::Error ReadExtensionBlock(
ModuleFile &F);
1394 void ReadModuleOffsetMap(
ModuleFile &F)
const;
1396 llvm::Error ReadSourceManagerBlock(
ModuleFile &F);
1397 SourceLocation getImportLocation(
ModuleFile *F);
1400 unsigned ClientLoadCapabilities);
1401 llvm::Error ReadSubmoduleBlock(
ModuleFile &F,
1402 unsigned ClientLoadCapabilities);
1404 ASTReaderListener &Listener,
1405 bool AllowCompatibleDifferences);
1407 ASTReaderListener &Listener,
1408 bool AllowCompatibleDifferences);
1409 static bool ParseDiagnosticOptions(
const RecordData &
Record,
bool Complain,
1410 ASTReaderListener &Listener);
1411 static bool ParseFileSystemOptions(
const RecordData &
Record,
bool Complain,
1412 ASTReaderListener &Listener);
1413 static bool ParseHeaderSearchOptions(
const RecordData &
Record,
bool Complain,
1414 ASTReaderListener &Listener);
1415 static bool ParseHeaderSearchPaths(
const RecordData &
Record,
bool Complain,
1416 ASTReaderListener &Listener);
1417 static bool ParsePreprocessorOptions(
const RecordData &
Record,
bool Complain,
1418 ASTReaderListener &Listener,
1419 std::string &SuggestedPredefines);
1421 struct RecordLocation {
1425 RecordLocation(
ModuleFile *M, uint64_t O) : F(M), Offset(O) {}
1428 QualType readTypeRecord(
unsigned Index);
1429 RecordLocation TypeCursorForIndex(
unsigned Index);
1430 void LoadedDecl(
unsigned Index, Decl *D);
1432 void markIncompleteDeclChain(Decl *D);
1437 Decl *getMostRecentExistingDecl(Decl *D);
1440 SourceLocation &Location);
1441 void loadDeclUpdateRecords(PendingUpdateRecord &
Record);
1442 void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
1444 unsigned PreviousGeneration = 0);
1446 RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
1452 findPreprocessedEntity(SourceLocation Loc,
bool EndsAfter)
const;
1461 findNextPreprocessedEntity(
1466 std::pair<ModuleFile *, unsigned>
1467 getModulePreprocessedEntity(
unsigned GlobalIndex);
1471 llvm::iterator_range<PreprocessingRecord::iterator>
1472 getModulePreprocessedEntities(
ModuleFile &Mod)
const;
1474 bool canRecoverFromOutOfDate(StringRef ModuleFileName,
1475 unsigned ClientLoadCapabilities);
1479 :
public llvm::iterator_adaptor_base<
1480 ModuleDeclIterator, const serialization::LocalDeclID *,
1481 std::random_access_iterator_tag, const Decl *, ptrdiff_t,
1482 const Decl *, const Decl *> {
1491 : iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {}
1500 assert(Reader == RHS.Reader && Mod == RHS.Mod);
1505 llvm::iterator_range<ModuleDeclIterator>
1509 bool isConsumerInterestedIn(
Decl *D);
1510 void PassInterestingDeclsToConsumer();
1511 void PassInterestingDeclToConsumer(
Decl *D);
1513 void finishPendingActions();
1514 void diagnoseOdrViolations();
1518 void addPendingDeclContextInfo(
Decl *D,
1522 PendingDeclContextInfo Info = { D, SemaDC, LexicalDC };
1523 PendingDeclContextInfos.push_back(Info);
1530 void Error(StringRef Msg)
const;
1531 void Error(
unsigned DiagID, StringRef Arg1 = StringRef(),
1532 StringRef Arg2 = StringRef(), StringRef Arg3 = StringRef())
const;
1533 void Error(llvm::Error &&Err)
const;
1575 ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1576 ASTContext *Context,
const PCHContainerReader &PCHContainerRdr,
1577 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
1578 StringRef isysroot =
"",
1581 bool AllowASTWithCompilerErrors =
false,
1582 bool AllowConfigurationMismatch =
false,
1583 bool ValidateSystemInputs =
false,
1584 bool ValidateASTInputFilesContent =
false,
1585 bool UseGlobalIndex =
true,
1586 std::unique_ptr<llvm::Timer> ReadTimer = {});
1649 unsigned ClientLoadCapabilities,
1674 return std::move(Listener);
1679 this->Listener = std::move(Listener);
1687 L = std::make_unique<ChainedASTReaderListener>(std::move(L),
1688 std::move(Listener));
1689 Listener = std::move(L);
1695 bool Chained =
false;
1703 L = std::make_unique<ChainedASTReaderListener>(std::move(L),
1719 bool TakeOwnership =
false);
1723 return DeserializationListener;
1752 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
1801 StringRef ExistingModuleCachePath,
1802 bool RequireStrictOptionMatches =
false);
1817 std::pair<unsigned, unsigned>
1835 return TotalNumSLocEntries;
1840 return static_cast<unsigned>(IdentifiersLoaded.size());
1845 return static_cast<unsigned>(MacrosLoaded.size());
1850 return static_cast<unsigned>(TypesLoaded.size());
1855 return static_cast<unsigned>(DeclsLoaded.size());
1860 return static_cast<unsigned>(SubmodulesLoaded.size());
1865 return static_cast<unsigned>(SelectorsLoaded.size());
1872 for (
const auto &M : ModuleMgr)
1873 Result += M.NumPreprocessedEntities;
1890 if (Idx >=
Record.size())
1928 template<
typename T>
1960 template<
typename T>
1984 uint64_t *StartOfBlockOffset =
nullptr);
2007 llvm::function_ref<
bool(
Decl::Kind)> IsKindWeWant,
2076 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined)
override;
2103 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WeakIDs)
override;
2112 llvm::MapVector<
const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
2214 unsigned LocalID)
const;
2247 "Cannot find offset to remap.");
2262 unsigned &Idx)
const {
2268 assert(FID.ID >= 0 &&
"Reading non-local FileID.");
2274 unsigned &Idx, LocSeq *
Seq =
nullptr);
2277 const StringRef Blob);
2313 assert(ReadingKind == Read_Stmt &&
2314 "Should be called only during statement reading!");
2317 assert(!StmtStack.empty() &&
"Read too many sub-statements!");
2318 return StmtStack.pop_back_val();
2342 uint32_t MacroDirectivesOffset);
2358 assert(ContextObj &&
"requested AST context when not loading AST");
2405 bool IncludeSystem,
bool Complain,
2407 bool isSystem)> Visitor);
2420 constexpr static uint32_t BitsIndexUpbound = 32;
2432 CurrentBitsIndex = 0;
2435 void advance(uint32_t BitsWidth) { CurrentBitsIndex += BitsWidth; }
2439 return Value & (1 << CurrentBitsIndex++);
2444 assert(Width < BitsIndexUpbound);
2445 uint32_t Ret = (
Value >> CurrentBitsIndex) & ((1 << Width) - 1);
2446 CurrentBitsIndex += Width;
2451 return CurrentBitsIndex + Width < BitsIndexUpbound;
2455 bool isValid()
const {
return CurrentBitsIndex < BitsIndexUpbound; }
2458 uint32_t CurrentBitsIndex = ~0;
Defines the Diagnostic-related interfaces.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
llvm::MachO::Record Record
Defines the clang::OpenCLOptions class.
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
Defines version macros and version-related utility functions for Clang.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const LangOptions & getLangOpts() const
An identifier-lookup iterator that enumerates all of the identifiers stored within a set of AST files...
Abstract interface for callback invocations by the ASTReader.
virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain)
Receives the header search options.
virtual void ReadModuleMapFile(StringRef ModuleMapPath)
virtual bool needsInputFileVisitation()
Returns true if this ASTReaderListener wants to receive the input files of the AST file via visitInpu...
virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences)
Receives the target options.
virtual bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden, bool isExplicitModule)
if needsInputFileVisitation returns true, this is called for each non-system input file of the AST Fi...
virtual bool ReadHeaderSearchPaths(const HeaderSearchOptions &HSOpts, bool Complain)
Receives the header search paths.
virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, bool Complain)
Receives the file system options.
virtual ~ASTReaderListener()
virtual bool ReadDiagnosticOptions(IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, bool Complain)
Receives the diagnostic options.
virtual void readModuleFileExtension(const ModuleFileExtensionMetadata &Metadata)
Indicates that a particular module file extension has been read.
virtual bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences)
Receives the language options.
virtual void visitImport(StringRef ModuleName, StringRef Filename)
If needsImportVisitation returns true, this is called for each AST file imported by this AST file.
virtual void visitModuleFile(StringRef Filename, serialization::ModuleKind Kind)
This is called for each AST file loaded.
virtual bool needsImportVisitation() const
Returns true if this ASTReaderListener wants to receive the imports of the AST file via visitImport,...
virtual bool ReadFullVersionInformation(StringRef FullVersion)
Receives the full Clang version information.
virtual void ReadCounter(const serialization::ModuleFile &M, unsigned Value)
Receives COUNTER value.
virtual void ReadModuleName(StringRef ModuleName)
virtual bool needsSystemInputFileVisitation()
Returns true if this ASTReaderListener wants to receive the system input files of the AST file via vi...
virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool ReadMacros, bool Complain, std::string &SuggestedPredefines)
Receives the preprocessor options.
RAII object to temporarily add an AST callback listener.
ListenerScope(ASTReader &Reader, std::unique_ptr< ASTReaderListener > L)
value_type operator*() const
value_type operator->() const
bool operator==(const ModuleDeclIterator &RHS) const
ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod, const serialization::LocalDeclID *Pos)
Reads an AST files chain containing the contents of a translation unit.
std::optional< bool > isPreprocessedEntityInFileID(unsigned Index, FileID FID) override
Optionally returns true or false if the preallocated preprocessed entity with index Index came from f...
PreprocessedEntity * ReadPreprocessedEntity(unsigned Index) override
Read a preallocated preprocessed entity from the external source.
void markIdentifierUpToDate(const IdentifierInfo *II)
Note that this identifier is up-to-date.
void visitTopLevelModuleMaps(serialization::ModuleFile &MF, llvm::function_ref< void(FileEntryRef)> Visitor)
Visit all the top-level module maps loaded when building the given module file.
void setDeserializationListener(ASTDeserializationListener *Listener, bool TakeOwnership=false)
Set the AST deserialization listener.
SmallVectorImpl< uint64_t > RecordDataImpl
ExtKind hasExternalDefinitions(const Decl *D) override
IdentifierTable & getIdentifierTable()
Retrieve the identifier table associated with the preprocessor.
ModuleManager & getModuleManager()
Retrieve the module manager.
ASTReader & operator=(const ASTReader &)=delete
bool ReadSLocEntry(int ID) override
Read the source location entry with index ID.
void RecordSwitchCaseID(SwitchCase *SC, unsigned ID)
Record that the given ID maps to the given switch-case statement.
DiagnosticBuilder Diag(unsigned DiagID) const
Report a diagnostic.
unsigned getTotalNumPreprocessedEntities() const
Returns the number of preprocessed entities known to the AST reader.
ASTContext & getContext()
Retrieve the AST context that this AST reader supplements.
ModuleManager::ModuleIterator ModuleIterator
static std::string ReadString(const RecordDataImpl &Record, unsigned &Idx)
void ReadDeclsToCheckForDeferredDiags(llvm::SmallSetVector< Decl *, 4 > &Decls) override
Read the set of decls to be checked for deferred diags.
T * GetLocalDeclAs(ModuleFile &F, uint32_t LocalID)
Reads a declaration with the given local ID in the given module.
void InitializeSema(Sema &S) override
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
LoadFailureCapabilities
Flags that indicate what kind of AST loading failures the client of the AST reader can directly handl...
@ ARR_Missing
The client can handle an AST file that cannot load because it is missing.
@ ARR_None
The client can't handle any AST loading failures.
@ ARR_ConfigurationMismatch
The client can handle an AST file that cannot load because it's compiled configuration doesn't match ...
@ ARR_OutOfDate
The client can handle an AST file that cannot load because it is out-of-date relative to its input fi...
@ ARR_TreatModuleWithErrorsAsOutOfDate
If a module file is marked with errors treat it as out-of-date so the caller can rebuild it.
@ ARR_VersionMismatch
The client can handle an AST file that cannot load because it was built with a different version of C...
void ReadMismatchingDeleteExpressions(llvm::MapVector< FieldDecl *, llvm::SmallVector< std::pair< SourceLocation, bool >, 4 > > &Exprs) override
void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length, SmallVectorImpl< Decl * > &Decls) override
Get the decls that are contained in a file in the Offset/Length range.
SourceRange ReadSkippedRange(unsigned Index) override
Read a preallocated skipped range from the external source.
Decl * GetDecl(serialization::DeclID ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
const std::string & getSuggestedPredefines()
Returns the suggested contents of the predefines buffer, which contains a (typically-empty) subset of...
void dump()
Dump information about the AST reader to standard error.
serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M, unsigned LocalID)
void AssignedLambdaNumbering(const CXXRecordDecl *Lambda) override
Notify the external source that a lambda was assigned a mangling number.
MacroInfo * ReadMacroRecord(ModuleFile &F, uint64_t Offset)
Reads the macro record located at the given offset.
Decl * GetLocalDecl(ModuleFile &F, uint32_t LocalID)
Reads a declaration with the given local ID in the given module.
SmallVector< std::pair< llvm::BitstreamCursor, serialization::ModuleFile * >, 8 > CommentsCursors
Cursors for comments blocks.
Selector getLocalSelector(ModuleFile &M, unsigned LocalID)
Retrieve a selector from the given module with its local ID number.
void FindExternalLexicalDecls(const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl * > &Decls) override
Read all of the declarations lexically stored in a declaration context.
std::optional< ASTSourceDescriptor > getSourceDescriptor(unsigned ID) override
Return a descriptor for the corresponding module.
const serialization::reader::DeclContextLookupTable * getLoadedLookupTables(DeclContext *Primary) const
Get the loaded lookup tables for Primary, if any.
void ClearSwitchCaseIDs()
Sema::AlignPackInfo ReadAlignPackInfo(uint32_t Raw) const
Read a AlignPackInfo from raw form.
QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a type from the current position in the given record, which was read from the given AST file.
void SetIdentifierInfo(unsigned ID, IdentifierInfo *II)
serialization::ModuleKind ModuleKind
bool loadGlobalIndex()
Attempts to load the global index.
void ReadComments() override
Loads comments ranges.
SourceManager & getSourceManager() const
void makeModuleVisible(Module *Mod, Module::NameVisibilityKind NameVisibility, SourceLocation ImportLoc)
Make the entities in the given module and any of its (non-explicit) submodules visible to name lookup...
unsigned getTotalNumSubmodules() const
Returns the number of submodules known.
ASTReader(const ASTReader &)=delete
bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const
Returns true if global DeclID ID originated from module M.
void finalizeForWriting()
Finalizes the AST reader's state before writing an AST file to disk.
Sema * getSema()
Retrieve the semantic analysis object used to analyze the translation unit in which the precompiled h...
unsigned getTotalNumIdentifiers() const
Returns the number of identifiers found in the chain.
CXXCtorInitializer ** GetExternalCXXCtorInitializers(uint64_t Offset) override
Read the contents of a CXXCtorInitializer array.
void visitInputFileInfos(serialization::ModuleFile &MF, bool IncludeSystem, llvm::function_ref< void(const serialization::InputFileInfo &IFI, bool IsSystem)> Visitor)
Visit all the input file infos of the given module file.
unsigned getTotalNumSLocs() const
Returns the number of source locations found in the chain.
void StartTranslationUnit(ASTConsumer *Consumer) override
Function that will be invoked when we begin parsing a new translation unit involving this external AS...
void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo)
bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) override
Finds all the visible declarations with a given name.
void ReadTentativeDefinitions(SmallVectorImpl< VarDecl * > &TentativeDefs) override
Read the set of tentative definitions known to the external Sema source.
void SetGloballyVisibleDecls(IdentifierInfo *II, const SmallVectorImpl< uint32_t > &DeclIDs, SmallVectorImpl< Decl * > *Decls=nullptr)
Set the globally-visible declarations associated with the given identifier.
Decl * GetExternalDecl(uint32_t ID) override
Resolve a declaration ID into a declaration, potentially building a new declaration.
llvm::Expected< SourceLocation::UIntTy > readSLocOffset(ModuleFile *F, unsigned Index)
Try to read the offset of the SLocEntry at the given index in the given module file.
void forEachImportedKeyDecl(const Decl *D, Fn Visit)
Run a callback on each imported key declaration of D.
static void SkipPath(const RecordData &Record, unsigned &Idx)
Stmt * ReadSubStmt()
Reads a sub-statement operand during statement reading.
Decl * GetExistingDecl(serialization::DeclID ID)
Resolve a declaration ID into a declaration.
void CompleteRedeclChain(const Decl *D) override
If any redeclarations of D have been imported since it was last checked, this digs out those redeclar...
Expr * ReadSubExpr()
Reads a sub-expression operand during statement reading.
SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile, SourceLocation Loc) const
Translate a source location from another module file's source location space into ours.
static llvm::Error ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID, uint64_t *StartOfBlockOffset=nullptr)
ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the specified cursor.
serialization::PreprocessedEntityID getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const
Determine the global preprocessed entity ID that corresponds to the given local ID within the given m...
std::pair< unsigned, unsigned > findPreprocessedEntitiesInRange(SourceRange Range) override
Returns a pair of [Begin, End) indices of preallocated preprocessed entities that Range encompasses.
IdentifierInfo * get(StringRef Name) override
Retrieve the IdentifierInfo for the named identifier.
void visitInputFiles(serialization::ModuleFile &MF, bool IncludeSystem, bool Complain, llvm::function_ref< void(const serialization::InputFile &IF, bool isSystem)> Visitor)
Visit all the input files of the given module file.
Module * getModule(unsigned ID) override
Retrieve the module that corresponds to the given module ID.
llvm::iterator_range< ModuleDeclIterator > getModuleFileLevelDecls(ModuleFile &Mod)
Stmt * GetExternalDeclStmt(uint64_t Offset) override
Resolve the offset of a statement into a statement.
Selector GetExternalSelector(serialization::SelectorID ID) override
Resolve a selector ID into a selector.
unsigned getTotalNumSelectors() const
Returns the number of selectors found in the chain.
MacroInfo * getMacro(serialization::MacroID ID)
Retrieve the macro with the given ID.
void ReadUndefinedButUsed(llvm::MapVector< NamedDecl *, SourceLocation > &Undefined) override
Load the set of used but not defined functions or variables with internal linkage,...
void ReadDelegatingConstructors(SmallVectorImpl< CXXConstructorDecl * > &Decls) override
Read the set of delegating constructors known to the external Sema source.
unsigned getTotalNumTypes() const
Returns the number of types found in the chain.
SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, SourceLocation::UIntTy Raw, LocSeq *Seq=nullptr) const
Read a source location from raw form.
QualType GetType(serialization::TypeID ID)
Resolve a type ID into a type, potentially building a new type.
void addPendingMacro(IdentifierInfo *II, ModuleFile *M, uint32_t MacroDirectivesOffset)
Add a macro to deserialize its macro directive history.
SourceRange ReadSourceRange(ModuleFile &F, const RecordData &Record, unsigned &Idx, LocSeq *Seq=nullptr)
Read a source range.
Expr * ReadExpr(ModuleFile &F)
Reads an expression.
void ReadWeakUndeclaredIdentifiers(SmallVectorImpl< std::pair< IdentifierInfo *, WeakInfo > > &WeakIDs) override
Read the set of weak, undeclared identifiers known to the external Sema source.
void completeVisibleDeclsMap(const DeclContext *DC) override
Load all external visible decls in the given DeclContext.
void ReadUnusedLocalTypedefNameCandidates(llvm::SmallSetVector< const TypedefNameDecl *, 4 > &Decls) override
Read the set of potentially unused typedefs known to the source.
IdentifierResolver & getIdResolver()
Get the identifier resolver used for name lookup / updates in the translation unit scope.
static bool readASTFileControlBlock(StringRef Filename, FileManager &FileMgr, const InMemoryModuleCache &ModuleCache, const PCHContainerReader &PCHContainerRdr, bool FindModuleFileExtensions, ASTReaderListener &Listener, bool ValidateDiagnosticOptions, unsigned ClientLoadCapabilities=ARR_ConfigurationMismatch|ARR_OutOfDate)
Read the control block for the named AST file.
SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID)
Returns the source location for the decl ID.
void ReadExtVectorDecls(SmallVectorImpl< TypedefNameDecl * > &Decls) override
Read the set of ext_vector type declarations known to the external Sema source.
void ResolveImportedPath(ModuleFile &M, std::string &Filename)
If we are loading a relocatable PCH or module file, and the filename is not an absolute path,...
static void SkipString(const RecordData &Record, unsigned &Idx)
ModuleFile * getOwningModuleFile(const Decl *D)
Retrieve the module file that owns the given declaration, or NULL if the declaration is not from a mo...
std::pair< SourceLocation, StringRef > getModuleImportLoc(int ID) override
Retrieve the module import location and module name for the given source manager entry ID.
void ReadUnusedFileScopedDecls(SmallVectorImpl< const DeclaratorDecl * > &Decls) override
Read the set of unused file-scope declarations known to the external Sema source.
void ReadReferencedSelectors(SmallVectorImpl< std::pair< Selector, SourceLocation > > &Sels) override
Read the set of referenced selectors known to the external Sema source.
Selector DecodeSelector(serialization::SelectorID Idx)
ASTReadResult ReadAST(StringRef FileName, ModuleKind Type, SourceLocation ImportLoc, unsigned ClientLoadCapabilities, ModuleFile **NewLoadedModuleFile=nullptr)
Load the AST file designated by the given file name.
StringRef getOriginalSourceFile()
Retrieve the name of the original source file name for the primary module file.
std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx)
ASTDeserializationListener * getDeserializationListener()
Get the AST deserialization listener.
void addListener(std::unique_ptr< ASTReaderListener > L)
Add an AST callback listener.
unsigned getModuleFileID(ModuleFile *M)
Get an ID for the given module file.
Decl * getKeyDeclaration(Decl *D)
Returns the first key declaration for the given declaration.
SourceLocation ReadUntranslatedSourceLocation(SourceLocation::UIntTy Raw, LocSeq *Seq=nullptr) const
Read a source location from raw form and return it in its originating module file's source location s...
serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Reads a declaration ID from the given position in a record in the given module.
void setListener(std::unique_ptr< ASTReaderListener > Listener)
Set the AST callbacks listener.
Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx)
ModuleManager::ModuleReverseIterator ModuleReverseIterator
IdentifierInfo * DecodeIdentifierInfo(serialization::IdentifierID ID)
serialization::DeclID getGlobalDeclID(ModuleFile &F, serialization::LocalDeclID LocalID) const
Map from a local declaration ID within a given module to a global declaration ID.
ASTReadResult
The result of reading the control block of an AST file, which can fail for various reasons.
@ Success
The control block was read successfully.
@ ConfigurationMismatch
The AST file was written with a different language/target configuration.
@ OutOfDate
The AST file is out-of-date relative to its input files, and needs to be regenerated.
@ Failure
The AST file itself appears corrupted.
@ VersionMismatch
The AST file was written by a different version of Clang.
@ HadErrors
The AST file has errors.
@ Missing
The AST file was missing.
void addInMemoryBuffer(StringRef &FileName, std::unique_ptr< llvm::MemoryBuffer > Buffer)
Add in-memory (virtual file) buffer.
static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx)
Read a version tuple.
Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx)
Reads a token out of a record.
SwitchCase * getSwitchCaseWithID(unsigned ID)
Retrieve the switch-case statement with the given ID.
ModuleFile * getLocalModuleFile(ModuleFile &M, unsigned ID)
Retrieve the module file with a given local ID within the specified ModuleFile.
FileID TranslateFileID(ModuleFile &F, FileID FID) const
Translate a FileID from another module file's FileID space into ours.
void ReadLateParsedTemplates(llvm::MapVector< const FunctionDecl *, std::unique_ptr< LateParsedTemplate > > &LPTMap) override
Read the set of late parsed template functions for this source.
IdentifierIterator * getIdentifiers() override
Retrieve an iterator into the set of all identifiers in all loaded AST files.
void ReadUsedVTables(SmallVectorImpl< ExternalVTableUse > &VTables) override
Read the set of used vtables known to the external Sema source.
bool isGlobalIndexUnavailable() const
Determine whether we tried to load the global index, but failed, e.g., because it is out-of-date or d...
uint32_t GetNumExternalSelectors() override
Returns the number of selectors known to the external AST source.
void updateOutOfDateSelector(Selector Sel) override
Load the contents of the global method pool for a given selector if necessary.
T * ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I)
Reads a declaration from the given position in a record in the given module.
Stmt * ReadStmt(ModuleFile &F)
Reads a statement.
static llvm::BitVector ReadBitVector(const RecordData &Record, const StringRef Blob)
void ForgetSema() override
Inform the semantic consumer that Sema is no longer available.
serialization::DeclID mapGlobalIDToModuleFileGlobalID(ModuleFile &M, serialization::DeclID GlobalID)
Map a global declaration ID into the declaration ID used to refer to this declaration within the give...
DiagnosticsEngine & getDiags() const
void LoadSelector(Selector Sel)
Load a selector from disk, registering its ID if it exists.
IdentifierInfo * getLocalIdentifier(ModuleFile &M, unsigned LocalID)
void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag)
SmallVector< uint64_t, 16 > PreloadedDeclIDs
void makeNamesVisible(const HiddenNames &Names, Module *Owner)
Make the names within this set of hidden names visible.
void UpdateSema()
Update the state of Sema after loading some additional modules.
bool isProcessingUpdateRecords()
ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache, ASTContext *Context, const PCHContainerReader &PCHContainerRdr, ArrayRef< std::shared_ptr< ModuleFileExtension > > Extensions, StringRef isysroot="", DisableValidationForModuleKind DisableValidationKind=DisableValidationForModuleKind::None, bool AllowASTWithCompilerErrors=false, bool AllowConfigurationMismatch=false, bool ValidateSystemInputs=false, bool ValidateASTInputFilesContent=false, bool UseGlobalIndex=true, std::unique_ptr< llvm::Timer > ReadTimer={})
Load the AST file and validate its contents against the given Preprocessor.
int getSLocEntryID(SourceLocation::UIntTy SLocOffset) override
Get the index ID for the loaded SourceLocation offset.
void ReadPendingInstantiations(SmallVectorImpl< std::pair< ValueDecl *, SourceLocation > > &Pending) override
Read the set of pending instantiations known to the external Sema source.
serialization::SubmoduleID getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID)
Retrieve the global submodule ID given a module and its local ID number.
Preprocessor & getPreprocessor() const
Retrieve the preprocessor.
CXXTemporary * ReadCXXTemporary(ModuleFile &F, const RecordData &Record, unsigned &Idx)
void ReadKnownNamespaces(SmallVectorImpl< NamespaceDecl * > &Namespaces) override
Load the set of namespaces that are known to the external source, which will be used during typo corr...
const Decl * getKeyDeclaration(const Decl *D)
ModuleManager::ModuleConstIterator ModuleConstIterator
QualType getLocalType(ModuleFile &F, unsigned LocalID)
Resolve a local type ID within a given AST file into a type.
Decl * ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I)
Reads a declaration from the given position in a record in the given module.
Module * getSubmodule(serialization::SubmoduleID GlobalID)
Retrieve the submodule that corresponds to a global submodule ID.
void PrintStats() override
Print some statistics about AST usage.
void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef)
Note that MergedDef is a redefinition of the canonical definition Def, so Def should be visible whene...
serialization::SelectorID getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const
Retrieve the global selector ID that corresponds to this the local selector ID in a given module.
SmallVector< uint64_t, 64 > RecordData
unsigned getTotalNumMacros() const
Returns the number of macros found in the chain.
FileID ReadFileID(ModuleFile &F, const RecordDataImpl &Record, unsigned &Idx) const
Read a FileID.
void StartedDeserializing() override
Notify ASTReader that we started deserialization of a decl or type so until FinishedDeserializing is ...
void ReadMethodPool(Selector Sel) override
Load the contents of the global method pool for a given selector.
void InitializeContext()
Initializes the ASTContext.
CXXBaseSpecifier * GetExternalCXXBaseSpecifiers(uint64_t Offset) override
Resolve the offset of a set of C++ base specifiers in the decl stream into an array of specifiers.
std::unique_ptr< ASTReaderListener > takeListener()
Take the AST callbacks listener.
void resetForReload()
Reset reader for a reload try.
FileManager & getFileManager() const
unsigned getTotalNumDecls() const
Returns the number of declarations found in the chain.
serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const
Map a local type ID within a given AST file into a global type ID.
static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, const InMemoryModuleCache &ModuleCache, const PCHContainerReader &PCHContainerRdr, const LangOptions &LangOpts, const TargetOptions &TargetOpts, const PreprocessorOptions &PPOpts, StringRef ExistingModuleCachePath, bool RequireStrictOptionMatches=false)
Determine whether the given AST file is acceptable to load into a translation unit with the given lan...
void FinishedDeserializing() override
Notify ASTReader that we finished the deserialization of a decl or type.
IdentifierInfo * readIdentifier(ModuleFile &M, const RecordData &Record, unsigned &Idx)
void updateOutOfDateIdentifier(const IdentifierInfo &II) override
Update an out-of-date identifier.
void ReadDefinedMacros() override
Read the set of macros defined by this external macro source.
GlobalModuleIndex * getGlobalIndex()
Return global module index.
IdentifierInfo * GetIdentifier(serialization::IdentifierID ID) override
HeaderFileInfo GetHeaderFileInfo(FileEntryRef FE) override
Read the header file information for the given file entry.
SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, const RecordDataImpl &Record, unsigned &Idx, LocSeq *Seq=nullptr)
Read a source location.
serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID)
Retrieve the global macro ID corresponding to the given local ID within the given module file.
serialization::ModuleFile ModuleFile
bool hasGlobalIndex() const
Determine whether this AST reader has a global index.
An object for streaming information from a record.
Utility class for loading a ASTContext from an AST file.
Writes an AST file containing the contents of a translation unit.
A simple helper class to unpack an integer to bits and consuming the bits in order.
BitsUnpacker operator=(const BitsUnpacker &)=delete
uint32_t getNextBits(uint32_t Width)
void advance(uint32_t BitsWidth)
bool canGetNextNBits(uint32_t Width) const
BitsUnpacker(BitsUnpacker &&)=delete
BitsUnpacker(const BitsUnpacker &)=delete
void updateValue(uint32_t V)
BitsUnpacker operator=(BitsUnpacker &&)=delete
Represents a base class of a C++ class.
Represents a C++ base or member initializer.
Represents a C++ struct/union/class.
Represents a C++ temporary.
Simple wrapper class for chaining listeners.
bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden, bool isExplicitModule) override
if needsInputFileVisitation returns true, this is called for each non-system input file of the AST Fi...
std::unique_ptr< ASTReaderListener > takeSecond()
bool ReadFullVersionInformation(StringRef FullVersion) override
Receives the full Clang version information.
bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, bool Complain) override
Receives the file system options.
std::unique_ptr< ASTReaderListener > takeFirst()
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool ReadMacros, bool Complain, std::string &SuggestedPredefines) override
Receives the preprocessor options.
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override
Receives COUNTER value.
void ReadModuleMapFile(StringRef ModuleMapPath) override
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain) override
Receives the header search options.
bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences) override
Receives the target options.
void ReadModuleName(StringRef ModuleName) override
bool needsInputFileVisitation() override
Returns true if this ASTReaderListener wants to receive the input files of the AST file via visitInpu...
ChainedASTReaderListener(std::unique_ptr< ASTReaderListener > First, std::unique_ptr< ASTReaderListener > Second)
Takes ownership of First and Second.
bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences) override
Receives the language options.
void readModuleFileExtension(const ModuleFileExtensionMetadata &Metadata) override
Indicates that a particular module file extension has been read.
bool ReadDiagnosticOptions(IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, bool Complain) override
Receives the diagnostic options.
void visitModuleFile(StringRef Filename, serialization::ModuleKind Kind) override
This is called for each AST file loaded.
bool needsSystemInputFileVisitation() override
Returns true if this ASTReaderListener wants to receive the system input files of the AST file via vi...
A map from continuous integer ranges to some value, with a very specialized interface.
typename Representation::const_iterator const_iterator
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
Kind
Lists the kind of concrete classes of Decl.
bool isFromExplicitGlobalModule() const
Whether this declaration comes from explicit global module.
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
A little helper class used to produce diagnostics.
Concrete class used by the front-end to report problems and issues.
This represents one expression.
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...
An abstract class that should be subclassed by any external source of preprocessing record entries.
Abstract interface for external sources of preprocessor information.
External source of source location entries.
An abstract interface that should be implemented by external AST sources that also provide informatio...
Represents a member of a struct/union/class.
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Implements support for file system lookup, file system caching, and directory search management.
Keeps track of options that affect how file operations are performed.
Represents a function declaration or definition.
A global index for a set of module files, providing information about the identifiers within those mo...
Provides lookups to, and iteration over, IdentiferInfo objects.
One of these records is kept for each identifier that is lexed.
An iterator that walks over all of the known identifiers in the lookup table.
IdentifierResolver - Keeps track of shadowed decls on enclosing scopes.
Implements an efficient mapping from strings to IdentifierInfo nodes.
In-memory cache for modules.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Encapsulates the data about a macro definition (e.g.
Describes a module or submodule.
NameVisibilityKind
Describes the visibility of the various names within a particular module.
This represents a decl that may have a name.
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
ASTReaderListener implementation to validate the information of the PCH file against an initialized P...
PCHValidator(Preprocessor &PP, ASTReader &Reader)
bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences) override
Receives the target options.
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override
Receives COUNTER value.
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool ReadMacros, bool Complain, std::string &SuggestedPredefines) override
Receives the preprocessor options.
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain) override
Receives the header search options.
bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, bool AllowCompatibleDifferences) override
Receives the language options.
bool ReadDiagnosticOptions(IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, bool Complain) override
Receives the diagnostic options.
Base class that describes a preprocessed entity, which may be a preprocessor directive or macro expan...
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
A (possibly-)qualified type.
Smart pointer class that efficiently represents Objective-C method names.
static AlignPackInfo getFromRawEncoding(unsigned Encoding)
Sema - This implements semantic analysis and AST building for C.
ASTReaderListenter implementation to set SuggestedPredefines of ASTReader which is required to use a ...
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool ReadMacros, bool Complain, std::string &SuggestedPredefines) override
Receives the preprocessor options.
SimpleASTReaderListener(Preprocessor &PP)
static SourceLocation decode(uint64_t, SourceLocationSequence *=nullptr)
Serialized encoding of a sequence of SourceLocations.
Encodes a location in the source.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Options for controlling the target.
Token - This structure provides full information about a lexed token.
The base class of the type hierarchy.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Information about a module that has been loaded by the ASTReader.
int SLocEntryBaseID
The base ID in the source manager's view of this module.
std::string OriginalSourceFileName
The original source file name that was used to build the primary AST file, which may have been modifi...
StringRef ModuleOffsetMap
The module offset map data for this file.
ContinuousRangeMap< SourceLocation::UIntTy, SourceLocation::IntTy, 2 > SLocRemap
Remapping table for source locations in this module.
Manages the set of modules loaded by an AST reader.
ModuleFile & getPrimaryModule()
Returns the primary module associated with the manager, that is, the first module loaded.
llvm::pointee_iterator< SmallVectorImpl< std::unique_ptr< ModuleFile > >::const_iterator > ModuleConstIterator
void addInMemoryBuffer(StringRef FileName, std::unique_ptr< llvm::MemoryBuffer > Buffer)
Add an in-memory buffer the list of known buffers.
llvm::pointee_iterator< SmallVectorImpl< std::unique_ptr< ModuleFile > >::reverse_iterator > ModuleReverseIterator
llvm::pointee_iterator< SmallVectorImpl< std::unique_ptr< ModuleFile > >::iterator > ModuleIterator
Class that performs lookup for an identifier stored in an AST file.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
uint32_t TypeID
An ID number that refers to a type in an AST file.
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
ModuleKind
Specifies the kind of module that has been loaded.
uint32_t MacroID
An ID number that refers to a macro in an AST file.
uint32_t IdentifierID
An ID number that refers to an identifier in an AST file.
The JSON file list parser is used to communicate input to InstallAPI.
@ Seq
'seq' clause, allowed on 'loop' and 'routine' directives.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
@ Result
The result type of a method or function.
const FunctionProtoType * T
DisableValidationForModuleKind
Whether to disable the normal validation performed on precompiled headers and module files when they ...
@ None
Perform validation, don't disable it.
bool shouldSkipCheckingODR(const Decl *D)
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...